mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Fix dead code lint for functions using impl Trait
This commit is contained in:
parent
088fc7384c
commit
3c46da8c82
@ -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<_>>();
|
||||
|
14
src/test/run-pass/async-await.stderr
Normal file
14
src/test/run-pass/async-await.stderr
Normal 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 {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
8
src/test/run-pass/impl-trait/existential-minimal.stderr
Normal file
8
src/test/run-pass/impl-trait/existential-minimal.stderr
Normal 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
|
||||
|
14
src/test/run-pass/impl-trait/issue-42479.stderr
Normal file
14
src/test/run-pass/impl-trait/issue-42479.stderr
Normal 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> {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
32
src/test/run-pass/impl-trait/issue-49376.stderr
Normal file
32
src/test/run-pass/impl-trait/issue-49376.stderr
Normal 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 }
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
8
src/test/run-pass/issues/issue-49556.stderr
Normal file
8
src/test/run-pass/issues/issue-49556.stderr
Normal 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
|
||||
|
8
src/test/run-pass/traits/conservative_impl_trait.stderr
Normal file
8
src/test/run-pass/traits/conservative_impl_trait.stderr
Normal 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
|
||||
|
@ -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)]
|
||||
|
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user