Skip to content

Commit bd39bbb

Browse files
committed
Auto merge of rust-lang#107767 - matthiaskrgr:rollup-9m1qfso, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - rust-lang#100599 (Add compiler error E0523 long description and test) - rust-lang#107471 (rustdoc: do not include empty default-settings tag in HTML) - rust-lang#107555 (Modify existing bounds if they exist) - rust-lang#107662 (Turn projections into copies in CopyProp.) - rust-lang#107695 (Add test for Future inflating arg size to 3x ) - rust-lang#107700 (Run the tools builder on all PRs) - rust-lang#107706 (Mark 'atomic_mut_ptr' methods const) - rust-lang#107709 (Fix problem noticed in PR106859 with char -> u8 suggestion) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 5dd0e1b + 0e3af6a commit bd39bbb

File tree

36 files changed

+492
-109
lines changed

36 files changed

+492
-109
lines changed

Diff for: .github/workflows/ci.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,8 @@ jobs:
6060
env: {}
6161
- name: x86_64-gnu-tools
6262
tidy: false
63-
env:
64-
CI_ONLY_WHEN_SUBMODULES_CHANGED: 1
6563
os: ubuntu-20.04-xl
64+
env: {}
6665
timeout-minutes: 600
6766
runs-on: "${{ matrix.os }}"
6867
steps:

Diff for: compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+1
Original file line numberDiff line numberDiff line change
@@ -803,6 +803,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
803803
predicates
804804
.iter()
805805
.map(|(param, constraint)| (param.name.as_str(), &**constraint, None)),
806+
None,
806807
);
807808
}
808809
}

Diff for: compiler/rustc_const_eval/src/transform/check_consts/ops.rs

+1
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ impl<'tcx> NonConstOp<'tcx> for FnCallNonConst<'tcx> {
136136
&param_ty.name.as_str(),
137137
&constraint,
138138
None,
139+
None,
139140
);
140141
}
141142
}

Diff for: compiler/rustc_error_codes/src/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ E0519: include_str!("./error_codes/E0519.md"),
286286
E0520: include_str!("./error_codes/E0520.md"),
287287
E0521: include_str!("./error_codes/E0521.md"),
288288
E0522: include_str!("./error_codes/E0522.md"),
289+
E0523: include_str!("./error_codes/E0523.md"),
289290
E0524: include_str!("./error_codes/E0524.md"),
290291
E0525: include_str!("./error_codes/E0525.md"),
291292
E0527: include_str!("./error_codes/E0527.md"),
@@ -622,7 +623,6 @@ E0793: include_str!("./error_codes/E0793.md"),
622623
// E0488, // lifetime of variable does not enclose its declaration
623624
// E0489, // type/lifetime parameter not in scope here
624625
// E0490, // removed: unreachable
625-
E0523, // two dependencies have same (crate-name, disambiguator) but different SVH
626626
// E0526, // shuffle indices are not constant
627627
// E0540, // multiple rustc_deprecated attributes
628628
// E0548, // replaced with a generic attribute input check

Diff for: compiler/rustc_error_codes/src/error_codes/E0464.md

+15
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,21 @@
11
The compiler found multiple library files with the requested crate name.
22

3+
```compile_fail
4+
// aux-build:crateresolve-1.rs
5+
// aux-build:crateresolve-2.rs
6+
// aux-build:crateresolve-3.rs
7+
8+
extern crate crateresolve;
9+
//~^ ERROR multiple candidates for `rlib` dependency `crateresolve` found
10+
11+
fn main() {}
12+
```
13+
314
This error can occur in several different cases -- for example, when using
415
`extern crate` or passing `--extern` options without crate paths. It can also be
516
caused by caching issues with the build directory, in which case `cargo clean`
617
may help.
18+
19+
In the above example, there are three different library files, all of which
20+
define the same crate name. Without providing a full path, there is no way for
21+
the compiler to know which crate it should use.

