Skip to content

Commit b2d6ea9

Browse files
committed
Auto merge of #54810 - 1aim:unused-impl-trait, r=oli-obk
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.
2 parents 0ee045e + e24f4d5 commit b2d6ea9

File tree

9 files changed

+24
-7
lines changed

9 files changed

+24
-7
lines changed

Diff for: src/librustc/middle/dead.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,13 @@ fn create_and_seed_worklist<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
398398
krate: &hir::Crate)
399399
-> Vec<ast::NodeId>
400400
{
401-
let worklist = access_levels.map.iter().map(|(&id, _)| id).chain(
401+
let worklist = access_levels.map.iter().filter_map(|(&id, level)| {
402+
if level >= &privacy::AccessLevel::Reachable {
403+
Some(id)
404+
} else {
405+
None
406+
}
407+
}).chain(
402408
// Seed entry point
403409
tcx.sess.entry_fn.borrow().map(|(id, _, _)| id)
404410
).collect::<Vec<_>>();

Diff for: src/test/run-pass/async-await.rs

+1
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ fn main() {
170170
async_closure,
171171
async_fn,
172172
async_fn_with_internal_borrow,
173+
Foo::async_method,
173174
|x| {
174175
async move {
175176
unsafe { await!(unsafe_async_fn(x)) }

Diff for: src/test/run-pass/impl-trait/existential-minimal.rs renamed to src/test/ui/impl-trait/existential-minimal.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// run-pass
11+
// compile-pass
1212

1313
fn main() {}
1414

Diff for: src/test/run-pass/impl-trait/issue-42479.rs renamed to src/test/ui/impl-trait/issue-42479.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// run-pass
11+
// compile-pass
1212

1313
use std::iter::once;
1414

Diff for: src/test/run-pass/impl-trait/issue-49376.rs renamed to src/test/ui/impl-trait/issue-49376.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// run-pass
11+
// compile-pass
1212

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

Diff for: src/test/run-pass/issues/issue-49556.rs renamed to src/test/ui/issue-49556.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// run-pass
11+
// compile-pass
1212
fn iter<'a>(data: &'a [usize]) -> impl Iterator<Item = usize> + 'a {
1313
data.iter()
1414
.map(

Diff for: src/test/ui/lint/lint-dead-code-1.rs

+4
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ fn bar() { //~ ERROR: function is never used
109109
foo();
110110
}
111111

112+
fn baz() -> impl Copy { //~ ERROR: function is never used
113+
"I'm unused, too"
114+
}
115+
112116
// Code with #[allow(dead_code)] should be marked live (and thus anything it
113117
// calls is marked live)
114118
#[allow(dead_code)]

Diff for: src/test/ui/lint/lint-dead-code-1.stderr

+7-1
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,11 @@ error: function is never used: `bar`
5858
LL | fn bar() { //~ ERROR: function is never used
5959
| ^^^^^^^^
6060

61-
error: aborting due to 9 previous errors
61+
error: function is never used: `baz`
62+
--> $DIR/lint-dead-code-1.rs:112:1
63+
|
64+
LL | fn baz() -> impl Copy { //~ ERROR: function is never used
65+
| ^^^^^^^^^^^^^^^^^^^^^
66+
67+
error: aborting due to 10 previous errors
6268

Diff for: src/test/run-pass/traits/conservative_impl_trait.rs renamed to src/test/ui/traits/conservative_impl_trait.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// run-pass
11+
// compile-pass
1212
// #39665
1313

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

0 commit comments

Comments
 (0)