about summary refs log tree commit diff
path: root/tests/ui/lint/dead-code
diff options
context:
space:
mode:
authormu001999 <mu001999@outlook.com>2024-06-18 15:56:34 +0800
committermu001999 <mu001999@outlook.com>2024-06-18 16:00:57 +0800
commita264bff9d557e9fc468c9fefeabc0c09d4eeea6f (patch)
tree63951f0d97ad025373e816b802a0bb35768d56a1 /tests/ui/lint/dead-code
parent737e42308c6e957575692965d73b17937f936f28 (diff)
downloadrust-a264bff9d557e9fc468c9fefeabc0c09d4eeea6f.tar.gz
rust-a264bff9d557e9fc468c9fefeabc0c09d4eeea6f.zip
Mark assoc tys live only if the trait is live
Diffstat (limited to 'tests/ui/lint/dead-code')
-rw-r--r--tests/ui/lint/dead-code/unused-trait-with-assoc-ty.rs11
-rw-r--r--tests/ui/lint/dead-code/unused-trait-with-assoc-ty.stderr20
2 files changed, 31 insertions, 0 deletions
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
+