Diff for: compiler/rustc_error_codes/src/error_codes/E0523.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
#### Note: this error code is no longer emitted by the compiler.
2+
3+
The compiler found multiple library files with the requested crate name.
4+
5+
```compile_fail
6+
// aux-build:crateresolve-1.rs
7+
// aux-build:crateresolve-2.rs
8+
// aux-build:crateresolve-3.rs
9+
10+
extern crate crateresolve;
11+
//~^ ERROR multiple candidates for `rlib` dependency `crateresolve` found
12+
13+
fn main() {}
14+
```
15+
16+
This error can occur in several different cases -- for example, when using
17+
`extern crate` or passing `--extern` options without crate paths. It can also be
18+
caused by caching issues with the build directory, in which case `cargo clean`
19+
may help.
20+
21+
In the above example, there are three different library files, all of which
22+
define the same crate name. Without providing a full path, there is no way for
23+
the compiler to know which crate it should use.
24+
25+
*Note that E0523 has been merged into E0464.*

Diff for: compiler/rustc_hir_analysis/src/coherence/builtin.rs

+1
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ fn visit_implementation_of_copy(tcx: TyCtxt<'_>, impl_did: LocalDefId) {
176176
bounds.iter().map(|(param, constraint, def_id)| {
177177
(param.as_str(), constraint.as_str(), *def_id)
178178
}),
179+
None,
179180
);
180181
err.emit();
181182
}

