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

Ignore generated fresh lifetimes in elision check #4266

Merged
merged 6 commits into from
Jul 23, 2019
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clippy_lints/src/lifetimes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,8 @@ impl<'v, 't> RefVisitor<'v, 't> {
if let Some(ref lt) = *lifetime {
if lt.name == LifetimeName::Static {
self.lts.push(RefLt::Static);
} else if let LifetimeName::Param(ParamName::Fresh(_)) = lt.name {
// Fresh lifetimes generated should be ignored.
} else if lt.is_elided() {
self.lts.push(RefLt::Unnamed);
} else {
Expand Down
2 changes: 1 addition & 1 deletion rustfmt.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ max_width = 120
comment_width = 100
match_block_trailing_comma = true
wrap_comments = true

edition = "2018"
error_on_line_overflow = true
18 changes: 9 additions & 9 deletions tests/ui/cognitive_complexity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ fn mcarton_sees_all() {
}

#[clippy::cognitive_complexity = "0"]
fn try() -> Result<i32, &'static str> {
fn try_() -> Result<i32, &'static str> {
match 5 {
5 => Ok(5),
_ => return Err("bla"),
Expand All @@ -322,14 +322,14 @@ fn try() -> Result<i32, &'static str> {

#[clippy::cognitive_complexity = "0"]
fn try_again() -> Result<i32, &'static str> {
let _ = try!(Ok(42));
let _ = try!(Ok(43));
let _ = try!(Ok(44));
let _ = try!(Ok(45));
let _ = try!(Ok(46));
let _ = try!(Ok(47));
let _ = try!(Ok(48));
let _ = try!(Ok(49));
let _ = r#try!(Ok(42));
let _ = r#try!(Ok(43));
let _ = r#try!(Ok(44));
let _ = r#try!(Ok(45));
let _ = r#try!(Ok(46));
let _ = r#try!(Ok(47));
let _ = r#try!(Ok(48));
let _ = r#try!(Ok(49));
match 5 {
5 => Ok(5),
_ => return Err("bla"),
Expand Down
8 changes: 4 additions & 4 deletions tests/ui/cognitive_complexity.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ LL | | }
error: the function has a cognitive complexity of 1
--> $DIR/cognitive_complexity.rs:316:1
|
LL | / fn try() -> Result<i32, &'static str> {
LL | / fn try_() -> Result<i32, &'static str> {
LL | | match 5 {
LL | | 5 => Ok(5),
LL | | _ => return Err("bla"),
Expand All @@ -230,9 +230,9 @@ error: the function has a cognitive complexity of 1
--> $DIR/cognitive_complexity.rs:324:1
|
LL | / fn try_again() -> Result<i32, &'static str> {
LL | | let _ = try!(Ok(42));
LL | | let _ = try!(Ok(43));
LL | | let _ = try!(Ok(44));
LL | | let _ = r#try!(Ok(42));
LL | | let _ = r#try!(Ok(43));
LL | | let _ = r#try!(Ok(44));
... |
LL | | }
LL | | }
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/dlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ use alloc::collections::linked_list::LinkedList;

trait Foo {
type Baz = LinkedList<u8>;
fn foo(LinkedList<u8>);
fn foo(_: LinkedList<u8>);
const BAR: Option<LinkedList<u8>>;
}

Expand Down
6 changes: 3 additions & 3 deletions tests/ui/dlist.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ LL | type Baz = LinkedList<u8>;
= help: a VecDeque might work

error: I see you're using a LinkedList! Perhaps you meant some other data structure?
--> $DIR/dlist.rs:10:12
--> $DIR/dlist.rs:10:15
|
LL | fn foo(LinkedList<u8>);
| ^^^^^^^^^^^^^^
LL | fn foo(_: LinkedList<u8>);
| ^^^^^^^^^^^^^^
|
= help: a VecDeque might work

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/if_same_then_else.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,10 +215,10 @@ fn if_same_then_else() -> Result<&'static str, ()> {
};

if true {
try!(Ok("foo"));
r#try!(Ok("foo"));
} else {
//~ ERROR same body as `if` block
try!(Ok("foo"));
r#try!(Ok("foo"));
}

if true {
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/if_same_then_else.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ error: this `if` has identical blocks
LL | } else {
| ____________^
LL | | //~ ERROR same body as `if` block
LL | | try!(Ok("foo"));
LL | | r#try!(Ok("foo"));
LL | | }
| |_____^
|
Expand All @@ -206,7 +206,7 @@ note: same as this
|
LL | if true {
| _____________^
LL | | try!(Ok("foo"));
LL | | r#try!(Ok("foo"));
LL | | } else {
| |_____^

Expand Down
38 changes: 38 additions & 0 deletions tests/ui/issue_4266.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// compile-flags: --edition 2018
#![feature(async_await)]
#![allow(dead_code)]

async fn sink1<'a>(_: &'a str) {} // lint
async fn sink1_elided(_: &str) {} // ok

// lint
async fn one_to_one<'a>(s: &'a str) -> &'a str {
s
}

// ok
async fn one_to_one_elided(s: &str) -> &str {
s
}

// ok
async fn all_to_one<'a>(a: &'a str, _b: &'a str) -> &'a str {
a
}

// async fn unrelated(_: &str, _: &str) {} // Not allowed in async fn

// #3988
struct Foo;
impl Foo {
// ok
pub async fn foo(&mut self) {}
}

// rust-lang/rust#61115
// ok
async fn print(s: &str) {
println!("{}", s);
}

fn main() {}
18 changes: 18 additions & 0 deletions tests/ui/issue_4266.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
--> $DIR/issue_4266.rs:5:1
|
LL | async fn sink1<'a>(_: &'a str) {} // lint
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::needless-lifetimes` implied by `-D warnings`

error: explicit lifetimes given in parameter types where they could be elided (or replaced with `'_` if needed by type declaration)
--> $DIR/issue_4266.rs:9:1
|
LL | / async fn one_to_one<'a>(s: &'a str) -> &'a str {
LL | | s
LL | | }
| |_^

error: aborting due to 2 previous errors

4 changes: 2 additions & 2 deletions tests/ui/unused_io_amount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
use std::io;

fn try_macro<T: io::Read + io::Write>(s: &mut T) -> io::Result<()> {
try!(s.write(b"test"));
r#try!(s.write(b"test"));
let mut buf = [0u8; 4];
try!(s.read(&mut buf));
r#try!(s.read(&mut buf));
Ok(())
}

Expand Down
8 changes: 4 additions & 4 deletions tests/ui/unused_io_amount.stderr
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
error: handle written amount returned or use `Write::write_all` instead
--> $DIR/unused_io_amount.rs:7:5
|
LL | try!(s.write(b"test"));
| ^^^^^^^^^^^^^^^^^^^^^^^
LL | r#try!(s.write(b"test"));
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: `-D clippy::unused-io-amount` implied by `-D warnings`
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error: handle read amount returned or use `Read::read_exact` instead
--> $DIR/unused_io_amount.rs:9:5
|
LL | try!(s.read(&mut buf));
| ^^^^^^^^^^^^^^^^^^^^^^^
LL | r#try!(s.read(&mut buf));
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

Expand Down