diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-10-28 07:06:46 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-10-28 07:06:46 +0200 |
| commit | ab0d9dfefee2535ffa1a5ca8abe3b64a8e5970fd (patch) | |
| tree | 929424f3bae98d917899737e59e18e3950177206 /src | |
| parent | 112fd022cd42698f644333206ef5335069b1ea13 (diff) | |
| parent | b3425587a669d81b45f0d14f7fd6ae6108bf9444 (diff) | |
| download | rust-ab0d9dfefee2535ffa1a5ca8abe3b64a8e5970fd.tar.gz rust-ab0d9dfefee2535ffa1a5ca8abe3b64a8e5970fd.zip | |
Rollup merge of #103609 - BoxyUwU:fix_impl_self_cycle, r=compiler-errors
Emit a nicer error on `impl Self {`
currently it emits a "cycle detected error" but this PR makes it emit a more user friendly error specifically saying that `Self` is disallowed in that position. this is a pretty hacky fix so i dont expect this to be merged (I basically only made this PR because i wanted to see if CI passes)
r? ``@compiler-errors``
Diffstat (limited to 'src')
| -rw-r--r-- | src/test/ui/resolve/issue-23305.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/resolve/issue-23305.stderr | 16 | ||||
| -rw-r--r-- | src/test/ui/resolve/resolve-self-in-impl.rs | 9 | ||||
| -rw-r--r-- | src/test/ui/resolve/resolve-self-in-impl.stderr | 74 |
4 files changed, 27 insertions, 74 deletions
diff --git a/src/test/ui/resolve/issue-23305.rs b/src/test/ui/resolve/issue-23305.rs index 95635e12a63..6d7fe7c50a2 100644 --- a/src/test/ui/resolve/issue-23305.rs +++ b/src/test/ui/resolve/issue-23305.rs @@ -3,6 +3,6 @@ pub trait ToNbt<T> { } impl dyn ToNbt<Self> {} -//~^ ERROR cycle detected +//~^ ERROR `Self` is not valid in the self type of an impl block fn main() {} diff --git a/src/test/ui/resolve/issue-23305.stderr b/src/test/ui/resolve/issue-23305.stderr index 20aeb7b995a..aad1b583a32 100644 --- a/src/test/ui/resolve/issue-23305.stderr +++ b/src/test/ui/resolve/issue-23305.stderr @@ -1,22 +1,10 @@ -error[E0391]: cycle detected when computing type of `<impl at $DIR/issue-23305.rs:5:1: 5:21>` +error: `Self` is not valid in the self type of an impl block --> $DIR/issue-23305.rs:5:16 | LL | impl dyn ToNbt<Self> {} | ^^^^ | - = note: ...which immediately requires computing type of `<impl at $DIR/issue-23305.rs:5:1: 5:21>` again -note: cycle used when collecting item types in top-level module - --> $DIR/issue-23305.rs:1:1 - | -LL | / pub trait ToNbt<T> { -LL | | fn new(val: T) -> Self; -LL | | } -LL | | -... | -LL | | -LL | | fn main() {} - | |____________^ + = note: replace `Self` with a different type error: aborting due to previous error -For more information about this error, try `rustc --explain E0391`. diff --git a/src/test/ui/resolve/resolve-self-in-impl.rs b/src/test/ui/resolve/resolve-self-in-impl.rs index 024fdc51ea3..d0872d1b76f 100644 --- a/src/test/ui/resolve/resolve-self-in-impl.rs +++ b/src/test/ui/resolve/resolve-self-in-impl.rs @@ -11,10 +11,11 @@ impl Tr for S where Self: Copy {} // OK impl Tr for S where S<Self>: Copy {} // OK impl Tr for S where Self::A: Copy {} // OK -impl Tr for Self {} //~ ERROR cycle detected -impl Tr for S<Self> {} //~ ERROR cycle detected -impl Self {} //~ ERROR cycle detected -impl S<Self> {} //~ ERROR cycle detected +impl Tr for Self {} //~ ERROR `Self` is not valid in the self type of an impl block +impl Tr for S<Self> {} //~ ERROR `Self` is not valid in the self type of an impl block +impl Self {} //~ ERROR `Self` is not valid in the self type of an impl block +impl S<Self> {} //~ ERROR `Self` is not valid in the self type of an impl block +impl (Self, Self) {} //~ ERROR `Self` is not valid in the self type of an impl block impl Tr<Self::A> for S {} //~ ERROR cycle detected fn main() {} diff --git a/src/test/ui/resolve/resolve-self-in-impl.stderr b/src/test/ui/resolve/resolve-self-in-impl.stderr index aa99c1a3335..9f9ed68898f 100644 --- a/src/test/ui/resolve/resolve-self-in-impl.stderr +++ b/src/test/ui/resolve/resolve-self-in-impl.stderr @@ -1,86 +1,50 @@ -error[E0391]: cycle detected when computing type of `<impl at $DIR/resolve-self-in-impl.rs:14:1: 14:17>` +error: `Self` is not valid in the self type of an impl block --> $DIR/resolve-self-in-impl.rs:14:13 | LL | impl Tr for Self {} | ^^^^ | - = note: ...which immediately requires computing type of `<impl at $DIR/resolve-self-in-impl.rs:14:1: 14:17>` again -note: cycle used when collecting item types in top-level module - --> $DIR/resolve-self-in-impl.rs:1:1 - | -LL | / #![feature(associated_type_defaults)] -LL | | -LL | | struct S<T = u8>(T); -LL | | trait Tr<T = u8> { -... | -LL | | -LL | | fn main() {} - | |____________^ + = note: replace `Self` with a different type -error[E0391]: cycle detected when computing type of `<impl at $DIR/resolve-self-in-impl.rs:15:1: 15:20>` +error: `Self` is not valid in the self type of an impl block --> $DIR/resolve-self-in-impl.rs:15:15 | LL | impl Tr for S<Self> {} | ^^^^ | - = note: ...which immediately requires computing type of `<impl at $DIR/resolve-self-in-impl.rs:15:1: 15:20>` again -note: cycle used when collecting item types in top-level module - --> $DIR/resolve-self-in-impl.rs:1:1 - | -LL | / #![feature(associated_type_defaults)] -LL | | -LL | | struct S<T = u8>(T); -LL | | trait Tr<T = u8> { -... | -LL | | -LL | | fn main() {} - | |____________^ + = note: replace `Self` with a different type -error[E0391]: cycle detected when computing type of `<impl at $DIR/resolve-self-in-impl.rs:16:1: 16:10>` +error: `Self` is not valid in the self type of an impl block --> $DIR/resolve-self-in-impl.rs:16:6 | LL | impl Self {} | ^^^^ | - = note: ...which immediately requires computing type of `<impl at $DIR/resolve-self-in-impl.rs:16:1: 16:10>` again -note: cycle used when collecting item types in top-level module - --> $DIR/resolve-self-in-impl.rs:1:1 - | -LL | / #![feature(associated_type_defaults)] -LL | | -LL | | struct S<T = u8>(T); -LL | | trait Tr<T = u8> { -... | -LL | | -LL | | fn main() {} - | |____________^ + = note: replace `Self` with a different type -error[E0391]: cycle detected when computing type of `<impl at $DIR/resolve-self-in-impl.rs:17:1: 17:13>` +error: `Self` is not valid in the self type of an impl block --> $DIR/resolve-self-in-impl.rs:17:8 | LL | impl S<Self> {} | ^^^^ | - = note: ...which immediately requires computing type of `<impl at $DIR/resolve-self-in-impl.rs:17:1: 17:13>` again -note: cycle used when collecting item types in top-level module - --> $DIR/resolve-self-in-impl.rs:1:1 + = note: replace `Self` with a different type + +error: `Self` is not valid in the self type of an impl block + --> $DIR/resolve-self-in-impl.rs:18:7 | -LL | / #![feature(associated_type_defaults)] -LL | | -LL | | struct S<T = u8>(T); -LL | | trait Tr<T = u8> { -... | -LL | | -LL | | fn main() {} - | |____________^ +LL | impl (Self, Self) {} + | ^^^^ ^^^^ + | + = note: replace `Self` with a different type -error[E0391]: cycle detected when computing trait implemented by `<impl at $DIR/resolve-self-in-impl.rs:18:1: 18:23>` - --> $DIR/resolve-self-in-impl.rs:18:1 +error[E0391]: cycle detected when computing trait implemented by `<impl at $DIR/resolve-self-in-impl.rs:19:1: 19:23>` + --> $DIR/resolve-self-in-impl.rs:19:1 | LL | impl Tr<Self::A> for S {} | ^^^^^^^^^^^^^^^^^^^^^^ | - = note: ...which immediately requires computing trait implemented by `<impl at $DIR/resolve-self-in-impl.rs:18:1: 18:23>` again + = note: ...which immediately requires computing trait implemented by `<impl at $DIR/resolve-self-in-impl.rs:19:1: 19:23>` again note: cycle used when collecting item types in top-level module --> $DIR/resolve-self-in-impl.rs:1:1 | @@ -93,6 +57,6 @@ LL | | LL | | fn main() {} | |____________^ -error: aborting due to 5 previous errors +error: aborting due to 6 previous errors For more information about this error, try `rustc --explain E0391`. |
