Skip to content

Rollup of 5 pull requests #106306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 12 commits into from
Closed
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
33 changes: 12 additions & 21 deletions compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
let local_decl = &self.body.local_decls[local];
assert_eq!(local_decl.mutability, Mutability::Not);

err.span_label(span, format!("cannot {ACT}", ACT = act));
err.span_label(span, format!("cannot {act}"));
err.span_suggestion(
local_decl.source_info.span,
"consider changing this to be mutable",
Expand All @@ -357,7 +357,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {

let captured_place = &self.upvars[upvar_index.index()].place;

err.span_label(span, format!("cannot {ACT}", ACT = act));
err.span_label(span, format!("cannot {act}"));

let upvar_hir_id = captured_place.get_root_variable();

Expand Down Expand Up @@ -397,7 +397,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
.span_to_snippet(span)
.map_or(false, |snippet| snippet.starts_with("&mut ")) =>
{
err.span_label(span, format!("cannot {ACT}", ACT = act));
err.span_label(span, format!("cannot {act}"));
err.span_suggestion(
span,
"try removing `&mut` here",
Expand All @@ -409,7 +409,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
PlaceRef { local, projection: [ProjectionElem::Deref] }
if self.body.local_decls[local].is_ref_for_guard() =>
{
err.span_label(span, format!("cannot {ACT}", ACT = act));
err.span_label(span, format!("cannot {act}"));
err.note(
"variables bound in patterns are immutable until the end of the pattern guard",
);
Expand Down Expand Up @@ -537,7 +537,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
Some((true, err_help_span, suggested_code)) => {
let (is_trait_sig, local_trait) = self.is_error_in_trait(local);
if !is_trait_sig {
err.span_suggestion(
err.span_suggestion_verbose(
err_help_span,
&format!(
"consider changing this to be a mutable {pointer_desc}"
Expand All @@ -546,7 +546,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
Applicability::MachineApplicable,
);
} else if let Some(x) = local_trait {
err.span_suggestion(
err.span_suggestion_verbose(
x,
&format!(
"consider changing that to be a mutable {pointer_desc}"
Expand All @@ -569,24 +569,15 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
err.span_label(
span,
format!(
"`{NAME}` is a `{SIGIL}` {DESC}, \
so the data it refers to cannot be {ACTED_ON}",
NAME = name,
SIGIL = pointer_sigil,
DESC = pointer_desc,
ACTED_ON = acted_on
"`{name}` is a `{pointer_sigil}` {pointer_desc}, \
so the data it refers to cannot be {acted_on}",
),
);
}
_ => {
err.span_label(
span,
format!(
"cannot {ACT} through `{SIGIL}` {DESC}",
ACT = act,
SIGIL = pointer_sigil,
DESC = pointer_desc
),
format!("cannot {act} through `{pointer_sigil}` {pointer_desc}"),
);
}
}
Expand All @@ -605,13 +596,13 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
Some(BorrowedContentSource::OverloadedDeref(ty)) => {
err.help(&format!(
"trait `DerefMut` is required to modify through a dereference, \
but it is not implemented for `{ty}`",
but it is not implemented for `{ty}`",
));
}
Some(BorrowedContentSource::OverloadedIndex(ty)) => {
err.help(&format!(
"trait `IndexMut` is required to modify indexed content, \
but it is not implemented for `{ty}`",
but it is not implemented for `{ty}`",
));
self.suggest_map_index_mut_alternatives(ty, &mut err, span);
}
Expand All @@ -620,7 +611,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
}

_ => {
err.span_label(span, format!("cannot {ACT}", ACT = act));
err.span_label(span, format!("cannot {act}"));
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_error_codes/src/error_codes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,7 @@ E0791: include_str!("./error_codes/E0791.md"),
// E0421, // merged into 531
// E0427, // merged into 530
// E0456, // plugin `..` is not available for triple `..`
E0465, // multiple .. candidates for `..` found
// E0465, // removed: merged with E0464
// E0467, // removed
// E0470, // removed
// E0471, // constant evaluation error (in pattern)
Expand Down
6 changes: 1 addition & 5 deletions compiler/rustc_error_messages/locales/en-US/metadata.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,7 @@ metadata_extern_location_not_file =
extern location for {$crate_name} is not a file: {$location}

metadata_multiple_candidates =
multiple {$flavor} candidates for `{$crate_name}` found

metadata_multiple_matching_crates =
multiple matching crates for `{$crate_name}`
.note = candidates:{$candidates}
multiple candidates for `{$flavor}` dependency `{$crate_name}` found

metadata_symbol_conflicts_current =
the current crate is indistinguishable from one of its dependencies: it has the same crate-name `{$crate_name}` and was compiled with the same `-C metadata` arguments. This will result in symbol conflicts between the two.
Expand Down
14 changes: 2 additions & 12 deletions compiler/rustc_metadata/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,25 +486,15 @@ impl IntoDiagnostic<'_> for MultipleCandidates {
let mut diag = handler.struct_err(rustc_errors::fluent::metadata_multiple_candidates);
diag.set_arg("crate_name", self.crate_name);
diag.set_arg("flavor", self.flavor);
diag.code(error_code!(E0465));
diag.code(error_code!(E0464));
diag.set_span(self.span);
for (i, candidate) in self.candidates.iter().enumerate() {
diag.span_note(self.span, &format!("candidate #{}: {}", i + 1, candidate.display()));
diag.note(&format!("candidate #{}: {}", i + 1, candidate.display()));
}
diag
}
}

#[derive(Diagnostic)]
#[diag(metadata_multiple_matching_crates, code = "E0464")]
#[note]
pub struct MultipleMatchingCrates {
#[primary_span]
pub span: Span,
pub crate_name: Symbol,
pub candidates: String,
}

#[derive(Diagnostic)]
#[diag(metadata_symbol_conflicts_current, code = "E0519")]
pub struct SymbolConflictsCurrent {
Expand Down
71 changes: 29 additions & 42 deletions compiler/rustc_metadata/src/locator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,8 @@ use crate::creader::Library;
use crate::errors::{
CannotFindCrate, CrateLocationUnknownType, DlError, ExternLocationNotExist,
ExternLocationNotFile, FoundStaticlib, IncompatibleRustc, InvalidMetadataFiles,
LibFilenameForm, MultipleCandidates, MultipleMatchingCrates, NewerCrateVersion,
NoCrateWithTriple, NoDylibPlugin, NonAsciiName, StableCrateIdCollision, SymbolConflictsCurrent,
SymbolConflictsOthers,
LibFilenameForm, MultipleCandidates, NewerCrateVersion, NoCrateWithTriple, NoDylibPlugin,
NonAsciiName, StableCrateIdCollision, SymbolConflictsCurrent, SymbolConflictsOthers,
};
use crate::rmeta::{rustc_version, MetadataBlob, METADATA_HEADER};

Expand All @@ -240,7 +239,6 @@ use rustc_target::spec::{Target, TargetTriple};

use snap::read::FrameDecoder;
use std::borrow::Cow;
use std::fmt::Write as _;
use std::io::{Read, Result as IoResult, Write};
use std::path::{Path, PathBuf};
use std::{cmp, fmt, fs};
Expand Down Expand Up @@ -482,7 +480,22 @@ impl<'a> CrateLocator<'a> {
match libraries.len() {
0 => Ok(None),
1 => Ok(Some(libraries.into_iter().next().unwrap().1)),
_ => Err(CrateError::MultipleMatchingCrates(self.crate_name, libraries)),
_ => {
let mut libraries: Vec<_> = libraries.into_values().collect();

libraries.sort_by_cached_key(|lib| lib.source.paths().next().unwrap().clone());
let candidates = libraries
.iter()
.map(|lib| lib.source.paths().next().unwrap().clone())
.collect::<Vec<_>>();

Err(CrateError::MultipleCandidates(
self.crate_name,
// these are the same for all candidates
get_flavor_from_path(candidates.first().unwrap()),
candidates,
))
}
}
}

Expand Down Expand Up @@ -882,17 +895,22 @@ pub fn list_file_metadata(
metadata_loader: &dyn MetadataLoader,
out: &mut dyn Write,
) -> IoResult<()> {
let flavor = get_flavor_from_path(path);
match get_metadata_section(target, flavor, path, metadata_loader) {
Ok(metadata) => metadata.list_crate_metadata(out),
Err(msg) => write!(out, "{}\n", msg),
}
}

fn get_flavor_from_path(path: &Path) -> CrateFlavor {
let filename = path.file_name().unwrap().to_str().unwrap();
let flavor = if filename.ends_with(".rlib") {

if filename.ends_with(".rlib") {
CrateFlavor::Rlib
} else if filename.ends_with(".rmeta") {
CrateFlavor::Rmeta
} else {
CrateFlavor::Dylib
};
match get_metadata_section(target, flavor, path, metadata_loader) {
Ok(metadata) => metadata.list_crate_metadata(out),
Err(msg) => write!(out, "{}\n", msg),
}
}

Expand Down Expand Up @@ -931,7 +949,6 @@ pub(crate) enum CrateError {
ExternLocationNotExist(Symbol, PathBuf),
ExternLocationNotFile(Symbol, PathBuf),
MultipleCandidates(Symbol, CrateFlavor, Vec<PathBuf>),
MultipleMatchingCrates(Symbol, FxHashMap<Svh, Library>),
SymbolConflictsCurrent(Symbol),
SymbolConflictsOthers(Symbol),
StableCrateIdCollision(Symbol, Symbol),
Expand Down Expand Up @@ -972,37 +989,7 @@ impl CrateError {
sess.emit_err(ExternLocationNotFile { span, crate_name, location: &loc });
}
CrateError::MultipleCandidates(crate_name, flavor, candidates) => {
sess.emit_err(MultipleCandidates { span, flavor: flavor, crate_name, candidates });
}
CrateError::MultipleMatchingCrates(crate_name, libraries) => {
let mut libraries: Vec<_> = libraries.into_values().collect();
// Make ordering of candidates deterministic.
// This has to `clone()` to work around lifetime restrictions with `sort_by_key()`.
// `sort_by()` could be used instead, but this is in the error path,
// so the performance shouldn't matter.
libraries.sort_by_cached_key(|lib| lib.source.paths().next().unwrap().clone());
let candidates = libraries
.iter()
.map(|lib| {
let crate_name = lib.metadata.get_root().name();
let crate_name = crate_name.as_str();
let mut paths = lib.source.paths();

// This `unwrap()` should be okay because there has to be at least one
// source file. `CrateSource`'s docs confirm that too.
let mut s = format!(
"\ncrate `{}`: {}",
crate_name,
paths.next().unwrap().display()
);
let padding = 8 + crate_name.len();
for path in paths {
write!(s, "\n{:>padding$}", path.display(), padding = padding).unwrap();
}
s
})
.collect::<String>();
sess.emit_err(MultipleMatchingCrates { span, crate_name, candidates });
sess.emit_err(MultipleCandidates { span, crate_name, flavor, candidates });
}
CrateError::SymbolConflictsCurrent(root_name) => {
sess.emit_err(SymbolConflictsCurrent { span, crate_name: root_name });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ fn encode_const<'tcx>(

/// Encodes a FnSig using the Itanium C++ ABI with vendor extended type qualifiers and types for
/// Rust types that are not used at the FFI boundary.
#[instrument(level = "trace", skip(tcx, dict))]
fn encode_fnsig<'tcx>(
tcx: TyCtxt<'tcx>,
fn_sig: &FnSig<'tcx>,
Expand Down Expand Up @@ -653,6 +654,7 @@ fn encode_ty<'tcx>(
// Transforms a ty:Ty for being encoded and used in the substitution dictionary. It transforms all
// c_void types into unit types unconditionally, and generalizes all pointers if
// TransformTyOptions::GENERALIZE_POINTERS option is set.
#[instrument(level = "trace", skip(tcx))]
fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptions) -> Ty<'tcx> {
let mut ty = ty;

Expand Down Expand Up @@ -698,7 +700,7 @@ fn transform_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>, options: TransformTyOptio
!is_zst
});
if let Some(field) = field {
let ty0 = tcx.type_of(field.did);
let ty0 = tcx.bound_type_of(field.did).subst(tcx, substs);
// Generalize any repr(transparent) user-defined type that is either a pointer
// or reference, and either references itself or any other type that contains or
// references itself, to avoid a reference cycle.
Expand Down Expand Up @@ -827,6 +829,7 @@ fn transform_substs<'tcx>(

/// Returns a type metadata identifier for the specified FnAbi using the Itanium C++ ABI with vendor
/// extended type qualifiers and types for Rust types that are not used at the FFI boundary.
#[instrument(level = "trace", skip(tcx))]
pub fn typeid_for_fnabi<'tcx>(
tcx: TyCtxt<'tcx>,
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
Expand Down
22 changes: 20 additions & 2 deletions src/bootstrap/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,36 @@ impl RunConfig<'_> {
self.builder.build.build
}

/// Return a `-p=x -p=y` string suitable for passing to a cargo invocation.
/// Return a list of crate names selected by `run.paths`.
pub fn cargo_crates_in_set(&self) -> Interned<Vec<String>> {
let mut crates = Vec::new();
for krate in &self.paths {
let path = krate.assert_single_path();
let crate_name = self.builder.crate_paths[&path.path];
crates.push(format!("-p={crate_name}"));
crates.push(crate_name.to_string());
}
INTERNER.intern_list(crates)
}
}

/// A description of the crates in this set, suitable for passing to `builder.info`.
///
/// `crates` should be generated by [`RunConfig::cargo_crates_in_set`].
pub fn crate_description(crates: &[impl AsRef<str>]) -> String {
if crates.is_empty() {
return "".into();
}

let mut descr = String::from(" {");
descr.push_str(crates[0].as_ref());
for krate in &crates[1..] {
descr.push_str(", ");
descr.push_str(krate.as_ref());
}
descr.push('}');
descr
}

struct StepDescription {
default: bool,
only_hosts: bool,
Expand Down
Loading