Skip to content

Commit

Permalink
Rollup merge of rust-lang#106608 - compiler-errors:missing-generics-v…
Browse files Browse the repository at this point in the history
…erbose, 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.
  • Loading branch information
matthiaskrgr authored Jan 13, 2023
2 parents 279f1c9 + bf0623e commit a102fb1
Show file tree
Hide file tree
Showing 17 changed files with 94 additions and 56 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_resolve/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl<'a> Resolver<'a> {
);
err.emit();
} else if let Some((span, msg, sugg, appl)) = suggestion {
err.span_suggestion(span, msg, sugg, appl);
err.span_suggestion_verbose(span, msg, sugg, appl);
err.emit();
} else if let [segment] = path.as_slice() && is_call {
err.stash(segment.ident.span, rustc_errors::StashKey::CallIntoMethod);
Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_resolve/src/late/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2065,7 +2065,11 @@ impl<'a: 'ast, 'ast> LateResolutionVisitor<'a, '_, 'ast> {
path: &[Segment],
) -> Option<(Span, &'static str, String, Applicability)> {
let (ident, span) = match path {
[segment] if !segment.has_generic_args && segment.ident.name != kw::SelfUpper => {
[segment]
if !segment.has_generic_args
&& segment.ident.name != kw::SelfUpper
&& segment.ident.name != kw::Dyn =>
{
(segment.ident.to_string(), segment.ident.span)
}
_ => return None,
Expand Down
9 changes: 6 additions & 3 deletions src/tools/clippy/tests/ui/crashes/ice-6252.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@ error[E0412]: cannot find type `VAL` in this scope
--> $DIR/ice-6252.rs:10:63
|
LL | impl<N, M> TypeVal<usize> for Multiply<N, M> where N: TypeVal<VAL> {}
| - ^^^ not found in this scope
| |
| help: you might be missing a type parameter: `, VAL`
| ^^^ not found in this scope
|
help: you might be missing a type parameter
|
LL | impl<N, M, VAL> TypeVal<usize> for Multiply<N, M> where N: TypeVal<VAL> {}
| +++++

error[E0046]: not all trait items implemented, missing: `VAL`
--> $DIR/ice-6252.rs:10:1
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ error[E0412]: cannot find type `T` in this scope
--> $DIR/fn-help-with-err-generic-is-not-function.rs:2:13
|
LL | impl Struct<T>
| - ^ not found in this scope
| |
| help: you might be missing a type parameter: `<T>`
| ^ not found in this scope
|
help: you might be missing a type parameter
|
LL | impl<T> Struct<T>
| +++

error[E0412]: cannot find type `T` in this scope
--> $DIR/fn-help-with-err-generic-is-not-function.rs:7:5
Expand Down
9 changes: 6 additions & 3 deletions tests/ui/issues/issue-58712.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ error[E0412]: cannot find type `DeviceId` in this scope
--> $DIR/issue-58712.rs:6:20
|
LL | impl<H> AddrVec<H, DeviceId> {
| - ^^^^^^^^ not found in this scope
| |
| help: you might be missing a type parameter: `, DeviceId`
| ^^^^^^^^ not found in this scope
|
help: you might be missing a type parameter
|
LL | impl<H, DeviceId> AddrVec<H, DeviceId> {
| ++++++++++

error[E0412]: cannot find type `DeviceId` in this scope
--> $DIR/issue-58712.rs:8:29
Expand Down
9 changes: 6 additions & 3 deletions tests/ui/issues/issue-77919.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ error[E0412]: cannot find type `VAL` in this scope
--> $DIR/issue-77919.rs:11:63
|
LL | impl<N, M> TypeVal<usize> for Multiply<N, M> where N: TypeVal<VAL> {}
| - ^^^ not found in this scope
| |
| help: you might be missing a type parameter: `, VAL`
| ^^^ not found in this scope
|
help: you might be missing a type parameter
|
LL | impl<N, M, VAL> TypeVal<usize> for Multiply<N, M> where N: TypeVal<VAL> {}
| +++++

error[E0046]: not all trait items implemented, missing: `VAL`
--> $DIR/issue-77919.rs:11:1
Expand Down
2 changes: 0 additions & 2 deletions tests/ui/issues/issue-86756.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ LL | trait Foo<T, T = T> {}
error[E0412]: cannot find type `dyn` in this scope
--> $DIR/issue-86756.rs:5:10
|
LL | fn eq<A, B>() {
| - help: you might be missing a type parameter: `, dyn`
LL | eq::<dyn, Foo>
| ^^^ not found in this scope

Expand Down
12 changes: 3 additions & 9 deletions tests/ui/parser/dyn-trait-compatibility.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,13 @@ error[E0412]: cannot find type `dyn` in this scope
--> $DIR/dyn-trait-compatibility.rs:5:15
|
LL | type A2 = dyn<dyn, dyn>;
| - ^^^ not found in this scope
| |
| help: you might be missing a type parameter: `<dyn>`
| ^^^ not found in this scope

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

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

error: aborting due to 8 previous errors

Expand Down
7 changes: 5 additions & 2 deletions tests/ui/suggestions/type-not-found-in-adt-field.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@ LL | m: Vec<Someunknownname<String, ()>>,
error[E0412]: cannot find type `K` in this scope
--> $DIR/type-not-found-in-adt-field.rs:6:8
|
LL | struct OtherStruct {
| - help: you might be missing a type parameter: `<K>`
LL | m: K,
| ^ not found in this scope
|
help: you might be missing a type parameter
|
LL | struct OtherStruct<K> {
| +++

error: aborting due to 2 previous errors

Expand Down
9 changes: 6 additions & 3 deletions tests/ui/traits/ignore-err-impls.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ error[E0412]: cannot find type `Type` in this scope
--> $DIR/ignore-err-impls.rs:6:14
|
LL | impl Generic<Type> for S {}
| - ^^^^ not found in this scope
| |
| help: you might be missing a type parameter: `<Type>`
| ^^^^ not found in this scope
|
help: you might be missing a type parameter
|
LL | impl<Type> Generic<Type> for S {}
| ++++++

error: aborting due to previous error

Expand Down
27 changes: 18 additions & 9 deletions tests/ui/traits/issue-50480.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ error[E0412]: cannot find type `N` in this scope
--> $DIR/issue-50480.rs:3:12
|
LL | struct Foo(N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String);
| -^ not found in this scope
| |
| help: you might be missing a type parameter: `<N>`
| ^ not found in this scope
|
help: you might be missing a type parameter
|
LL | struct Foo<N>(N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String);
| +++

error[E0412]: cannot find type `NotDefined` in this scope
--> $DIR/issue-50480.rs:3:15
Expand All @@ -16,17 +19,23 @@ error[E0412]: cannot find type `N` in this scope
--> $DIR/issue-50480.rs:3:12
|
LL | struct Foo(N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String);
| -^ not found in this scope
| |
| help: you might be missing a type parameter: `<N>`
| ^ not found in this scope
|
help: you might be missing a type parameter
|
LL | struct Foo<N>(N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String);
| +++

error[E0412]: cannot find type `NotDefined` in this scope
--> $DIR/issue-50480.rs:3:15
|
LL | struct Foo(N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String);
| - ^^^^^^^^^^ not found in this scope
| |
| help: you might be missing a type parameter: `<NotDefined>`
| ^^^^^^^^^^ not found in this scope
|
help: you might be missing a type parameter
|
LL | struct Foo<NotDefined>(N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String);
| ++++++++++++

error[E0412]: cannot find type `N` in this scope
--> $DIR/issue-50480.rs:12:18
Expand Down
9 changes: 6 additions & 3 deletions tests/ui/traits/issue-75627.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ error[E0412]: cannot find type `T` in this scope
--> $DIR/issue-75627.rs:3:26
|
LL | unsafe impl Send for Foo<T> {}
| - ^ not found in this scope
| |
| help: you might be missing a type parameter: `<T>`
| ^ not found in this scope
|
help: you might be missing a type parameter
|
LL | unsafe impl<T> Send for Foo<T> {}
| +++

error: aborting due to previous error

Expand Down
9 changes: 6 additions & 3 deletions tests/ui/traits/issue-78372.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,12 @@ error[E0412]: cannot find type `MISC` in this scope
--> $DIR/issue-78372.rs:3:34
|
LL | impl<T> DispatchFromDyn<Smaht<U, MISC>> for T {}
| - ^^^^ not found in this scope
| |
| help: you might be missing a type parameter: `, MISC`
| ^^^^ not found in this scope
|
help: you might be missing a type parameter
|
LL | impl<T, MISC> DispatchFromDyn<Smaht<U, MISC>> for T {}
| ++++++

error[E0658]: use of unstable library feature 'dispatch_from_dyn'
--> $DIR/issue-78372.rs:1:5
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
error[E0412]: cannot find type `Dst` in this scope
--> $DIR/unknown_dst.rs:20:36
|
LL | fn should_gracefully_handle_unknown_dst() {
| - help: you might be missing a type parameter: `<Dst>`
...
LL | assert::is_transmutable::<Src, Dst, Context>();
| ^^^ not found in this scope
|
help: you might be missing a type parameter
|
LL | fn should_gracefully_handle_unknown_dst<Dst>() {
| +++++

error: aborting due to previous error

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
error[E0412]: cannot find type `Src` in this scope
--> $DIR/unknown_src.rs:20:31
|
LL | fn should_gracefully_handle_unknown_src() {
| - help: you might be missing a type parameter: `<Src>`
...
LL | assert::is_transmutable::<Src, Dst, Context>();
| ^^^ not found in this scope
|
help: you might be missing a type parameter
|
LL | fn should_gracefully_handle_unknown_src<Src>() {
| +++++

error: aborting due to previous error

Expand Down
8 changes: 5 additions & 3 deletions tests/ui/typeck/autoderef-with-param-env-error.stderr
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
error[E0412]: cannot find type `T` in this scope
--> $DIR/autoderef-with-param-env-error.rs:3:5
|
LL | fn foo()
| - help: you might be missing a type parameter: `<T>`
LL | where
LL | T: Send,
| ^ not found in this scope
|
help: you might be missing a type parameter
|
LL | fn foo<T>()
| +++

error: aborting due to previous error

Expand Down
7 changes: 5 additions & 2 deletions tests/ui/typeck/issue-104513-ice.stderr
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
error[E0405]: cannot find trait `Oops` in this scope
--> $DIR/issue-104513-ice.rs:3:19
|
LL | fn f() {
| - help: you might be missing a type parameter: `<Oops>`
LL | let _: S<impl Oops> = S;
| ^^^^ not found in this scope
|
help: you might be missing a type parameter
|
LL | fn f<Oops>() {
| ++++++

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

0 comments on commit a102fb1

Please sign in to comment.