Diff for: compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1457,6 +1457,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
14571457
generics,
14581458
diag,
14591459
vec![(param.name.as_str(), "Clone", Some(clone_trait_did))].into_iter(),
1460+
None,
14601461
);
14611462
} else {
14621463
self.suggest_derive(diag, &[(trait_ref.to_predicate(self.tcx), None, None)]);

Diff for: compiler/rustc_infer/src/infer/error_reporting/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1922,7 +1922,8 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
19221922
(ty::Uint(ty::UintTy::U8), ty::Char) => {
19231923
if let Ok(code) = self.tcx.sess().source_map().span_to_snippet(span)
19241924
&& let Some(code) = code.strip_prefix('\'').and_then(|s| s.strip_suffix('\''))
1925-
&& code.chars().next().map_or(false, |c| c.is_ascii())
1925+
&& !code.starts_with("\\u") // forbid all Unicode escapes
1926+
&& code.chars().next().map_or(false, |c| c.is_ascii()) // forbids literal Unicode characters beyond ASCII
19261927
{
19271928
err.span_suggestion(
19281929
span,

Diff for: compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs

+66-29
Original file line numberDiff line numberDiff line change
@@ -77,49 +77,86 @@ impl<'tcx> TypeErrCtxt<'_, 'tcx> {
7777
(ty::Param(p), ty::Alias(ty::Projection, proj)) | (ty::Alias(ty::Projection, proj), ty::Param(p))
7878
if tcx.def_kind(proj.def_id) != DefKind::ImplTraitPlaceholder =>
7979
{
80-
let generics = tcx.generics_of(body_owner_def_id);
81-
let p_span = tcx.def_span(generics.type_param(p, tcx).def_id);
80+
let p_def_id = tcx
81+
.generics_of(body_owner_def_id)
82+
.type_param(p, tcx)
83+
.def_id;
84+
let p_span = tcx.def_span(p_def_id);
8285
if !sp.contains(p_span) {
8386
diag.span_label(p_span, "this type parameter");
8487
}
8588
let hir = tcx.hir();
8689
let mut note = true;
87-
if let Some(generics) = generics
88-
.type_param(p, tcx)
89-
.def_id
90+
let parent = p_def_id
9091
.as_local()
91-
.map(|id| hir.local_def_id_to_hir_id(id))
92-
.and_then(|id| tcx.hir().find_parent(id))
93-
.as_ref()
94-
.and_then(|node| node.generics())
92+
.and_then(|id| {
93+
let local_id = hir.local_def_id_to_hir_id(id);
94+
let generics = tcx.hir().find_parent(local_id)?.generics()?;
95+
Some((id, generics))
96+
});
97+
if let Some((local_id, generics)) = parent
9598
{
9699
// Synthesize the associated type restriction `Add<Output = Expected>`.
97100
// FIXME: extract this logic for use in other diagnostics.
98101
let (trait_ref, assoc_substs) = proj.trait_ref_and_own_substs(tcx);
99-
let path =
100-
tcx.def_path_str_with_substs(trait_ref.def_id, trait_ref.substs);
101102
let item_name = tcx.item_name(proj.def_id);
102103
let item_args = self.format_generic_args(assoc_substs);
103104

104-
let path = if path.ends_with('>') {
105-
format!(
106-
"{}, {}{} = {}>",
107-
&path[..path.len() - 1],
108-
item_name,
109-
item_args,
110-
p
111-
)
105+
// Here, we try to see if there's an existing
106+
// trait implementation that matches the one that
107+
// we're suggesting to restrict. If so, find the
108+
// "end", whether it be at the end of the trait
109+
// or the end of the generic arguments.
110+
let mut matching_span = None;
111+
let mut matched_end_of_args = false;
112+
for bound in generics.bounds_for_param(local_id) {
113+
let potential_spans = bound
114+
.bounds
115+
.iter()
116+
.find_map(|bound| {
117+
let bound_trait_path = bound.trait_ref()?.path;
118+
let def_id = bound_trait_path.res.opt_def_id()?;
119+
let generic_args = bound_trait_path.segments.iter().last().map(|path| path.args());
120+
(def_id == trait_ref.def_id).then_some((bound_trait_path.span, generic_args))
121+
});
122+
123+
if let Some((end_of_trait, end_of_args)) = potential_spans {
124+
let args_span = end_of_args.and_then(|args| args.span());
125+
matched_end_of_args = args_span.is_some();
126+
matching_span = args_span
127+
.or_else(|| Some(end_of_trait))
128+
.map(|span| span.shrink_to_hi());
129+
break;
130+
}
131+
}
132+
133+
if matched_end_of_args {
134+
// Append suggestion to the end of our args
135+
let path = format!(", {}{} = {}",item_name, item_args, p);
136+
note = !suggest_constraining_type_param(
137+
tcx,
138+
generics,
139+
diag,
140+
&format!("{}", proj.self_ty()),
141+
&path,
142+
None,
143+
matching_span,
144+
);
112145
} else {
113-
format!("{}<{}{} = {}>", path, item_name, item_args, p)
114-
};
115-
note = !suggest_constraining_type_param(
116-
tcx,
117-
generics,
118-
diag,
119-
&format!("{}", proj.self_ty()),
120-
&path,
121-
None,
122-
);
146+
// Suggest adding a bound to an existing trait
147+
// or if the trait doesn't exist, add the trait
148+
// and the suggested bounds.
149+
let path = format!("<{}{} = {}>", item_name, item_args, p);
150+
note = !suggest_constraining_type_param(
151+
tcx,
152+
generics,
153+
diag,
154+
&format!("{}", proj.self_ty()),
155+
&path,
156+
None,
157+
matching_span,
158+
);
159+
}
123160
}
124161
if note {
125162
diag.note("you might be missing a type parameter or trait bound");

Diff for: compiler/rustc_metadata/src/creader.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,12 @@ impl<'a> CrateLoader<'a> {
356356
for (_, other) in self.cstore.iter_crate_data() {
357357
// Same stable crate id but different SVH
358358
if other.stable_crate_id() == root.stable_crate_id() && other.hash() != root.hash() {
359-
return Err(CrateError::SymbolConflictsOthers(root.name()));
359+
bug!(
360+
"Previously returned E0523 here. \
361+
See https://github.com/rust-lang/rust/pull/100599 for additional discussion.\
362+
root.name() = {}.",
363+
root.name()
364+
);
360365
}
361366
}
362367

Diff for: compiler/rustc_metadata/src/errors.rs

-8
Original file line numberDiff line numberDiff line change
@@ -511,14 +511,6 @@ pub struct SymbolConflictsCurrent {
511511
pub crate_name: Symbol,
512512
}
513513

514-
#[derive(Diagnostic)]
515-
#[diag(metadata_symbol_conflicts_others, code = "E0523")]
516-
pub struct SymbolConflictsOthers {
517-
#[primary_span]
518-
pub span: Span,
519-
pub crate_name: Symbol,
520-
}
521-
522514
#[derive(Diagnostic)]
523515
#[diag(metadata_stable_crate_id_collision)]
524516
pub struct StableCrateIdCollision {

Diff for: compiler/rustc_metadata/src/locator.rs

-4
Original file line numberDiff line numberDiff line change
@@ -945,7 +945,6 @@ pub(crate) enum CrateError {
945945
ExternLocationNotFile(Symbol, PathBuf),
946946
MultipleCandidates(Symbol, CrateFlavor, Vec<PathBuf>),
947947
SymbolConflictsCurrent(Symbol),
948-
SymbolConflictsOthers(Symbol),
949948
StableCrateIdCollision(Symbol, Symbol),
950949
DlOpen(String),
951950
DlSym(String),
@@ -989,9 +988,6 @@ impl CrateError {
989988
CrateError::SymbolConflictsCurrent(root_name) => {
990989
sess.emit_err(errors::SymbolConflictsCurrent { span, crate_name: root_name });
991990
}
992-
CrateError::SymbolConflictsOthers(root_name) => {
993-
sess.emit_err(errors::SymbolConflictsOthers { span, crate_name: root_name });
994-
}
995991
CrateError::StableCrateIdCollision(crate_name0, crate_name1) => {
996992
sess.emit_err(errors::StableCrateIdCollision { span, crate_name0, crate_name1 });
997993
}

Diff for: compiler/rustc_middle/src/ty/diagnostics.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -193,19 +193,24 @@ fn suggest_removing_unsized_bound(
193193
}
194194

195195
/// Suggest restricting a type param with a new bound.
196+
///
197+
/// If `span_to_replace` is provided, then that span will be replaced with the
198+
/// `constraint`. If one wasn't provided, then the full bound will be suggested.
196199
pub fn suggest_constraining_type_param(
197200
tcx: TyCtxt<'_>,
198201
generics: &hir::Generics<'_>,
199202
err: &mut Diagnostic,
200203
param_name: &str,
201204
constraint: &str,
202205
def_id: Option<DefId>,
206+
span_to_replace: Option<Span>,
203207
) -> bool {
204208
suggest_constraining_type_params(
205209
tcx,
206210
generics,
207211
err,
208212
[(param_name, constraint, def_id)].into_iter(),
213+
span_to_replace,
209214
)
210215
}
211216

@@ -215,6 +220,7 @@ pub fn suggest_constraining_type_params<'a>(
215220
generics: &hir::Generics<'_>,
216221
err: &mut Diagnostic,
217222
param_names_and_constraints: impl Iterator<Item = (&'a str, &'a str, Option<DefId>)>,
223+
span_to_replace: Option<Span>,
218224
) -> bool {
219225
let mut grouped = FxHashMap::default();
220226
param_names_and_constraints.for_each(|(param_name, constraint, def_id)| {
@@ -253,7 +259,9 @@ pub fn suggest_constraining_type_params<'a>(
253259
let mut suggest_restrict = |span, bound_list_non_empty| {
254260
suggestions.push((
255261
span,
256-
if bound_list_non_empty {
262+
if span_to_replace.is_some() {
263+
constraint.clone()
264+
} else if bound_list_non_empty {
257265
format!(" + {}", constraint)
258266
} else {
259267
format!(" {}", constraint)
@@ -262,6 +270,11 @@ pub fn suggest_constraining_type_params<'a>(
262270
))
263271
};
264272

273+
if let Some(span) = span_to_replace {
274+
suggest_restrict(span, true);
275+
continue;
276+
}
277+
265278
// When the type parameter has been provided bounds
266279
//
267280
// Message:

Diff for: compiler/rustc_mir_transform/src/copy_prop.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,9 @@ impl<'tcx> MutVisitor<'tcx> for Replacer<'_, 'tcx> {
153153

154154
fn visit_operand(&mut self, operand: &mut Operand<'tcx>, loc: Location) {
155155
if let Operand::Move(place) = *operand
156-
&& let Some(local) = place.as_local()
157-
&& !self.fully_moved.contains(local)
156+
// A move out of a projection of a copy is equivalent to a copy of the original projection.
157+
&& !place.has_deref()
158+
&& !self.fully_moved.contains(place.local)
158159
{
159160
*operand = Operand::Copy(place);
160161
}

Diff for: compiler/rustc_trait_selection/src/traits/error_reporting/suggestions.rs

+2
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
679679
&param_name,
680680
&constraint,
681681
Some(trait_pred.def_id()),
682+
None,
682683
) {
683684
return;
684685
}
@@ -1087,6 +1088,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
10871088
param.name.as_str(),
10881089
"Clone",
10891090
Some(clone_trait),
1091+
None,
10901092
);
10911093
}
10921094
err.span_suggestion_verbose(

0 commit comments

Comments
 (0)