Skip to content
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

Fix dead code lint for functions using impl Trait #54810

Merged
merged 7 commits into from Oct 7, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 7 additions & 1 deletion src/librustc/middle/dead.rs
Expand Up @@ -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<_>>();
Expand Down
1 change: 1 addition & 0 deletions src/test/run-pass/async-await.rs
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
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
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
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
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
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
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

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