diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2021-12-04 10:42:20 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-04 10:42:20 +0100 |
| commit | 0311cfa88cd4f86493b197ad4d337eb6085c8c03 (patch) | |
| tree | 9cec8a6ff34e219b97d4f32ed62812b50533be54 /src | |
| parent | 9f8e822364e23b500a20fbebc439817c6c59d355 (diff) | |
| parent | b0c3968615d8728fb0476bd81fa58903aca5d191 (diff) | |
| download | rust-0311cfa88cd4f86493b197ad4d337eb6085c8c03.tar.gz rust-0311cfa88cd4f86493b197ad4d337eb6085c8c03.zip | |
Rollup merge of #90519 - estebank:issue-84003, r=petrochenkov
Keep spans for generics in `#[derive(_)]` desugaring Keep the spans for generics coming from a `derive`d Item, so that errors and suggestions have better detail. Fix #84003.
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/ui/issues/issue-38821.stderr | 4 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-50480.rs | 11 | ||||
| -rw-r--r-- | src/test/ui/issues/issue-50480.stderr | 89 | ||||
| -rw-r--r-- | src/test/ui/lifetimes/undeclared-lifetime-used-in-debug-macro-issue-70152.stderr | 3 | ||||
| -rw-r--r-- | src/test/ui/suggestions/derive-macro-missing-bounds.rs | 89 | ||||
| -rw-r--r-- | src/test/ui/suggestions/derive-macro-missing-bounds.stderr | 107 |
6 files changed, 287 insertions, 16 deletions
diff --git a/src/test/ui/issues/issue-38821.stderr b/src/test/ui/issues/issue-38821.stderr index e53a543f3a0..cdf1f0dfc53 100644 --- a/src/test/ui/issues/issue-38821.stderr +++ b/src/test/ui/issues/issue-38821.stderr @@ -10,6 +10,10 @@ note: required because of the requirements on the impl of `IntoNullable` for `<C LL | impl<T: NotNull> IntoNullable for T { | ^^^^^^^^^^^^ ^ = note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider further restricting the associated type + | +LL | Expr: Expression<SqlType=<Col::SqlType as IntoNullable>::Nullable>, <Col as Expression>::SqlType: NotNull, + | +++++++++++++++++++++++++++++++++++++++ error: aborting due to previous error diff --git a/src/test/ui/issues/issue-50480.rs b/src/test/ui/issues/issue-50480.rs index deb63872f69..10597caf5b2 100644 --- a/src/test/ui/issues/issue-50480.rs +++ b/src/test/ui/issues/issue-50480.rs @@ -1,8 +1,17 @@ #[derive(Clone, Copy)] //~^ ERROR the trait `Copy` may not be implemented for this type -struct Foo(NotDefined, <i32 as Iterator>::Item, Vec<i32>, String); +struct Foo(N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String); //~^ ERROR cannot find type `NotDefined` in this scope //~| ERROR cannot find type `NotDefined` in this scope +//~| ERROR cannot find type `N` in this scope +//~| ERROR cannot find type `N` in this scope +//~| ERROR `i32` is not an iterator + +#[derive(Clone, Copy)] +//~^ ERROR the trait `Copy` may not be implemented for this type +struct Bar<T>(T, N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String); +//~^ ERROR cannot find type `NotDefined` in this scope +//~| ERROR cannot find type `N` in this scope //~| ERROR `i32` is not an iterator fn main() {} diff --git a/src/test/ui/issues/issue-50480.stderr b/src/test/ui/issues/issue-50480.stderr index 15f38c89267..0bb1f9ae035 100644 --- a/src/test/ui/issues/issue-50480.stderr +++ b/src/test/ui/issues/issue-50480.stderr @@ -1,20 +1,61 @@ -error[E0412]: cannot find type `NotDefined` in this scope +error[E0412]: cannot find type `N` in this scope --> $DIR/issue-50480.rs:3:12 | -LL | struct Foo(NotDefined, <i32 as Iterator>::Item, Vec<i32>, String); - | ^^^^^^^^^^ not found in this scope +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>` 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 + +error[E0412]: cannot find type `N` in this scope --> $DIR/issue-50480.rs:3:12 | -LL | struct Foo(NotDefined, <i32 as Iterator>::Item, Vec<i32>, String); - | ^^^^^^^^^^ not found in this scope +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>` + +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>` + +error[E0412]: cannot find type `N` in this scope + --> $DIR/issue-50480.rs:12:18 + | +LL | struct Bar<T>(T, N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String); + | - ^ + | | + | similarly named type parameter `T` defined here + | +help: a type parameter with a similar name exists + | +LL | struct Bar<T>(T, T, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String); + | ~ +help: you might be missing a type parameter + | +LL | struct Bar<T, N>(T, N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String); + | +++ + +error[E0412]: cannot find type `NotDefined` in this scope + --> $DIR/issue-50480.rs:12:21 + | +LL | struct Bar<T>(T, N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String); + | ^^^^^^^^^^ not found in this scope error[E0277]: `i32` is not an iterator - --> $DIR/issue-50480.rs:3:24 + --> $DIR/issue-50480.rs:3:27 | -LL | struct Foo(NotDefined, <i32 as Iterator>::Item, Vec<i32>, String); - | ^^^^^^^^^^^^^^^^^^^^^^^ `i32` is not an iterator +LL | struct Foo(N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String); + | ^^^^^^^^^^^^^^^^^^^^^^^ `i32` is not an iterator | = help: the trait `Iterator` is not implemented for `i32` = note: if you want to iterate between `start` until a value `end`, use the exclusive range syntax `start..end` or the inclusive range syntax `start..=end` @@ -25,14 +66,36 @@ error[E0204]: the trait `Copy` may not be implemented for this type LL | #[derive(Clone, Copy)] | ^^^^ LL | -LL | struct Foo(NotDefined, <i32 as Iterator>::Item, Vec<i32>, String); - | -------- ------ this field does not implement `Copy` - | | - | this field does not implement `Copy` +LL | struct Foo(N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String); + | -------- ------ this field does not implement `Copy` + | | + | this field does not implement `Copy` + | + = note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info) + +error[E0277]: `i32` is not an iterator + --> $DIR/issue-50480.rs:12:33 + | +LL | struct Bar<T>(T, N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String); + | ^^^^^^^^^^^^^^^^^^^^^^^ `i32` is not an iterator + | + = help: the trait `Iterator` is not implemented for `i32` + = note: if you want to iterate between `start` until a value `end`, use the exclusive range syntax `start..end` or the inclusive range syntax `start..=end` + +error[E0204]: the trait `Copy` may not be implemented for this type + --> $DIR/issue-50480.rs:10:17 + | +LL | #[derive(Clone, Copy)] + | ^^^^ +LL | +LL | struct Bar<T>(T, N, NotDefined, <i32 as Iterator>::Item, Vec<i32>, String); + | -------- ------ this field does not implement `Copy` + | | + | this field does not implement `Copy` | = note: this error originates in the derive macro `Copy` (in Nightly builds, run with -Z macro-backtrace for more info) -error: aborting due to 4 previous errors +error: aborting due to 10 previous errors Some errors have detailed explanations: E0204, E0277, E0412. For more information about an error, try `rustc --explain E0204`. diff --git a/src/test/ui/lifetimes/undeclared-lifetime-used-in-debug-macro-issue-70152.stderr b/src/test/ui/lifetimes/undeclared-lifetime-used-in-debug-macro-issue-70152.stderr index e18d725faef..a2086895234 100644 --- a/src/test/ui/lifetimes/undeclared-lifetime-used-in-debug-macro-issue-70152.stderr +++ b/src/test/ui/lifetimes/undeclared-lifetime-used-in-debug-macro-issue-70152.stderr @@ -11,9 +11,8 @@ LL | a: &'b str, error[E0261]: use of undeclared lifetime name `'b` --> $DIR/undeclared-lifetime-used-in-debug-macro-issue-70152.rs:3:9 | -LL | #[derive(Eq, PartialEq)] - | -- lifetime `'b` is missing in item created through this procedural macro LL | struct Test { + | - help: consider introducing lifetime `'b` here: `<'b>` LL | a: &'b str, | ^^ undeclared lifetime | diff --git a/src/test/ui/suggestions/derive-macro-missing-bounds.rs b/src/test/ui/suggestions/derive-macro-missing-bounds.rs new file mode 100644 index 00000000000..56c218f97eb --- /dev/null +++ b/src/test/ui/suggestions/derive-macro-missing-bounds.rs @@ -0,0 +1,89 @@ +mod a { + use std::fmt::{Debug, Formatter, Result}; + struct Inner<T>(T); + + impl Debug for Inner<()> { + fn fmt(&self, f: &mut Formatter<'_>) -> Result { + todo!() + } + } + + #[derive(Debug)] + struct Outer<T>(Inner<T>); //~ ERROR `a::Inner<T>` doesn't implement `Debug` +} + +mod b { + use std::fmt::{Debug, Formatter, Result}; + struct Inner<T>(T); + + impl<T: Debug> Debug for Inner<T> { + fn fmt(&self, f: &mut Formatter<'_>) -> Result { + todo!() + } + } + + #[derive(Debug)] + struct Outer<T>(Inner<T>); +} + +mod c { + use std::fmt::{Debug, Formatter, Result}; + struct Inner<T>(T); + trait Trait {} + + impl<T: Debug + Trait> Debug for Inner<T> { + fn fmt(&self, f: &mut Formatter<'_>) -> Result { + todo!() + } + } + + #[derive(Debug)] + struct Outer<T>(Inner<T>); //~ ERROR the trait bound `T: c::Trait` is not satisfied +} + +mod d { + use std::fmt::{Debug, Formatter, Result}; + struct Inner<T>(T); + trait Trait {} + + impl<T> Debug for Inner<T> where T: Debug, T: Trait { + fn fmt(&self, f: &mut Formatter<'_>) -> Result { + todo!() + } + } + + #[derive(Debug)] + struct Outer<T>(Inner<T>); //~ ERROR the trait bound `T: d::Trait` is not satisfied +} + +mod e { + use std::fmt::{Debug, Formatter, Result}; + struct Inner<T>(T); + trait Trait {} + + impl<T> Debug for Inner<T> where T: Debug + Trait { + fn fmt(&self, f: &mut Formatter<'_>) -> Result { + todo!() + } + } + + #[derive(Debug)] + struct Outer<T>(Inner<T>); //~ ERROR the trait bound `T: e::Trait` is not satisfied +} + +mod f { + use std::fmt::{Debug, Formatter, Result}; + struct Inner<T>(T); + trait Trait {} + + impl<T: Debug> Debug for Inner<T> where T: Trait { + fn fmt(&self, f: &mut Formatter<'_>) -> Result { + todo!() + } + } + + #[derive(Debug)] + struct Outer<T>(Inner<T>); //~ ERROR the trait bound `T: f::Trait` is not satisfied +} + +fn main() {} diff --git a/src/test/ui/suggestions/derive-macro-missing-bounds.stderr b/src/test/ui/suggestions/derive-macro-missing-bounds.stderr new file mode 100644 index 00000000000..7a4f7e209c1 --- /dev/null +++ b/src/test/ui/suggestions/derive-macro-missing-bounds.stderr @@ -0,0 +1,107 @@ +error[E0277]: `a::Inner<T>` doesn't implement `Debug` + --> $DIR/derive-macro-missing-bounds.rs:12:21 + | +LL | #[derive(Debug)] + | ----- in this derive macro expansion +LL | struct Outer<T>(Inner<T>); + | ^^^^^^^^ `a::Inner<T>` cannot be formatted using `{:?}` + | + = help: the trait `Debug` is not implemented for `a::Inner<T>` + = note: add `#[derive(Debug)]` to `a::Inner<T>` or manually `impl Debug for a::Inner<T>` + = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider introducing a `where` bound, but there might be an alternative better way to express this requirement + | +LL | struct Outer<T>(Inner<T>) where a::Inner<T>: Debug; + | ++++++++++++++++++++++++ + +error[E0277]: the trait bound `T: c::Trait` is not satisfied + --> $DIR/derive-macro-missing-bounds.rs:41:21 + | +LL | #[derive(Debug)] + | ----- in this derive macro expansion +LL | struct Outer<T>(Inner<T>); + | ^^^^^^^^ the trait `c::Trait` is not implemented for `T` + | +note: required because of the requirements on the impl of `Debug` for `c::Inner<T>` + --> $DIR/derive-macro-missing-bounds.rs:34:28 + | +LL | impl<T: Debug + Trait> Debug for Inner<T> { + | ^^^^^ ^^^^^^^^ + = note: 1 redundant requirement hidden + = note: required because of the requirements on the impl of `Debug` for `&c::Inner<T>` + = note: required for the cast to the object type `dyn Debug` + = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider restricting type parameter `T` + | +LL | struct Outer<T: c::Trait>(Inner<T>); + | ++++++++++ + +error[E0277]: the trait bound `T: d::Trait` is not satisfied + --> $DIR/derive-macro-missing-bounds.rs:56:21 + | +LL | #[derive(Debug)] + | ----- in this derive macro expansion +LL | struct Outer<T>(Inner<T>); + | ^^^^^^^^ the trait `d::Trait` is not implemented for `T` + | +note: required because of the requirements on the impl of `Debug` for `d::Inner<T>` + --> $DIR/derive-macro-missing-bounds.rs:49:13 + | +LL | impl<T> Debug for Inner<T> where T: Debug, T: Trait { + | ^^^^^ ^^^^^^^^ + = note: 1 redundant requirement hidden + = note: required because of the requirements on the impl of `Debug` for `&d::Inner<T>` + = note: required for the cast to the object type `dyn Debug` + = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider restricting type parameter `T` + | +LL | struct Outer<T: d::Trait>(Inner<T>); + | ++++++++++ + +error[E0277]: the trait bound `T: e::Trait` is not satisfied + --> $DIR/derive-macro-missing-bounds.rs:71:21 + | +LL | #[derive(Debug)] + | ----- in this derive macro expansion +LL | struct Outer<T>(Inner<T>); + | ^^^^^^^^ the trait `e::Trait` is not implemented for `T` + | +note: required because of the requirements on the impl of `Debug` for `e::Inner<T>` + --> $DIR/derive-macro-missing-bounds.rs:64:13 + | +LL | impl<T> Debug for Inner<T> where T: Debug + Trait { + | ^^^^^ ^^^^^^^^ + = note: 1 redundant requirement hidden + = note: required because of the requirements on the impl of `Debug` for `&e::Inner<T>` + = note: required for the cast to the object type `dyn Debug` + = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider restricting type parameter `T` + | +LL | struct Outer<T: e::Trait>(Inner<T>); + | ++++++++++ + +error[E0277]: the trait bound `T: f::Trait` is not satisfied + --> $DIR/derive-macro-missing-bounds.rs:86:21 + | +LL | #[derive(Debug)] + | ----- in this derive macro expansion +LL | struct Outer<T>(Inner<T>); + | ^^^^^^^^ the trait `f::Trait` is not implemented for `T` + | +note: required because of the requirements on the impl of `Debug` for `f::Inner<T>` + --> $DIR/derive-macro-missing-bounds.rs:79:20 + | +LL | impl<T: Debug> Debug for Inner<T> where T: Trait { + | ^^^^^ ^^^^^^^^ + = note: 1 redundant requirement hidden + = note: required because of the requirements on the impl of `Debug` for `&f::Inner<T>` + = note: required for the cast to the object type `dyn Debug` + = note: this error originates in the derive macro `Debug` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider restricting type parameter `T` + | +LL | struct Outer<T: f::Trait>(Inner<T>); + | ++++++++++ + +error: aborting due to 5 previous errors + +For more information about this error, try `rustc --explain E0277`. |
