Auto merge of #54810 - 1aim:unused-impl-trait, r=oli-obk
Fix dead code lint for functions using impl Trait Fixes https://github.com/rust-lang/rust/issues/54754 This is a minimal fix that doesn't add any new queries or touches unnecessary code. Please nominate for beta backport if wanted.
This commit is contained in:
commit
b2d6ea98b0
9 changed files with 24 additions and 7 deletions
15
src/test/ui/impl-trait/existential-minimal.rs
Normal file
15
src/test/ui/impl-trait/existential-minimal.rs
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// compile-pass
|
||||
|
||||
fn main() {}
|
||||
|
||||
fn foo() -> impl std::fmt::Debug { "cake" }
|
||||
27
src/test/ui/impl-trait/issue-42479.rs
Normal file
27
src/test/ui/impl-trait/issue-42479.rs
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// compile-pass
|
||||
|
||||
use std::iter::once;
|
||||
|
||||
struct Foo {
|
||||
x: i32,
|
||||
}
|
||||
|
||||
impl Foo {
|
||||
fn inside(&self) -> impl Iterator<Item = &i32> {
|
||||
once(&self.x)
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
println!("hi");
|
||||
}
|
||||
31
src/test/ui/impl-trait/issue-49376.rs
Normal file
31
src/test/ui/impl-trait/issue-49376.rs
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// compile-pass
|
||||
|
||||
// Tests for nested self-reference which caused a stack overflow.
|
||||
|
||||
use std::fmt::Debug;
|
||||
use std::ops::*;
|
||||
|
||||
fn gen() -> impl PartialOrd + PartialEq + Debug { }
|
||||
|
||||
struct Bar {}
|
||||
trait Foo<T = Self> {}
|
||||
impl Foo for Bar {}
|
||||
|
||||
fn foo() -> impl Foo {
|
||||
Bar {}
|
||||
}
|
||||
|
||||
fn test_impl_ops() -> impl Add + Sub + Mul + Div { 1 }
|
||||
fn test_impl_assign_ops() -> impl AddAssign + SubAssign + MulAssign + DivAssign { 1 }
|
||||
|
||||
fn main() {}
|
||||
23
src/test/ui/issue-49556.rs
Normal file
23
src/test/ui/issue-49556.rs
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// compile-pass
|
||||
fn iter<'a>(data: &'a [usize]) -> impl Iterator<Item = usize> + 'a {
|
||||
data.iter()
|
||||
.map(
|
||||
|x| x // fn(&'a usize) -> &'(ReScope) usize
|
||||
)
|
||||
.map(
|
||||
|x| *x // fn(&'(ReScope) usize) -> usize
|
||||
)
|
||||
}
|
||||
|
||||
fn main() {
|
||||
}
|
||||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
18
src/test/ui/traits/conservative_impl_trait.rs
Normal file
18
src/test/ui/traits/conservative_impl_trait.rs
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
|
||||
// file at the top-level directory of this distribution and at
|
||||
// http://rust-lang.org/COPYRIGHT.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
||||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
||||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
||||
// option. This file may not be copied, modified, or distributed
|
||||
// except according to those terms.
|
||||
|
||||
// compile-pass
|
||||
// #39665
|
||||
|
||||
fn batches(n: &u32) -> impl Iterator<Item=&u32> {
|
||||
std::iter::once(n)
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
Loading…
Add table
Add a link
Reference in a new issue