Auto merge of #107767 - matthiaskrgr:rollup-9m1qfso, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #100599 (Add compiler error E0523 long description and test) - #107471 (rustdoc: do not include empty default-settings tag in HTML) - #107555 (Modify existing bounds if they exist) - #107662 (Turn projections into copies in CopyProp.) - #107695 (Add test for Future inflating arg size to 3x ) - #107700 (Run the tools builder on all PRs) - #107706 (Mark 'atomic_mut_ptr' methods const) - #107709 (Fix problem noticed in PR106859 with char -> u8 suggestion) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
This commit is contained in:
commit
bd39bbb4bb
36 changed files with 492 additions and 109 deletions
|
@ -803,6 +803,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
|||
predicates
|
||||
.iter()
|
||||
.map(|(param, constraint)| (param.name.as_str(), &**constraint, None)),
|
||||
None,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -136,6 +136,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
|
|||
¶m_ty.name.as_str(),
|
||||
&constraint,
|
||||
None,
|
||||
None,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -286,6 +286,7 @@ E0519: include_str!("./error_codes/E0519.md"),
|
|||
E0520: include_str!("./error_codes/E0520.md"),
|
||||
E0521: include_str!("./error_codes/E0521.md"),
|
||||
E0522: include_str!("./error_codes/E0522.md"),
|
||||
E0523: include_str!("./error_codes/E0523.md"),
|
||||
E0524: include_str!("./error_codes/E0524.md"),
|
||||
E0525: include_str!("./error_codes/E0525.md"),
|
||||
E0527: include_str!("./error_codes/E0527.md"),
|
||||
|
@ -622,7 +623,6 @@ E0793: include_str!("./error_codes/E0793.md"),
|
|||
// E0488, // lifetime of variable does not enclose its declaration
|
||||
// E0489, // type/lifetime parameter not in scope here
|
||||
// E0490, // removed: unreachable
|
||||
E0523, // two dependencies have same (crate-name, disambiguator) but different SVH
|
||||
// E0526, // shuffle indices are not constant
|
||||
// E0540, // multiple rustc_deprecated attributes
|
||||
// E0548, // replaced with a generic attribute input check
|
||||
|
|
|
@ -1,6 +1,21 @@
|
|||
The compiler found multiple library files with the requested crate name.
|
||||
|
||||
```compile_fail
|
||||
// aux-build:crateresolve-1.rs
|
||||
// aux-build:crateresolve-2.rs
|
||||
// aux-build:crateresolve-3.rs
|
||||
|
||||
extern crate crateresolve;
|
||||
//~^ ERROR multiple candidates for `rlib` dependency `crateresolve` found
|
||||
|
||||
fn main() {}
|
||||
```
|
||||
|
||||
This error can occur in several different cases -- for example, when using
|
||||
`extern crate` or passing `--extern` options without crate paths. It can also be
|
||||
caused by caching issues with the build directory, in which case `cargo clean`
|
||||
may help.
|
||||
|
||||
In the above example, there are three different library files, all of which
|
||||
define the same crate name. Without providing a full path, there is no way for
|
||||
the compiler to know which crate it should use.
|
||||
|
|
25
compiler/rustc_error_codes/src/error_codes/E0523.md
Normal file
25
compiler/rustc_error_codes/src/error_codes/E0523.md
Normal file
|
@ -0,0 +1,25 @@
|
|||
#### Note: this error code is no longer emitted by the compiler.
|
||||
|
||||
The compiler found multiple library files with the requested crate name.
|
||||
|
||||
```compile_fail
|
||||
// aux-build:crateresolve-1.rs
|
||||
// aux-build:crateresolve-2.rs
|
||||
// aux-build:crateresolve-3.rs
|
||||
|
||||
extern crate crateresolve;
|
||||
//~^ ERROR multiple candidates for `rlib` dependency `crateresolve` found
|
||||
|
||||
fn main() {}
|
||||
```
|
||||
|
||||
This error can occur in several different cases -- for example, when using
|
||||
`extern crate` or passing `--extern` options without crate paths. It can also be
|
||||
caused by caching issues with the build directory, in which case `cargo clean`
|
||||
may help.
|
||||
|
||||
In the above example, there are three different library files, all of which
|
||||
define the same crate name. Without providing a full path, there is no way for
|
||||
the compiler to know which crate it should use.
|
||||
|
||||
*Note that E0523 has been merged into E0464.*
|
|
@ -176,6 +176,7 @@ fn visit_implementation_of_copy(tcx: TyCtxt<'_>, impl_did: LocalDefId) {
|
|||
bounds.iter().map(|(param, constraint, def_id)| {
|
||||
(param.as_str(), constraint.as_str(), *def_id)
|
||||
}),
|
||||
None,
|
||||
);
|
||||
err.emit();
|
||||
}
|
||||
|
|
|
@ -1457,6 +1457,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||
generics,
|
||||
diag,
|
||||
vec![(param.name.as_str(), "Clone", Some(clone_trait_did))].into_iter(),
|
||||
None,
|
||||
);
|
||||
} else {
|
||||
self.suggest_derive(diag, &[(trait_ref.to_predicate(self.tcx), None, None)]);
|
||||
|
|
|
@ -1922,7 +1922,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
(ty::Uint(ty::UintTy::U8), ty::Char) => {
|
||||
if let Ok(code) = self.tcx.sess().source_map().span_to_snippet(span)
|
||||
&& let Some(code) = code.strip_prefix('\'').and_then(|s| s.strip_suffix('\''))
|
||||
&& code.chars().next().map_or(false, |c| c.is_ascii())
|
||||
&& !code.starts_with("\\u") // forbid all Unicode escapes
|
||||
&& code.chars().next().map_or(false, |c| c.is_ascii()) // forbids literal Unicode characters beyond ASCII
|
||||
{
|
||||
err.span_suggestion(
|
||||
span,
|
||||
|
|
|
@ -77,49 +77,86 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
|
|||
(ty::Param(p), ty::Alias(ty::Projection, proj)) | (ty::Alias(ty::Projection, proj), ty::Param(p))
|
||||
if tcx.def_kind(proj.def_id) != DefKind::ImplTraitPlaceholder =>
|
||||
{
|
||||
let generics = tcx.generics_of(body_owner_def_id);
|
||||
let p_span = tcx.def_span(generics.type_param(p, tcx).def_id);
|
||||
let p_def_id = tcx
|
||||
.generics_of(body_owner_def_id)
|
||||
.type_param(p, tcx)
|
||||
.def_id;
|
||||
let p_span = tcx.def_span(p_def_id);
|
||||
if !sp.contains(p_span) {
|
||||
diag.span_label(p_span, "this type parameter");
|
||||
}
|
||||
let hir = tcx.hir();
|
||||
let mut note = true;
|
||||
if let Some(generics) = generics
|
||||
.type_param(p, tcx)
|
||||
.def_id
|
||||
let parent = p_def_id
|
||||
.as_local()
|
||||
.map(|id| hir.local_def_id_to_hir_id(id))
|
||||
.and_then(|id| tcx.hir().find_parent(id))
|
||||
.as_ref()
|
||||
.and_then(|node| node.generics())
|
||||
.and_then(|id| {
|
||||
let local_id = hir.local_def_id_to_hir_id(id);
|
||||
let generics = tcx.hir().find_parent(local_id)?.generics()?;
|
||||
Some((id, generics))
|
||||
});
|
||||
if let Some((local_id, generics)) = parent
|
||||
{
|
||||
// Synthesize the associated type restriction `Add<Output = Expected>`.
|
||||
// FIXME: extract this logic for use in other diagnostics.
|
||||
let (trait_ref, assoc_substs) = proj.trait_ref_and_own_substs(tcx);
|
||||
let path =
|
||||
tcx.def_path_str_with_substs(trait_ref.def_id, trait_ref.substs);
|
||||
let item_name = tcx.item_name(proj.def_id);
|
||||
let item_args = self.format_generic_args(assoc_substs);
|
||||
|
||||
let path = if path.ends_with('>') {
|
||||
format!(
|
||||
"{}, {}{} = {}>",
|
||||
&path[..path.len() - 1],
|
||||
item_name,
|
||||
item_args,
|
||||
p
|
||||
)
|
||||
// Here, we try to see if there's an existing
|
||||
// trait implementation that matches the one that
|
||||
// we're suggesting to restrict. If so, find the
|
||||
// "end", whether it be at the end of the trait
|
||||
// or the end of the generic arguments.
|
||||
let mut matching_span = None;
|
||||
let mut matched_end_of_args = false;
|
||||
for bound in generics.bounds_for_param(local_id) {
|
||||
let potential_spans = bound
|
||||
.bounds
|
||||
.iter()
|
||||
.find_map(|bound| {
|
||||
let bound_trait_path = bound.trait_ref()?.path;
|
||||
let def_id = bound_trait_path.res.opt_def_id()?;
|
||||
let generic_args = bound_trait_path.segments.iter().last().map(|path| path.args());
|
||||
(def_id == trait_ref.def_id).then_some((bound_trait_path.span, generic_args))
|
||||
});
|
||||
|
||||
if let Some((end_of_trait, end_of_args)) = potential_spans {
|
||||
let args_span = end_of_args.and_then(|args| args.span());
|
||||
matched_end_of_args = args_span.is_some();
|
||||
matching_span = args_span
|
||||
.or_else(|| Some(end_of_trait))
|
||||
.map(|span| span.shrink_to_hi());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if matched_end_of_args {
|
||||
// Append suggestion to the end of our args
|
||||
let path = format!(", {}{} = {}",item_name, item_args, p);
|
||||
note = !suggest_constraining_type_param(
|
||||
tcx,
|
||||
generics,
|
||||
diag,
|
||||
&format!("{}", proj.self_ty()),
|
||||
&path,
|
||||
None,
|
||||
matching_span,
|
||||
);
|
||||
} else {
|
||||
format!("{}<{}{} = {}>", path, item_name, item_args, p)
|
||||
};
|
||||
note = !suggest_constraining_type_param(
|
||||
tcx,
|
||||
generics,
|
||||
diag,
|
||||
&format!("{}", proj.self_ty()),
|
||||
&path,
|
||||
None,
|
||||
);
|
||||
// Suggest adding a bound to an existing trait
|
||||
// or if the trait doesn't exist, add the trait
|
||||
// and the suggested bounds.
|
||||
let path = format!("<{}{} = {}>", item_name, item_args, p);
|
||||
note = !suggest_constraining_type_param(
|
||||
tcx,
|
||||
generics,
|
||||
diag,
|
||||
&format!("{}", proj.self_ty()),
|
||||
&path,
|
||||
None,
|
||||
matching_span,
|
||||
);
|
||||
}
|
||||
}
|
||||
if note {
|
||||
diag.note("you might be missing a type parameter or trait bound");
|
||||
|
|
|
@ -356,7 +356,12 @@ impl<'a> CrateLoader<'a> {
|
|||
for (_, other) in self.cstore.iter_crate_data() {
|
||||
// Same stable crate id but different SVH
|
||||
if other.stable_crate_id() == root.stable_crate_id() && other.hash() != root.hash() {
|
||||
return Err(CrateError::SymbolConflictsOthers(root.name()));
|
||||
bug!(
|
||||
"Previously returned E0523 here. \
|
||||
See https://github.com/rust-lang/rust/pull/100599 for additional discussion.\
|
||||
root.name() = {}.",
|
||||
root.name()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -511,14 +511,6 @@ pub struct SymbolConflictsCurrent {
|
|||
pub crate_name: Symbol,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(metadata_symbol_conflicts_others, code = "E0523")]
|
||||
pub struct SymbolConflictsOthers {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
pub crate_name: Symbol,
|
||||
}
|
||||
|
||||
#[derive(Diagnostic)]
|
||||
#[diag(metadata_stable_crate_id_collision)]
|
||||
pub struct StableCrateIdCollision {
|
||||
|
|
|
@ -945,7 +945,6 @@ pub(crate) enum CrateError {
|
|||
ExternLocationNotFile(Symbol, PathBuf),
|
||||
MultipleCandidates(Symbol, CrateFlavor, Vec<PathBuf>),
|
||||
SymbolConflictsCurrent(Symbol),
|
||||
SymbolConflictsOthers(Symbol),
|
||||
StableCrateIdCollision(Symbol, Symbol),
|
||||
DlOpen(String),
|
||||
DlSym(String),
|
||||
|
@ -989,9 +988,6 @@ impl CrateError {
|
|||
CrateError::SymbolConflictsCurrent(root_name) => {
|
||||
sess.emit_err(errors::SymbolConflictsCurrent { span, crate_name: root_name });
|
||||
}
|
||||
CrateError::SymbolConflictsOthers(root_name) => {
|
||||
sess.emit_err(errors::SymbolConflictsOthers { span, crate_name: root_name });
|
||||
}
|
||||
CrateError::StableCrateIdCollision(crate_name0, crate_name1) => {
|
||||
sess.emit_err(errors::StableCrateIdCollision { span, crate_name0, crate_name1 });
|
||||
}
|
||||
|
|
|
@ -193,6 +193,9 @@ fn suggest_removing_unsized_bound(
|
|||
}
|
||||
|
||||
/// Suggest restricting a type param with a new bound.
|
||||
///
|
||||
/// If `span_to_replace` is provided, then that span will be replaced with the
|
||||
/// `constraint`. If one wasn't provided, then the full bound will be suggested.
|
||||
pub fn suggest_constraining_type_param(
|
||||
tcx: TyCtxt<'_>,
|
||||
generics: &hir::Generics<'_>,
|
||||
|
@ -200,12 +203,14 @@ pub fn suggest_constraining_type_param(
|
|||
param_name: &str,
|
||||
constraint: &str,
|
||||
def_id: Option<DefId>,
|
||||
span_to_replace: Option<Span>,
|
||||
) -> bool {
|
||||
suggest_constraining_type_params(
|
||||
tcx,
|
||||
generics,
|
||||
err,
|
||||
[(param_name, constraint, def_id)].into_iter(),
|
||||
span_to_replace,
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -215,6 +220,7 @@ pub fn suggest_constraining_type_params<'a>(
|
|||
generics: &hir::Generics<'_>,
|
||||
err: &mut Diagnostic,
|
||||
param_names_and_constraints: impl Iterator<Item = (&'a str, &'a str, Option<DefId>)>,
|
||||
span_to_replace: Option<Span>,
|
||||
) -> bool {
|
||||
let mut grouped = FxHashMap::default();
|
||||
param_names_and_constraints.for_each(|(param_name, constraint, def_id)| {
|
||||
|
@ -253,7 +259,9 @@ pub fn suggest_constraining_type_params<'a>(
|
|||
let mut suggest_restrict = |span, bound_list_non_empty| {
|
||||
suggestions.push((
|
||||
span,
|
||||
if bound_list_non_empty {
|
||||
if span_to_replace.is_some() {
|
||||
constraint.clone()
|
||||
} else if bound_list_non_empty {
|
||||
format!(" + {}", constraint)
|
||||
} else {
|
||||
format!(" {}", constraint)
|
||||
|
@ -262,6 +270,11 @@ pub fn suggest_constraining_type_params<'a>(
|
|||
))
|
||||
};
|
||||
|
||||
if let Some(span) = span_to_replace {
|
||||
suggest_restrict(span, true);
|
||||
continue;
|
||||
}
|
||||
|
||||
// When the type parameter has been provided bounds
|
||||
//
|
||||
// Message:
|
||||
|
|
|
@ -153,8 +153,9 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'_, 'tcx> {
|
|||
|
||||
fn visit_operand(&mut self, operand: &mut Operand<'tcx>, loc: Location) {
|
||||
if let Operand::Move(place) = *operand
|
||||
&& let Some(local) = place.as_local()
|
||||
&& !self.fully_moved.contains(local)
|
||||
// A move out of a projection of a copy is equivalent to a copy of the original projection.
|
||||
&& !place.has_deref()
|
||||
&& !self.fully_moved.contains(place.local)
|
||||
{
|
||||
*operand = Operand::Copy(place);
|
||||
}
|
||||
|
|
|
@ -679,6 +679,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
¶m_name,
|
||||
&constraint,
|
||||
Some(trait_pred.def_id()),
|
||||
None,
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
@ -1087,6 +1088,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||
param.name.as_str(),
|
||||
"Clone",
|
||||
Some(clone_trait),
|
||||
None,
|
||||
);
|
||||
}
|
||||
err.span_suggestion_verbose(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue