Skip to content

Commit

Permalink
Auto merge of #54810 - 1aim:unused-impl-trait, r=oli-obk
Browse files Browse the repository at this point in the history
Fix dead code lint for functions using impl Trait

Fixes #54754

This is a minimal fix that doesn't add any new queries or touches unnecessary code. Please nominate for beta backport if wanted.
  • Loading branch information
bors committed Oct 7, 2018
2 parents 0ee045e + e24f4d5 commit b2d6ea9
Show file tree
Hide file tree
Showing 9 changed files with 24 additions and 7 deletions.
8 changes: 7 additions & 1 deletion src/librustc/middle/dead.rs
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,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<_>>();
Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/async-await.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ fn main() {
async_closure,
async_fn,
async_fn_with_internal_borrow,
Foo::async_method,
|x| {
async move {
unsafe { await!(unsafe_async_fn(x)) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// run-pass
// compile-pass

fn main() {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// run-pass
// compile-pass

use std::iter::once;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// run-pass
// compile-pass

// Tests for nested self-reference which caused a stack overflow.

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// run-pass
// compile-pass
fn iter<'a>(data: &'a [usize]) -> impl Iterator<Item = usize> + 'a {
data.iter()
.map(
Expand Down
4 changes: 4 additions & 0 deletions src/test/ui/lint/lint-dead-code-1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down
8 changes: 7 additions & 1 deletion src/test/ui/lint/lint-dead-code-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// option. This file may not be copied, modified, or distributed
// except according to those terms.

// run-pass
// compile-pass
// #39665

fn batches(n: &u32) -> impl Iterator<Item=&u32> {
Expand Down

0 comments on commit b2d6ea9

Please sign in to comment.