Skip to content

Commit 9a2f393

Browse files
author
Yuki Okushi
authored
Rollup merge of #106608 - compiler-errors:missing-generics-verbose, r=estebank
Render missing generics suggestion verbosely It's a bit easier to read like this, especially ones that are appending new generics onto an existing list, like ": `, T`" which render somewhat poorly inline. Also don't suggest `dyn` as a type parameter to add, even if technically that's valid in edition 2015.
2 parents 279f1c9 + bf0623e commit 9a2f393

17 files changed

+94
-56
lines changed

compiler/rustc_resolve/src/diagnostics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl<'a> Resolver<'a> {
167167
);
168168
err.emit();
169169
} else if let Some((span, msg, sugg, appl)) = suggestion {
170-
err.span_suggestion(span, msg, sugg, appl);
170+
err.span_suggestion_verbose(span, msg, sugg, appl);
171171
err.emit();
172172
} else if let [segment] = path.as_slice() && is_call {
173173
err.stash(segment.ident.span, rustc_errors::StashKey::CallIntoMethod);

compiler/rustc_resolve/src/late/diagnostics.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -2065,7 +2065,11 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
20652065
path: &[Segment],
20662066
) -> Option<(Span, &'static str, String, Applicability)> {
20672067
let (ident, span) = match path {
2068-
[segment] if !segment.has_generic_args && segment.ident.name != kw::SelfUpper => {
2068+
[segment]
2069+
if !segment.has_generic_args
2070+
&& segment.ident.name != kw::SelfUpper
2071+
&& segment.ident.name != kw::Dyn =>
2072+
{
20692073
(segment.ident.to_string(), segment.ident.span)
20702074
}
20712075
_ => return None,

src/tools/clippy/tests/ui/crashes/ice-6252.stderr

+6-3
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,12 @@ error[E0412]: cannot find type `VAL` in this scope
1717
--> $DIR/ice-6252.rs:10:63
1818
|
1919
LL | impl<N, M> TypeVal<usize> for Multiply<N, M> where N: TypeVal<VAL> {}
20-
| - ^^^ not found in this scope
21-
| |
22-
| help: you might be missing a type parameter: `, VAL`
20+
| ^^^ not found in this scope
21+
|
22+
help: you might be missing a type parameter
23+
|
24+
LL | impl<N, M, VAL> TypeVal<usize> for Multiply<N, M> where N: TypeVal<VAL> {}
25+
| +++++
2326

2427
error[E0046]: not all trait items implemented, missing: `VAL`
2528
--> $DIR/ice-6252.rs:10:1

tests/ui/functions-closures/fn-help-with-err-generic-is-not-function.stderr

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ error[E0412]: cannot find type `T` in this scope
22
--> $DIR/fn-help-with-err-generic-is-not-function.rs:2:13
33
|
44
LL | impl Struct<T>
5-
| - ^ not found in this scope
6-
| |
7-
| help: you might be missing a type parameter: `<T>`
5+
| ^ not found in this scope
6+
|
7+
help: you might be missing a type parameter
8+
|
9+
LL | impl<T> Struct<T>
10+
| +++
811

912
error[E0412]: cannot find type `T` in this scope
1013
--> $DIR/fn-help-with-err-generic-is-not-function.rs:7:5

tests/ui/issues/issue-58712.stderr

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ error[E0412]: cannot find type `DeviceId` in this scope
22
--> $DIR/issue-58712.rs:6:20
33
|
44
LL | impl<H> AddrVec<H, DeviceId> {
5-
| - ^^^^^^^^ not found in this scope
6-
| |
7-
| help: you might be missing a type parameter: `, DeviceId`
5+
| ^^^^^^^^ not found in this scope
6+
|
7+
help: you might be missing a type parameter
8+
|
9+
LL | impl<H, DeviceId> AddrVec<H, DeviceId> {
10+
| ++++++++++
811

912
error[E0412]: cannot find type `DeviceId` in this scope
1013
--> $DIR/issue-58712.rs:8:29

tests/ui/issues/issue-77919.stderr

+6-3
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ error[E0412]: cannot find type `VAL` in this scope
1313
--> $DIR/issue-77919.rs:11:63
1414
|
1515
LL | impl<N, M> TypeVal<usize> for Multiply<N, M> where N: TypeVal<VAL> {}
16-
| - ^^^ not found in this scope
17-
| |
18-
| help: you might be missing a type parameter: `, VAL`
16+
| ^^^ not found in this scope
17+
|
18+
help: you might be missing a type parameter
19+
|
20+
LL | impl<N, M, VAL> TypeVal<usize> for Multiply<N, M> where N: TypeVal<VAL> {}
21+
| +++++
1922

2023
error[E0046]: not all trait items implemented, missing: `VAL`
2124
--> $DIR/issue-77919.rs:11:1

tests/ui/issues/issue-86756.stderr

-2
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ LL | trait Foo<T, T = T> {}
99
error[E0412]: cannot find type `dyn` in this scope
1010
--> $DIR/issue-86756.rs:5:10
1111
|
12-
LL | fn eq<A, B>() {
13-
| - help: you might be missing a type parameter: `, dyn`
1412
LL | eq::<dyn, Foo>
1513
| ^^^ not found in this scope
1614

tests/ui/parser/dyn-trait-compatibility.stderr

+3-9
Original file line numberDiff line numberDiff line change
@@ -26,17 +26,13 @@ error[E0412]: cannot find type `dyn` in this scope
2626
--> $DIR/dyn-trait-compatibility.rs:5:15
2727
|
2828
LL | type A2 = dyn<dyn, dyn>;
29-
| - ^^^ not found in this scope
30-
| |
31-
| help: you might be missing a type parameter: `<dyn>`
29+
| ^^^ not found in this scope
3230

3331
error[E0412]: cannot find type `dyn` in this scope
3432
--> $DIR/dyn-trait-compatibility.rs:5:20
3533
|
3634
LL | type A2 = dyn<dyn, dyn>;
37-
| - ^^^ not found in this scope
38-
| |
39-
| help: you might be missing a type parameter: `<dyn>`
35+
| ^^^ not found in this scope
4036

4137
error[E0412]: cannot find type `dyn` in this scope
4238
--> $DIR/dyn-trait-compatibility.rs:9:11
@@ -48,9 +44,7 @@ error[E0412]: cannot find type `dyn` in this scope
4844
--> $DIR/dyn-trait-compatibility.rs:9:16
4945
|
5046
LL | type A3 = dyn<<dyn as dyn>::dyn>;
51-
| - ^^^ not found in this scope
52-
| |
53-
| help: you might be missing a type parameter: `<dyn>`
47+
| ^^^ not found in this scope
5448

5549
error: aborting due to 8 previous errors
5650

tests/ui/suggestions/type-not-found-in-adt-field.stderr

+5-2
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,13 @@ LL | m: Vec<Someunknownname<String, ()>>,
77
error[E0412]: cannot find type `K` in this scope
88
--> $DIR/type-not-found-in-adt-field.rs:6:8
99
|
10-
LL | struct OtherStruct {
11-
| - help: you might be missing a type parameter: `<K>`
1210
LL | m: K,
1311
| ^ not found in this scope
12+
|
13+
help: you might be missing a type parameter
14+
|
15+
LL | struct OtherStruct<K> {
16+
| +++
1417

1518
error: aborting due to 2 previous errors
1619

tests/ui/traits/ignore-err-impls.stderr

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ error[E0412]: cannot find type `Type` in this scope
22
--> $DIR/ignore-err-impls.rs:6:14
33
|
44
LL | impl Generic<Type> for S {}
5-
| - ^^^^ not found in this scope
6-
| |
7-
| help: you might be missing a type parameter: `<Type>`
5+
| ^^^^ not found in this scope
6+
|
7+
help: you might be missing a type parameter
8+
|
9+
LL | impl<Type> Generic<Type> for S {}
10+
| ++++++
811

912
error: aborting due to previous error
1013

tests/ui/traits/issue-50480.stderr

+18-9
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ error[E0412]: cannot find type `N` in this scope
22
--> $DIR/issue-50480.rs:3:12
33
|
44
LL | struct Foo(N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String);
5-
| -^ not found in this scope
6-
| |
7-
| help: you might be missing a type parameter: `<N>`
5+
| ^ not found in this scope
6+
|
7+
help: you might be missing a type parameter
8+
|
9+
LL | struct Foo<N>(N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String);
10+
| +++
811

912
error[E0412]: cannot find type `NotDefined` in this scope
1013
--> $DIR/issue-50480.rs:3:15
@@ -16,17 +19,23 @@ error[E0412]: cannot find type `N` in this scope
1619
--> $DIR/issue-50480.rs:3:12
1720
|
1821
LL | struct Foo(N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String);
19-
| -^ not found in this scope
20-
| |
21-
| help: you might be missing a type parameter: `<N>`
22+
| ^ not found in this scope
23+
|
24+
help: you might be missing a type parameter
25+
|
26+
LL | struct Foo<N>(N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String);
27+
| +++
2228

2329
error[E0412]: cannot find type `NotDefined` in this scope
2430
--> $DIR/issue-50480.rs:3:15
2531
|
2632
LL | struct Foo(N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String);
27-
| - ^^^^^^^^^^ not found in this scope
28-
| |
29-
| help: you might be missing a type parameter: `<NotDefined>`
33+
| ^^^^^^^^^^ not found in this scope
34+
|
35+
help: you might be missing a type parameter
36+
|
37+
LL | struct Foo<NotDefined>(N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String);
38+
| ++++++++++++
3039

3140
error[E0412]: cannot find type `N` in this scope
3241
--> $DIR/issue-50480.rs:12:18

tests/ui/traits/issue-75627.stderr

+6-3
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@ error[E0412]: cannot find type `T` in this scope
22
--> $DIR/issue-75627.rs:3:26
33
|
44
LL | unsafe impl Send for Foo<T> {}
5-
| - ^ not found in this scope
6-
| |
7-
| help: you might be missing a type parameter: `<T>`
5+
| ^ not found in this scope
6+
|
7+
help: you might be missing a type parameter
8+
|
9+
LL | unsafe impl<T> Send for Foo<T> {}
10+
| +++
811

912
error: aborting due to previous error
1013

tests/ui/traits/issue-78372.stderr

+6-3
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@ error[E0412]: cannot find type `MISC` in this scope
3030
--> $DIR/issue-78372.rs:3:34
3131
|
3232
LL | impl<T> DispatchFromDyn<Smaht<U, MISC>> for T {}
33-
| - ^^^^ not found in this scope
34-
| |
35-
| help: you might be missing a type parameter: `, MISC`
33+
| ^^^^ not found in this scope
34+
|
35+
help: you might be missing a type parameter
36+
|
37+
LL | impl<T, MISC> DispatchFromDyn<Smaht<U, MISC>> for T {}
38+
| ++++++
3639

3740
error[E0658]: use of unstable library feature 'dispatch_from_dyn'
3841
--> $DIR/issue-78372.rs:1:5

tests/ui/transmutability/malformed-program-gracefulness/unknown_dst.stderr

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
error[E0412]: cannot find type `Dst` in this scope
22
--> $DIR/unknown_dst.rs:20:36
33
|
4-
LL | fn should_gracefully_handle_unknown_dst() {
5-
| - help: you might be missing a type parameter: `<Dst>`
6-
...
74
LL | assert::is_transmutable::<Src, Dst, Context>();
85
| ^^^ not found in this scope
6+
|
7+
help: you might be missing a type parameter
8+
|
9+
LL | fn should_gracefully_handle_unknown_dst<Dst>() {
10+
| +++++
911

1012
error: aborting due to previous error
1113

tests/ui/transmutability/malformed-program-gracefulness/unknown_src.stderr

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
error[E0412]: cannot find type `Src` in this scope
22
--> $DIR/unknown_src.rs:20:31
33
|
4-
LL | fn should_gracefully_handle_unknown_src() {
5-
| - help: you might be missing a type parameter: `<Src>`
6-
...
74
LL | assert::is_transmutable::<Src, Dst, Context>();
85
| ^^^ not found in this scope
6+
|
7+
help: you might be missing a type parameter
8+
|
9+
LL | fn should_gracefully_handle_unknown_src<Src>() {
10+
| +++++
911

1012
error: aborting due to previous error
1113

tests/ui/typeck/autoderef-with-param-env-error.stderr

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
error[E0412]: cannot find type `T` in this scope
22
--> $DIR/autoderef-with-param-env-error.rs:3:5
33
|
4-
LL | fn foo()
5-
| - help: you might be missing a type parameter: `<T>`
6-
LL | where
74
LL | T: Send,
85
| ^ not found in this scope
6+
|
7+
help: you might be missing a type parameter
8+
|
9+
LL | fn foo<T>()
10+
| +++
911

1012
error: aborting due to previous error
1113

tests/ui/typeck/issue-104513-ice.stderr

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
error[E0405]: cannot find trait `Oops` in this scope
22
--> $DIR/issue-104513-ice.rs:3:19
33
|
4-
LL | fn f() {
5-
| - help: you might be missing a type parameter: `<Oops>`
64
LL | let _: S<impl Oops> = S;
75
| ^^^^ not found in this scope
6+
|
7+
help: you might be missing a type parameter
8+
|
9+
LL | fn f<Oops>() {
10+
| ++++++
811

912
error[E0562]: `impl Trait` only allowed in function and inherent method return types, not in variable binding
1013
--> $DIR/issue-104513-ice.rs:3:14

0 commit comments

Comments
 (0)