summaryrefslogtreecommitdiffstats
path: root/tests/ui/lint/dead-code
diff options
context:
space:
mode:
Diffstat (limited to 'tests/ui/lint/dead-code')
-rw-r--r--tests/ui/lint/dead-code/issue-59003.rs18
-rw-r--r--tests/ui/lint/dead-code/issue-85255.rs12
-rw-r--r--tests/ui/lint/dead-code/issue-85255.stderr54
-rw-r--r--tests/ui/lint/dead-code/lint-dead-code-3.stderr14
-rw-r--r--tests/ui/lint/dead-code/lint-dead-code-6.rs9
-rw-r--r--tests/ui/lint/dead-code/lint-dead-code-6.stderr18
-rw-r--r--tests/ui/lint/dead-code/unused-assoc-fns.rs35
-rw-r--r--tests/ui/lint/dead-code/unused-assoc-fns.stderr29
8 files changed, 131 insertions, 58 deletions
diff --git a/tests/ui/lint/dead-code/issue-59003.rs b/tests/ui/lint/dead-code/issue-59003.rs
new file mode 100644
index 000000000..966d64128
--- /dev/null
+++ b/tests/ui/lint/dead-code/issue-59003.rs
@@ -0,0 +1,18 @@
+// check-pass
+
+// Make sure we don't have any false positives about the "struct is never constructed" lint.
+
+#![deny(dead_code)]
+
+struct Foo {
+ #[allow(dead_code)]
+ inner: u32,
+}
+
+impl From<u32> for Foo {
+ fn from(inner: u32) -> Self {
+ Self { inner }
+ }
+}
+
+fn main() {}
diff --git a/tests/ui/lint/dead-code/issue-85255.rs b/tests/ui/lint/dead-code/issue-85255.rs
index 1978bd4e8..d75a8e2dd 100644
--- a/tests/ui/lint/dead-code/issue-85255.rs
+++ b/tests/ui/lint/dead-code/issue-85255.rs
@@ -11,8 +11,8 @@ struct Foo {
struct Bar;
impl Bar {
- fn a(&self) -> i32 { 5 } //~ WARNING: method `a` is never used
- pub fn b(&self) -> i32 { 6 } //~ WARNING: method `b` is never used
+ fn a(&self) -> i32 { 5 } //~ WARNING: methods `a` and `b` are never used [dead_code]
+ pub fn b(&self) -> i32 { 6 }
}
pub(crate) struct Foo1 {
@@ -23,8 +23,8 @@ pub(crate) struct Foo1 {
pub(crate) struct Bar1;
impl Bar1 {
- fn a(&self) -> i32 { 5 } //~ WARNING: method `a` is never used
- pub fn b(&self) -> i32 { 6 } //~ WARNING: method `b` is never used
+ fn a(&self) -> i32 { 5 } //~ WARNING: methods `a` and `b` are never used [dead_code]
+ pub fn b(&self) -> i32 { 6 }
}
pub(crate) struct Foo2 {
@@ -35,8 +35,8 @@ pub(crate) struct Foo2 {
pub(crate) struct Bar2;
impl Bar2 {
- fn a(&self) -> i32 { 5 } //~ WARNING: method `a` is never used
- pub fn b(&self) -> i32 { 6 } //~ WARNING: method `b` is never used
+ fn a(&self) -> i32 { 5 } //~ WARNING: methods `a` and `b` are never used [dead_code]
+ pub fn b(&self) -> i32 { 6 }
}
diff --git a/tests/ui/lint/dead-code/issue-85255.stderr b/tests/ui/lint/dead-code/issue-85255.stderr
index 58a19cf3c..d981085a4 100644
--- a/tests/ui/lint/dead-code/issue-85255.stderr
+++ b/tests/ui/lint/dead-code/issue-85255.stderr
@@ -14,6 +14,16 @@ note: the lint level is defined here
LL | #![warn(dead_code)]
| ^^^^^^^^^
+warning: methods `a` and `b` are never used
+ --> $DIR/issue-85255.rs:14:8
+ |
+LL | impl Bar {
+ | -------- methods in this implementation
+LL | fn a(&self) -> i32 { 5 }
+ | ^
+LL | pub fn b(&self) -> i32 { 6 }
+ | ^
+
warning: fields `a` and `b` are never read
--> $DIR/issue-85255.rs:19:5
|
@@ -24,6 +34,16 @@ LL | a: i32,
LL | pub b: i32,
| ^
+warning: methods `a` and `b` are never used
+ --> $DIR/issue-85255.rs:26:8
+ |
+LL | impl Bar1 {
+ | --------- methods in this implementation
+LL | fn a(&self) -> i32 { 5 }
+ | ^
+LL | pub fn b(&self) -> i32 { 6 }
+ | ^
+
warning: fields `a` and `b` are never read
--> $DIR/issue-85255.rs:31:5
|
@@ -34,41 +54,15 @@ LL | a: i32,
LL | pub b: i32,
| ^
-warning: method `a` is never used
- --> $DIR/issue-85255.rs:14:8
- |
-LL | fn a(&self) -> i32 { 5 }
- | ^
-
-warning: method `b` is never used
- --> $DIR/issue-85255.rs:15:12
- |
-LL | pub fn b(&self) -> i32 { 6 }
- | ^
-
-warning: method `a` is never used
- --> $DIR/issue-85255.rs:26:8
- |
-LL | fn a(&self) -> i32 { 5 }
- | ^
-
-warning: method `b` is never used
- --> $DIR/issue-85255.rs:27:12
- |
-LL | pub fn b(&self) -> i32 { 6 }
- | ^
-
-warning: method `a` is never used
+warning: methods `a` and `b` are never used
--> $DIR/issue-85255.rs:38:8
|
+LL | impl Bar2 {
+ | --------- methods in this implementation
LL | fn a(&self) -> i32 { 5 }
| ^
-
-warning: method `b` is never used
- --> $DIR/issue-85255.rs:39:12
- |
LL | pub fn b(&self) -> i32 { 6 }
| ^
-warning: 9 warnings emitted
+warning: 6 warnings emitted
diff --git a/tests/ui/lint/dead-code/lint-dead-code-3.stderr b/tests/ui/lint/dead-code/lint-dead-code-3.stderr
index 797b7559c..5c68cf0e1 100644
--- a/tests/ui/lint/dead-code/lint-dead-code-3.stderr
+++ b/tests/ui/lint/dead-code/lint-dead-code-3.stderr
@@ -10,6 +10,14 @@ note: the lint level is defined here
LL | #![deny(dead_code)]
| ^^^^^^^^^
+error: method `foo` is never used
+ --> $DIR/lint-dead-code-3.rs:16:8
+ |
+LL | impl Foo {
+ | -------- method in this implementation
+LL | fn foo(&self) {
+ | ^^^
+
error: function `bar` is never used
--> $DIR/lint-dead-code-3.rs:21:4
|
@@ -34,12 +42,6 @@ error: function `blah` is never used
LL | fn blah() {}
| ^^^^
-error: method `foo` is never used
- --> $DIR/lint-dead-code-3.rs:16:8
- |
-LL | fn foo(&self) {
- | ^^^
-
error: function `free` is never used
--> $DIR/lint-dead-code-3.rs:62:8
|
diff --git a/tests/ui/lint/dead-code/lint-dead-code-6.rs b/tests/ui/lint/dead-code/lint-dead-code-6.rs
index e3074acf1..5b2b76b76 100644
--- a/tests/ui/lint/dead-code/lint-dead-code-6.rs
+++ b/tests/ui/lint/dead-code/lint-dead-code-6.rs
@@ -2,17 +2,16 @@
struct UnusedStruct; //~ ERROR struct `UnusedStruct` is never constructed
impl UnusedStruct {
- fn unused_impl_fn_1() { //~ ERROR associated function `unused_impl_fn_1` is never used
+ fn unused_impl_fn_1() {
+ //~^ ERROR associated functions `unused_impl_fn_1`, `unused_impl_fn_2`, and `unused_impl_fn_3` are never used [dead_code]
println!("blah");
}
- fn unused_impl_fn_2(var: i32) { //~ ERROR associated function `unused_impl_fn_2` is never used
+ fn unused_impl_fn_2(var: i32) {
println!("foo {}", var);
}
- fn unused_impl_fn_3( //~ ERROR associated function `unused_impl_fn_3` is never used
- var: i32,
- ) {
+ fn unused_impl_fn_3(var: i32) {
println!("bar {}", var);
}
}
diff --git a/tests/ui/lint/dead-code/lint-dead-code-6.stderr b/tests/ui/lint/dead-code/lint-dead-code-6.stderr
index f9d83308a..ce4110086 100644
--- a/tests/ui/lint/dead-code/lint-dead-code-6.stderr
+++ b/tests/ui/lint/dead-code/lint-dead-code-6.stderr
@@ -10,23 +10,19 @@ note: the lint level is defined here
LL | #![deny(dead_code)]
| ^^^^^^^^^
-error: associated function `unused_impl_fn_1` is never used
+error: associated functions `unused_impl_fn_1`, `unused_impl_fn_2`, and `unused_impl_fn_3` are never used
--> $DIR/lint-dead-code-6.rs:5:8
|
+LL | impl UnusedStruct {
+ | ----------------- associated functions in this implementation
LL | fn unused_impl_fn_1() {
| ^^^^^^^^^^^^^^^^
-
-error: associated function `unused_impl_fn_2` is never used
- --> $DIR/lint-dead-code-6.rs:9:8
- |
+...
LL | fn unused_impl_fn_2(var: i32) {
| ^^^^^^^^^^^^^^^^
-
-error: associated function `unused_impl_fn_3` is never used
- --> $DIR/lint-dead-code-6.rs:13:8
- |
-LL | fn unused_impl_fn_3(
+...
+LL | fn unused_impl_fn_3(var: i32) {
| ^^^^^^^^^^^^^^^^
-error: aborting due to 4 previous errors
+error: aborting due to 2 previous errors
diff --git a/tests/ui/lint/dead-code/unused-assoc-fns.rs b/tests/ui/lint/dead-code/unused-assoc-fns.rs
new file mode 100644
index 000000000..b111f4b94
--- /dev/null
+++ b/tests/ui/lint/dead-code/unused-assoc-fns.rs
@@ -0,0 +1,35 @@
+#![feature(inherent_associated_types)]
+#![allow(incomplete_features)]
+#![deny(unused)]
+
+struct Foo;
+
+impl Foo {
+ fn one() {}
+ //~^ ERROR associated items `one`, `two`, `CONSTANT`, `Type`, and `three` are never used [dead_code]
+
+ fn two(&self) {}
+
+ // seperation between items
+ // ...
+ // ...
+
+ fn used() {}
+
+ const CONSTANT: usize = 5;
+
+ // more seperation
+ // ...
+ // ...
+
+ type Type = usize;
+
+ fn three(&self) {
+ Foo::one();
+ // ...
+ }
+}
+
+fn main() {
+ Foo::used();
+}
diff --git a/tests/ui/lint/dead-code/unused-assoc-fns.stderr b/tests/ui/lint/dead-code/unused-assoc-fns.stderr
new file mode 100644
index 000000000..6344a70ea
--- /dev/null
+++ b/tests/ui/lint/dead-code/unused-assoc-fns.stderr
@@ -0,0 +1,29 @@
+error: associated items `one`, `two`, `CONSTANT`, `Type`, and `three` are never used
+ --> $DIR/unused-assoc-fns.rs:8:8
+ |
+LL | impl Foo {
+ | -------- associated items in this implementation
+LL | fn one() {}
+ | ^^^
+...
+LL | fn two(&self) {}
+ | ^^^
+...
+LL | const CONSTANT: usize = 5;
+ | ^^^^^^^^
+...
+LL | type Type = usize;
+ | ^^^^
+LL |
+LL | fn three(&self) {
+ | ^^^^^
+ |
+note: the lint level is defined here
+ --> $DIR/unused-assoc-fns.rs:3:9
+ |
+LL | #![deny(unused)]
+ | ^^^^^^
+ = note: `#[deny(dead_code)]` implied by `#[deny(unused)]`
+
+error: aborting due to previous error
+