-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Do not complain about unused code when used in impl
Self
type
#63317
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,12 +5,15 @@ | |
// when deriving Debug on an empty enum | ||
|
||
#[derive(Debug)] | ||
enum Void {} //~ WARN never used | ||
enum Void {} | ||
|
||
#[derive(Debug)] | ||
enum Foo { //~ WARN never used | ||
enum Foo { | ||
Bar(u8), | ||
Void(Void), | ||
Void(Void), //~ WARN never used | ||
RalfJung marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
fn main() {} | ||
fn main() { | ||
let x = Foo::Bar(42); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is added to remove the warning for |
||
println!("{:?}", x); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,8 @@ | ||
warning: enum is never used: `Void` | ||
--> $DIR/derive-uninhabited-enum-38885.rs:8:1 | ||
warning: variant is never constructed: `Void` | ||
--> $DIR/derive-uninhabited-enum-38885.rs:13:5 | ||
| | ||
LL | enum Void {} | ||
| ^^^^^^^^^ | ||
LL | Void(Void), | ||
| ^^^^^^^^^^ | ||
| | ||
= note: `-W dead-code` implied by `-W unused` | ||
|
||
warning: enum is never used: `Foo` | ||
--> $DIR/derive-uninhabited-enum-38885.rs:11:1 | ||
| | ||
LL | enum Foo { | ||
| ^^^^^^^^ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// check-pass | ||
|
||
#![deny(dead_code)] | ||
|
||
const TLC: usize = 4; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No complaint about TLC being unused |
||
|
||
trait Tr { fn doit(&self); } | ||
|
||
impl Tr for [usize; TLC] { | ||
fn doit(&self) { | ||
println!("called 4"); | ||
} | ||
} | ||
|
||
struct X; | ||
struct Y; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No complaint about Y being unused |
||
struct Z; | ||
|
||
trait Foo<T> { | ||
type Ty; | ||
fn foo() -> Self::Ty; | ||
} | ||
|
||
impl Foo<Y> for X { | ||
type Ty = Z; | ||
fn foo() -> Self::Ty { | ||
unimplemented!() | ||
} | ||
} | ||
|
||
fn main() { | ||
let s = [0,1,2,3]; | ||
s.doit(); | ||
X::foo(); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// build-pass | ||
#![deny(unused)] | ||
|
||
pub enum E {} | ||
|
||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#![deny(unused)] | ||
|
||
enum E {} //~ ERROR enum is never used | ||
|
||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error: enum is never used: `E` | ||
--> $DIR/lint-dead-code-empty-unused-enum.rs:3:1 | ||
| | ||
LL | enum E {} | ||
| ^^^^^^ | ||
| | ||
note: lint level defined here | ||
--> $DIR/lint-dead-code-empty-unused-enum.rs:1:9 | ||
| | ||
LL | #![deny(unused)] | ||
| ^^^^^^ | ||
= note: `#[deny(dead_code)]` implied by `#[deny(unused)]` | ||
|
||
error: aborting due to previous error | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#![deny(unused)] | ||
|
||
struct F; //~ ERROR struct is never constructed | ||
struct B; //~ ERROR struct is never constructed | ||
|
||
enum E { //~ ERROR enum is never used | ||
Foo(F), | ||
Bar(B), | ||
} | ||
|
||
fn main() {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
error: struct is never constructed: `F` | ||
--> $DIR/lint-dead-code-unused-enum.rs:3:1 | ||
| | ||
LL | struct F; | ||
| ^^^^^^^^^ | ||
| | ||
note: lint level defined here | ||
--> $DIR/lint-dead-code-unused-enum.rs:1:9 | ||
| | ||
LL | #![deny(unused)] | ||
| ^^^^^^ | ||
= note: `#[deny(dead_code)]` implied by `#[deny(unused)]` | ||
|
||
error: struct is never constructed: `B` | ||
--> $DIR/lint-dead-code-unused-enum.rs:4:1 | ||
| | ||
LL | struct B; | ||
| ^^^^^^^^^ | ||
|
||
error: enum is never used: `E` | ||
--> $DIR/lint-dead-code-unused-enum.rs:6:1 | ||
| | ||
LL | enum E { | ||
| ^^^^^^ | ||
|
||
error: aborting due to 3 previous errors | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
// build-pass | ||
#![deny(unused)] | ||
|
||
pub struct F; | ||
pub struct B; | ||
|
||
pub enum E { | ||
Foo(F), | ||
Bar(B), | ||
} | ||
|
||
fn main() { | ||
let _ = E::Foo(F); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#![deny(unused)] | ||
|
||
struct F; | ||
struct B; | ||
|
||
enum E { | ||
Foo(F), | ||
Bar(B), //~ ERROR variant is never constructed | ||
} | ||
|
||
fn main() { | ||
let _ = E::Foo(F); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error: variant is never constructed: `Bar` | ||
--> $DIR/lint-dead-code-unused-variant.rs:8:5 | ||
| | ||
LL | Bar(B), | ||
| ^^^^^^ | ||
| | ||
note: lint level defined here | ||
--> $DIR/lint-dead-code-unused-variant.rs:1:9 | ||
| | ||
LL | #![deny(unused)] | ||
| ^^^^^^ | ||
= note: `#[deny(dead_code)]` implied by `#[deny(unused)]` | ||
|
||
error: aborting due to previous error | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is to verify that this doesn't emit a warning due to
derive
.