diff options
| author | mu001999 <mu001999@outlook.com> | 2024-06-18 15:56:34 +0800 |
|---|---|---|
| committer | mu001999 <mu001999@outlook.com> | 2024-06-18 16:00:57 +0800 |
| commit | a264bff9d557e9fc468c9fefeabc0c09d4eeea6f (patch) | |
| tree | 63951f0d97ad025373e816b802a0bb35768d56a1 /tests | |
| parent | 737e42308c6e957575692965d73b17937f936f28 (diff) | |
| download | rust-a264bff9d557e9fc468c9fefeabc0c09d4eeea6f.tar.gz rust-a264bff9d557e9fc468c9fefeabc0c09d4eeea6f.zip | |
Mark assoc tys live only if the trait is live
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui/const-generics/cross_crate_complex.rs | 1 | ||||
| -rw-r--r-- | tests/ui/generic-associated-types/missing-bounds.fixed | 4 | ||||
| -rw-r--r-- | tests/ui/generic-associated-types/missing-bounds.rs | 4 | ||||
| -rw-r--r-- | tests/ui/generic-associated-types/missing-bounds.stderr | 18 | ||||
| -rw-r--r-- | tests/ui/lint/dead-code/unused-trait-with-assoc-ty.rs | 11 | ||||
| -rw-r--r-- | tests/ui/lint/dead-code/unused-trait-with-assoc-ty.stderr | 20 | ||||
| -rw-r--r-- | tests/ui/pattern/issue-22546.rs | 2 | ||||
| -rw-r--r-- | tests/ui/pattern/issue-22546.stderr | 10 |
8 files changed, 50 insertions, 20 deletions
diff --git a/tests/ui/const-generics/cross_crate_complex.rs b/tests/ui/const-generics/cross_crate_complex.rs index d13b69aa0cf..b44d889f5e9 100644 --- a/tests/ui/const-generics/cross_crate_complex.rs +++ b/tests/ui/const-generics/cross_crate_complex.rs @@ -11,6 +11,7 @@ async fn foo() { async_in_foo(async_out_foo::<4>().await).await; } +#[allow(dead_code)] struct Faz<const N: usize>; impl<const N: usize> Foo<N> for Faz<N> {} diff --git a/tests/ui/generic-associated-types/missing-bounds.fixed b/tests/ui/generic-associated-types/missing-bounds.fixed index 703d3c1e0fb..ff69016d862 100644 --- a/tests/ui/generic-associated-types/missing-bounds.fixed +++ b/tests/ui/generic-associated-types/missing-bounds.fixed @@ -2,6 +2,7 @@ use std::ops::Add; +#[allow(dead_code)] struct A<B>(B); impl<B> Add for A<B> where B: Add<Output = B> { @@ -12,6 +13,7 @@ impl<B> Add for A<B> where B: Add<Output = B> { } } +#[allow(dead_code)] struct C<B>(B); impl<B: Add<Output = B>> Add for C<B> { @@ -22,6 +24,7 @@ impl<B: Add<Output = B>> Add for C<B> { } } +#[allow(dead_code)] struct D<B>(B); impl<B: std::ops::Add<Output = B>> Add for D<B> { @@ -32,6 +35,7 @@ impl<B: std::ops::Add<Output = B>> Add for D<B> { } } +#[allow(dead_code)] struct E<B>(B); impl<B: Add<Output = B>> Add for E<B> where B: Add<Output = B> { diff --git a/tests/ui/generic-associated-types/missing-bounds.rs b/tests/ui/generic-associated-types/missing-bounds.rs index f40b4228873..1f83356c2fa 100644 --- a/tests/ui/generic-associated-types/missing-bounds.rs +++ b/tests/ui/generic-associated-types/missing-bounds.rs @@ -2,6 +2,7 @@ use std::ops::Add; +#[allow(dead_code)] struct A<B>(B); impl<B> Add for A<B> where B: Add { @@ -12,6 +13,7 @@ impl<B> Add for A<B> where B: Add { } } +#[allow(dead_code)] struct C<B>(B); impl<B: Add> Add for C<B> { @@ -22,6 +24,7 @@ impl<B: Add> Add for C<B> { } } +#[allow(dead_code)] struct D<B>(B); impl<B> Add for D<B> { @@ -32,6 +35,7 @@ impl<B> Add for D<B> { } } +#[allow(dead_code)] struct E<B>(B); impl<B: Add> Add for E<B> where <B as Add>::Output = B { diff --git a/tests/ui/generic-associated-types/missing-bounds.stderr b/tests/ui/generic-associated-types/missing-bounds.stderr index 1d7d80d1b07..0f0dc24c06c 100644 --- a/tests/ui/generic-associated-types/missing-bounds.stderr +++ b/tests/ui/generic-associated-types/missing-bounds.stderr @@ -1,5 +1,5 @@ error: equality constraints are not yet supported in `where` clauses - --> $DIR/missing-bounds.rs:37:33 + --> $DIR/missing-bounds.rs:41:33 | LL | impl<B: Add> Add for E<B> where <B as Add>::Output = B { | ^^^^^^^^^^^^^^^^^^^^^^ not supported @@ -11,7 +11,7 @@ LL | impl<B: Add> Add for E<B> where B: Add<Output = B> { | ~~~~~~~~~~~~~~~~~~ error[E0308]: mismatched types - --> $DIR/missing-bounds.rs:11:11 + --> $DIR/missing-bounds.rs:12:11 | LL | impl<B> Add for A<B> where B: Add { | - expected this type parameter @@ -24,14 +24,14 @@ LL | A(self.0 + rhs.0) = note: expected type parameter `B` found associated type `<B as Add>::Output` help: the type constructed contains `<B as Add>::Output` due to the type of the argument passed - --> $DIR/missing-bounds.rs:11:9 + --> $DIR/missing-bounds.rs:12:9 | LL | A(self.0 + rhs.0) | ^^--------------^ | | | this argument influences the type of `A` note: tuple struct defined here - --> $DIR/missing-bounds.rs:5:8 + --> $DIR/missing-bounds.rs:6:8 | LL | struct A<B>(B); | ^ @@ -41,7 +41,7 @@ LL | impl<B> Add for A<B> where B: Add<Output = B> { | ++++++++++++ error[E0308]: mismatched types - --> $DIR/missing-bounds.rs:21:14 + --> $DIR/missing-bounds.rs:23:14 | LL | impl<B: Add> Add for C<B> { | - expected this type parameter @@ -54,7 +54,7 @@ LL | Self(self.0 + rhs.0) = note: expected type parameter `B` found associated type `<B as Add>::Output` note: tuple struct defined here - --> $DIR/missing-bounds.rs:15:8 + --> $DIR/missing-bounds.rs:17:8 | LL | struct C<B>(B); | ^ @@ -64,7 +64,7 @@ LL | impl<B: Add<Output = B>> Add for C<B> { | ++++++++++++ error[E0369]: cannot add `B` to `B` - --> $DIR/missing-bounds.rs:31:21 + --> $DIR/missing-bounds.rs:34:21 | LL | Self(self.0 + rhs.0) | ------ ^ ----- B @@ -77,7 +77,7 @@ LL | impl<B: std::ops::Add<Output = B>> Add for D<B> { | +++++++++++++++++++++++++++ error[E0308]: mismatched types - --> $DIR/missing-bounds.rs:42:14 + --> $DIR/missing-bounds.rs:46:14 | LL | impl<B: Add> Add for E<B> where <B as Add>::Output = B { | - expected this type parameter @@ -90,7 +90,7 @@ LL | Self(self.0 + rhs.0) = note: expected type parameter `B` found associated type `<B as Add>::Output` note: tuple struct defined here - --> $DIR/missing-bounds.rs:35:8 + --> $DIR/missing-bounds.rs:39:8 | LL | struct E<B>(B); | ^ diff --git a/tests/ui/lint/dead-code/unused-trait-with-assoc-ty.rs b/tests/ui/lint/dead-code/unused-trait-with-assoc-ty.rs new file mode 100644 index 00000000000..e8116d83ebf --- /dev/null +++ b/tests/ui/lint/dead-code/unused-trait-with-assoc-ty.rs @@ -0,0 +1,11 @@ +#![deny(dead_code)] + +struct T1; //~ ERROR struct `T1` is never constructed + +trait Foo { type Unused; } //~ ERROR trait `Foo` is never used +impl Foo for T1 { type Unused = Self; } + +pub trait Bar { type Used; } +impl Bar for T1 { type Used = Self; } + +fn main() {} diff --git a/tests/ui/lint/dead-code/unused-trait-with-assoc-ty.stderr b/tests/ui/lint/dead-code/unused-trait-with-assoc-ty.stderr new file mode 100644 index 00000000000..ab73c640634 --- /dev/null +++ b/tests/ui/lint/dead-code/unused-trait-with-assoc-ty.stderr @@ -0,0 +1,20 @@ +error: struct `T1` is never constructed + --> $DIR/unused-trait-with-assoc-ty.rs:3:8 + | +LL | struct T1; + | ^^ + | +note: the lint level is defined here + --> $DIR/unused-trait-with-assoc-ty.rs:1:9 + | +LL | #![deny(dead_code)] + | ^^^^^^^^^ + +error: trait `Foo` is never used + --> $DIR/unused-trait-with-assoc-ty.rs:5:7 + | +LL | trait Foo { type Unused; } + | ^^^ + +error: aborting due to 2 previous errors + diff --git a/tests/ui/pattern/issue-22546.rs b/tests/ui/pattern/issue-22546.rs index fd1d5fb6c47..d5c5b68be78 100644 --- a/tests/ui/pattern/issue-22546.rs +++ b/tests/ui/pattern/issue-22546.rs @@ -15,7 +15,7 @@ impl<T: ::std::fmt::Display> Foo<T> { } } -trait Tr { //~ WARN trait `Tr` is never used +trait Tr { type U; } diff --git a/tests/ui/pattern/issue-22546.stderr b/tests/ui/pattern/issue-22546.stderr deleted file mode 100644 index e067a95e422..00000000000 --- a/tests/ui/pattern/issue-22546.stderr +++ /dev/null @@ -1,10 +0,0 @@ -warning: trait `Tr` is never used - --> $DIR/issue-22546.rs:18:7 - | -LL | trait Tr { - | ^^ - | - = note: `#[warn(dead_code)]` on by default - -warning: 1 warning emitted - |
