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

.github/workflows/ci.yml

Lines changed: 1 addition & 2 deletions
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:

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 1 addition & 0 deletions
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
}

compiler/rustc_const_eval/src/transform/check_consts/ops.rs

Lines changed: 1 addition & 0 deletions
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
}

compiler/rustc_error_codes/src/error_codes.rs

Lines changed: 1 addition & 1 deletion
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
Lines changed: 15 additions & 0 deletions
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.
Lines changed: 25 additions & 0 deletions
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.*

compiler/rustc_hir_analysis/src/coherence/builtin.rs

Lines changed: 1 addition & 0 deletions
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
}

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

Lines changed: 1 addition & 0 deletions
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)]);

compiler/rustc_infer/src/infer/error_reporting/mod.rs

Lines changed: 2 additions & 1 deletion
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,

compiler/rustc_infer/src/infer/error_reporting/note_and_explain.rs

Lines changed: 66 additions & 29 deletions
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");

0 commit comments

Comments
 (0)