Fix dead code lint for functions using impl Trait

This commit is contained in:
Jonas Schievink 2018-10-04 12:38:06 +02:00
parent 088fc7384c
commit 3c46da8c82
9 changed files with 102 additions and 2 deletions

View File

@ -395,7 +395,13 @@ fn create_and_seed_worklist<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
krate: &hir::Crate)
-> Vec<ast::NodeId>
{
let worklist = access_levels.map.iter().map(|(&id, _)| id).chain(
let worklist = access_levels.map.iter().filter_map(|(&id, level)| {
if level >= &privacy::AccessLevel::Reachable {
Some(id)
} else {
None
}
}).chain(
// Seed entry point
tcx.sess.entry_fn.borrow().map(|(id, _, _)| id)
).collect::<Vec<_>>();

View File

@ -0,0 +1,14 @@
warning: struct is never constructed: `Foo`
--> $DIR/async-await.rs:122:1
|
LL | struct Foo;
| ^^^^^^^^^^^
|
= note: #[warn(dead_code)] on by default
warning: method is never used: `async_method`
--> $DIR/async-await.rs:129:5
|
LL | async fn async_method(x: u8) -> u8 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -0,0 +1,8 @@
warning: function is never used: `foo`
--> $DIR/existential-minimal.rs:15:1
|
LL | fn foo() -> impl std::fmt::Debug { "cake" }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[warn(dead_code)] on by default

View File

@ -0,0 +1,14 @@
warning: struct is never constructed: `Foo`
--> $DIR/issue-42479.rs:15:1
|
LL | struct Foo {
| ^^^^^^^^^^
|
= note: #[warn(dead_code)] on by default
warning: method is never used: `inside`
--> $DIR/issue-42479.rs:20:5
|
LL | fn inside(&self) -> impl Iterator<Item = &i32> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -0,0 +1,32 @@
warning: function is never used: `gen`
--> $DIR/issue-49376.rs:18:1
|
LL | fn gen() -> impl PartialOrd + PartialEq + Debug { }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[warn(dead_code)] on by default
warning: struct is never constructed: `Bar`
--> $DIR/issue-49376.rs:20:1
|
LL | struct Bar {}
| ^^^^^^^^^^
warning: function is never used: `foo`
--> $DIR/issue-49376.rs:24:1
|
LL | fn foo() -> impl Foo {
| ^^^^^^^^^^^^^^^^^^^^
warning: function is never used: `test_impl_ops`
--> $DIR/issue-49376.rs:28:1
|
LL | fn test_impl_ops() -> impl Add + Sub + Mul + Div { 1 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
warning: function is never used: `test_impl_assign_ops`
--> $DIR/issue-49376.rs:29:1
|
LL | fn test_impl_assign_ops() -> impl AddAssign + SubAssign + MulAssign + DivAssign { 1 }
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

View File

@ -0,0 +1,8 @@
warning: function is never used: `iter`
--> $DIR/issue-49556.rs:12:1
|
LL | fn iter<'a>(data: &'a [usize]) -> impl Iterator<Item = usize> + 'a {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[warn(dead_code)] on by default

View File

@ -0,0 +1,8 @@
warning: function is never used: `batches`
--> $DIR/conservative_impl_trait.rs:14:1
|
LL | fn batches(n: &u32) -> impl Iterator<Item=&u32> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: #[warn(dead_code)] on by default

View File

@ -109,6 +109,10 @@ fn bar() { //~ ERROR: function is never used
foo();
}
fn baz() -> impl Copy { //~ ERROR: function is never used
"I'm unused, too"
}
// Code with #[allow(dead_code)] should be marked live (and thus anything it
// calls is marked live)
#[allow(dead_code)]

View File

@ -58,5 +58,11 @@ error: function is never used: `bar`
LL | fn bar() { //~ ERROR: function is never used
| ^^^^^^^^
error: aborting due to 9 previous errors
error: function is never used: `baz`
--> $DIR/lint-dead-code-1.rs:112:1
|
LL | fn baz() -> impl Copy { //~ ERROR: function is never used
| ^^^^^^^^^^^^^^^^^^^^^
error: aborting due to 10 previous errors