Skip to content

Commit a102fb1

Browse files
authored
Rollup merge of rust-lang#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 a102fb1

File tree

17 files changed

+94
-56
lines changed

17 files changed

+94
-56
lines changed

compiler/rustc_resolve/src/diagnostics.rs

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

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

Lines changed: 6 additions & 3 deletions
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

Lines changed: 6 additions & 3 deletions
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

Lines changed: 6 additions & 3 deletions
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

Lines changed: 6 additions & 3 deletions
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 3 additions & 9 deletions
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

Lines changed: 5 additions & 2 deletions
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

Lines changed: 6 additions & 3 deletions
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

0 commit comments

Comments
 (0)