Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 4 additions & 6 deletions src/cli/rustup_mode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1144,7 +1144,7 @@ async fn show(cfg: &Cfg<'_>, verbose: bool) -> Result<ExitCode> {
.components()?
.into_iter()
.filter_map(|c| {
(c.installed && c.component.short_name_in_manifest() == "rust-std")
(c.installed && c.component.short_name() == "rust-std")
.then(|| c.component.target.expect("rust-std should have a target"))
})
.collect(),
Expand Down Expand Up @@ -1287,7 +1287,7 @@ async fn target_list(
if let Ok(distributable) = DistributableToolchain::from_partial(toolchain.clone(), cfg).await {
common::list_items(
distributable.components()?.into_iter().filter_map(|c| {
if c.component.short_name_in_manifest() == "rust-std" && c.available {
if c.component.short_name() == "rust-std" && c.available {
c.component.target.map(|target| (target, c.installed))
} else {
None
Expand Down Expand Up @@ -1335,7 +1335,7 @@ async fn target_add(

targets.clear();
for component in components {
if component.component.short_name_in_manifest() == "rust-std"
if component.component.short_name() == "rust-std"
&& component.available
&& !component.installed
{
Expand Down Expand Up @@ -1763,9 +1763,7 @@ async fn doc(
&& let [_] = distributable
.components()?
.into_iter()
.filter(|cstatus| {
cstatus.component.short_name_in_manifest() == "rust-docs" && !cstatus.installed
})
.filter(|cstatus| cstatus.component.short_name() == "rust-docs" && !cstatus.installed)
.take(1)
.collect::<Vec<ComponentStatus>>()
.as_slice()
Expand Down
16 changes: 8 additions & 8 deletions src/dist/manifest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ impl Manifest {
}

pub(super) fn binary(&self, component: &Component) -> Result<Option<&HashedBinary>> {
let package = self.get_package(component.short_name_in_manifest())?;
let package = self.get_package(component.short_name())?;
let target_package = package.get_target(component.target.as_ref())?;
// We prefer the first format in the list, since the parsing of the
// manifest leaves us with the files/hash pairs in preference order.
Expand Down Expand Up @@ -456,7 +456,7 @@ impl Manifest {

// Get the component so we can check if it is available
let component_pkg = self
.get_package(component.short_name_in_manifest())
.get_package(component.short_name())
.unwrap_or_else(|_| {
panic!(
"manifest should contain component {}",
Expand Down Expand Up @@ -538,7 +538,7 @@ impl Component {
let manifest = distributable.get_manifest()?;
for component_status in distributable.components()? {
let component = component_status.component;
if name == component.name_in_manifest() || name == manifest.name(&component) {
if name == component.name() || name == manifest.name(&component) {
return Ok(component);
}
}
Expand All @@ -558,11 +558,11 @@ impl Component {
}
}

pub fn short_name_in_manifest(&self) -> &String {
pub fn short_name(&self) -> &String {
Copy link
Copy Markdown
Member

@rami3l rami3l Mar 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: Kind of pre-existing, but I'd argue that to make this even less of a confusion going forward, it'd be cool to add doc comments to explicitly compare the Component:: and Manifest:: functions in question. It can be really simple.

How about something like the following in the impl Manifest block (not sure about the syntax, but the overall idea should be clear):

/// Returns the [`Component`]'s short name (not including the target) before renaming.
/// For the name after renaming, see [`Component::short_name()`].
/// Returns the [`Component`]'s name (including the target) before renaming.
/// For the name after renaming, see [`Component::name()`].

&self.pkg
}
pub(crate) fn name_in_manifest(&self) -> String {
let pkg = self.short_name_in_manifest();
pub(crate) fn name(&self) -> String {
let pkg = self.short_name();
if let Some(t) = &self.target {
format!("{pkg}-{t}")
} else {
Expand Down Expand Up @@ -670,11 +670,11 @@ mod tests {
assert_eq!(rust_target_pkg.bins[0].hash, "...");

let component = &rust_target_pkg.components[0];
assert_eq!(component.short_name_in_manifest(), "rustc");
assert_eq!(component.short_name(), "rustc");
assert_eq!(component.target.as_ref(), Some(&x86_64_unknown_linux_gnu));

let component = &rust_target_pkg.components[4];
assert_eq!(component.short_name_in_manifest(), "rust-std");
assert_eq!(component.short_name(), "rust-std");
assert_eq!(component.target.as_ref(), Some(&x86_64_unknown_linux_musl));

let docs_pkg = pkg.get_package("rust-docs").unwrap();
Expand Down
11 changes: 5 additions & 6 deletions src/dist/manifestation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,8 +336,8 @@ impl Manifestation {
// names are not the same as the dist manifest component
// names. Some are just the component name some are the
// component name plus the target tuple.
let name = component.name_in_manifest();
let short_name = component.short_name_in_manifest();
let name = component.name();
let short_name = component.short_name();
if let Some(c) = self.installation.find(&name)? {
tx = c.uninstall(tx)?;
} else if let Some(c) = self.installation.find(short_name)? {
Expand Down Expand Up @@ -712,8 +712,7 @@ impl Update {
.iter()
.filter(|c| {
use crate::dist::manifest::{Package, TargetedPackage};
let pkg: Option<&Package> =
new_manifest.get_package(c.short_name_in_manifest()).ok();
let pkg: Option<&Package> = new_manifest.get_package(c.short_name()).ok();
let target_pkg: Option<&TargetedPackage> =
pkg.and_then(|p| p.get_target(c.target.as_ref()).ok());
target_pkg.map(TargetedPackage::available) != Some(true)
Expand Down Expand Up @@ -827,8 +826,8 @@ impl ComponentInstall {
// names are not the same as the dist manifest component
// names. Some are just the component name some are the
// component name plus the target tuple.
let pkg_name = self.component.name_in_manifest();
let short_pkg_name = self.component.short_name_in_manifest();
let pkg_name = self.component.name();
let short_pkg_name = self.component.short_name();
let reader = self.status.unpack(utils::buffered(&self.installer)?);
let package = DirectoryPackage::compressed(
reader,
Expand Down
2 changes: 1 addition & 1 deletion src/dist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1175,7 +1175,7 @@ async fn try_update_from_dist_(
if let Some(c) = rust_target_package
.components
.iter()
.find(|c| c.short_name_in_manifest() == component.short_name_in_manifest())
.find(|c| c.short_name() == component.short_name())
&& c.target.is_none()
{
component = component.wildcard();
Expand Down
19 changes: 5 additions & 14 deletions src/toolchain/distributable.rs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ impl<'a> DistributableToolchain<'a> {
let wanted_components = components.iter().all(|name| {
installed_components.iter().any(|status| {
let cname = manifest.short_name(&status.component);
let cnameim = status.component.short_name_in_manifest();
let cnameim = status.component.short_name();
let cnameim = cnameim.as_str();
(cname == *name || cnameim == *name) && status.installed
})
Expand All @@ -172,7 +172,7 @@ impl<'a> DistributableToolchain<'a> {
let wanted_targets = targets.iter().all(|name| {
installed_components
.iter()
.filter(|c| c.component.short_name_in_manifest() == "rust-std")
.filter(|c| c.component.short_name() == "rust-std")
.any(|status| {
let ctarg = status.component.target();
(ctarg == *name) && status.installed
Expand Down Expand Up @@ -265,10 +265,7 @@ impl<'a> DistributableToolchain<'a> {
.filter(|c| !only_installed || c.installed)
.map(|c| {
(
damerau_levenshtein(
&c.component.name_in_manifest()[..],
&manifest.name(component)[..],
),
damerau_levenshtein(&c.component.name()[..], &manifest.name(component)[..]),
c,
)
})
Expand All @@ -285,16 +282,10 @@ impl<'a> DistributableToolchain<'a> {
closest_distance = long_name_distance;

// Check if only targets differ
if closest_distance.1.component.short_name_in_manifest()
== component.short_name_in_manifest()
{
if closest_distance.1.component.short_name() == component.short_name() {
closest_match = long_name_distance.1.component.target();
} else {
closest_match = long_name_distance
.1
.component
.short_name_in_manifest()
.to_string();
closest_match = long_name_distance.1.component.short_name().to_string();
}
} else {
// Check if only targets differ
Expand Down
Loading