Skip to content

Commit 75e7789

Browse files
authored
Rollup merge of rust-lang#134256 - krtab:suggestion_overlapping, r=petrochenkov
Use a more precise span in placeholder_type_error_diag Closes: rust-lang#123861
2 parents 87bbbcd + af530c4 commit 75e7789

File tree

4 files changed

+64
-8
lines changed

4 files changed

+64
-8
lines changed

compiler/rustc_hir_analysis/src/collect.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -201,12 +201,13 @@ pub(crate) fn placeholder_type_error_diag<'cx, 'tcx>(
201201
placeholder_types.iter().map(|sp| (*sp, (*type_name).to_string())).collect();
202202

203203
if let Some(generics) = generics {
204-
if let Some(arg) = params.iter().find(|arg| {
205-
matches!(arg.name, hir::ParamName::Plain(Ident { name: kw::Underscore, .. }))
204+
if let Some(span) = params.iter().find_map(|arg| match arg.name {
205+
hir::ParamName::Plain(Ident { name: kw::Underscore, span }) => Some(span),
206+
_ => None,
206207
}) {
207208
// Account for `_` already present in cases like `struct S<_>(_);` and suggest
208209
// `struct S<T>(T);` instead of `struct S<_, T>(T);`.
209-
sugg.push((arg.span, (*type_name).to_string()));
210+
sugg.push((span, (*type_name).to_string()));
210211
} else if let Some(span) = generics.span_for_param_suggestion() {
211212
// Account for bounds, we want `fn foo<T: E, K>(_: K)` not `fn foo<T, K: E>(_: K)`.
212213
sugg.push((span, format!(", {type_name}")));

tests/crashes/123861.rs

-5
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
fn mainIterator<_ = _> {}
2+
//~^ ERROR expected identifier, found reserved identifier `_`
3+
//~| ERROR missing parameters for function definition
4+
//~| ERROR defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions [invalid_type_param_default]
5+
//~| WARNING this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
6+
//~| ERROR the placeholder `_` is not allowed within types on item signatures for functions [E0121]
7+
8+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
error: expected identifier, found reserved identifier `_`
2+
--> $DIR/overlapping-errors-span-issue-123861.rs:1:17
3+
|
4+
LL | fn mainIterator<_ = _> {}
5+
| ^ expected identifier, found reserved identifier
6+
7+
error: missing parameters for function definition
8+
--> $DIR/overlapping-errors-span-issue-123861.rs:1:23
9+
|
10+
LL | fn mainIterator<_ = _> {}
11+
| ^
12+
|
13+
help: add a parameter list
14+
|
15+
LL | fn mainIterator<_ = _>() {}
16+
| ++
17+
18+
error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
19+
--> $DIR/overlapping-errors-span-issue-123861.rs:1:17
20+
|
21+
LL | fn mainIterator<_ = _> {}
22+
| ^^^^^
23+
|
24+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
25+
= note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
26+
= note: `#[deny(invalid_type_param_default)]` on by default
27+
28+
error[E0121]: the placeholder `_` is not allowed within types on item signatures for functions
29+
--> $DIR/overlapping-errors-span-issue-123861.rs:1:21
30+
|
31+
LL | fn mainIterator<_ = _> {}
32+
| ^ not allowed in type signatures
33+
|
34+
help: use type parameters instead
35+
|
36+
LL | fn mainIterator<T = T> {}
37+
| ~ ~
38+
39+
error: aborting due to 4 previous errors
40+
41+
For more information about this error, try `rustc --explain E0121`.
42+
Future incompatibility report: Future breakage diagnostic:
43+
error: defaults for type parameters are only allowed in `struct`, `enum`, `type`, or `trait` definitions
44+
--> $DIR/overlapping-errors-span-issue-123861.rs:1:17
45+
|
46+
LL | fn mainIterator<_ = _> {}
47+
| ^^^^^
48+
|
49+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
50+
= note: for more information, see issue #36887 <https://github.com/rust-lang/rust/issues/36887>
51+
= note: `#[deny(invalid_type_param_default)]` on by default
52+

0 commit comments

Comments
 (0)