From a9bec0c8a6020ed61ca150f046455b309283848d Mon Sep 17 00:00:00 2001 From: uHOOCCOOHu Date: Wed, 10 Jul 2019 01:57:25 +0800 Subject: [PATCH 1/6] Ignore generated fresh lifetimes in elision check. --- clippy_lints/src/lifetimes.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/clippy_lints/src/lifetimes.rs b/clippy_lints/src/lifetimes.rs index dbdb3c519627..47cced9d9a42 100644 --- a/clippy_lints/src/lifetimes.rs +++ b/clippy_lints/src/lifetimes.rs @@ -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 { From e6bbed909ee516b5e50bfb1a3b2b86a6b2988bc3 Mon Sep 17 00:00:00 2001 From: uHOOCCOOHu Date: Fri, 19 Jul 2019 02:43:10 +0800 Subject: [PATCH 2/6] Add test --- tests/ui/issue_4266.rs | 24 ++++++++++++++++++++++++ tests/ui/issue_4266.stderr | 16 ++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 tests/ui/issue_4266.rs create mode 100644 tests/ui/issue_4266.stderr diff --git a/tests/ui/issue_4266.rs b/tests/ui/issue_4266.rs new file mode 100644 index 000000000000..dbf482ea11ae --- /dev/null +++ b/tests/ui/issue_4266.rs @@ -0,0 +1,24 @@ +// compile-flags: --edition 2018 +#![feature(async_await)] +#![allow(dead_code)] + +async fn sink1<'a>(_: &'a str) {} // lint +async fn sink1_elided(_: &str) {} // ok + +async fn one_to_one<'a>(s: &'a str) -> &'a str { s } // lint +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 } // ok +// async fn unrelated(_: &str, _: &str) {} // Not allowed in async fn + +// #3988 +struct Foo; +impl Foo { + pub async fn foo(&mut self) {} // ok +} + +// rust-lang/rust#61115 +async fn print(s: &str) { // ok + println!("{}", s); +} + +fn main() {} diff --git a/tests/ui/issue_4266.stderr b/tests/ui/issue_4266.stderr new file mode 100644 index 000000000000..3c9740c4a222 --- /dev/null +++ b/tests/ui/issue_4266.stderr @@ -0,0 +1,16 @@ +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:8:1 + | +LL | async fn one_to_one<'a>(s: &'a str) -> &'a str { s } // lint + | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +error: aborting due to 2 previous errors + From 2cc373ac54e7d244cea22b305cefc1c2d08d81f6 Mon Sep 17 00:00:00 2001 From: uHOOCCOOHu Date: Fri, 19 Jul 2019 23:03:34 +0800 Subject: [PATCH 3/6] Fix fmt --- rustfmt.toml | 2 +- tests/ui/issue_4266.rs | 24 +++++++++++++++++++----- tests/ui/issue_4266.stderr | 8 +++++--- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/rustfmt.toml b/rustfmt.toml index 797eccdad99e..f1241e74b0a3 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -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 diff --git a/tests/ui/issue_4266.rs b/tests/ui/issue_4266.rs index dbf482ea11ae..953879f7bed0 100644 --- a/tests/ui/issue_4266.rs +++ b/tests/ui/issue_4266.rs @@ -5,19 +5,33 @@ async fn sink1<'a>(_: &'a str) {} // lint async fn sink1_elided(_: &str) {} // ok -async fn one_to_one<'a>(s: &'a str) -> &'a str { s } // lint -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 } // 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 { - pub async fn foo(&mut self) {} // ok + // ok + pub async fn foo(&mut self) {} } // rust-lang/rust#61115 -async fn print(s: &str) { // ok +// ok +async fn print(s: &str) { println!("{}", s); } diff --git a/tests/ui/issue_4266.stderr b/tests/ui/issue_4266.stderr index 3c9740c4a222..8b4e70eb9c22 100644 --- a/tests/ui/issue_4266.stderr +++ b/tests/ui/issue_4266.stderr @@ -7,10 +7,12 @@ 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:8:1 + --> $DIR/issue_4266.rs:9:1 | -LL | async fn one_to_one<'a>(s: &'a str) -> &'a str { s } // lint - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +LL | / async fn one_to_one<'a>(s: &'a str) -> &'a str { +LL | | s +LL | | } + | |_^ error: aborting due to 2 previous errors From b70b3b14aa3125fe4f74a6a71fb7a7b7e78ab13f Mon Sep 17 00:00:00 2001 From: uHOOCCOOHu Date: Sat, 20 Jul 2019 00:50:18 +0800 Subject: [PATCH 4/6] Revert global fmt config and use `rustfmt::skip` --- rustfmt.toml | 2 +- tests/ui/issue_4266.rs | 54 ++++++++++++++++++++------------------ tests/ui/issue_4266.stderr | 16 +++++------ 3 files changed, 38 insertions(+), 34 deletions(-) diff --git a/rustfmt.toml b/rustfmt.toml index f1241e74b0a3..797eccdad99e 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -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 diff --git a/tests/ui/issue_4266.rs b/tests/ui/issue_4266.rs index 953879f7bed0..737e718c4c08 100644 --- a/tests/ui/issue_4266.rs +++ b/tests/ui/issue_4266.rs @@ -2,37 +2,41 @@ #![feature(async_await)] #![allow(dead_code)] -async fn sink1<'a>(_: &'a str) {} // lint -async fn sink1_elided(_: &str) {} // ok +// No edition 2018 +#[rustfmt::skip] +mod m { + 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 -} + // 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 one_to_one_elided(s: &str) -> &str { + s + } -// ok -async fn all_to_one<'a>(a: &'a str, _b: &'a str) -> &'a str { - a -} + // 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 + // async fn unrelated(_: &str, _: &str) {} // Not allowed in async fn -// #3988 -struct Foo; -impl Foo { - // ok - pub async fn foo(&mut self) {} -} + // #3988 + struct Foo; + impl Foo { + // ok + pub async fn foo(&mut self) {} + } -// rust-lang/rust#61115 -// ok -async fn print(s: &str) { - println!("{}", s); + // rust-lang/rust#61115 + // ok + async fn print(s: &str) { + println!("{}", s); + } } fn main() {} diff --git a/tests/ui/issue_4266.stderr b/tests/ui/issue_4266.stderr index 8b4e70eb9c22..649d01dca1ef 100644 --- a/tests/ui/issue_4266.stderr +++ b/tests/ui/issue_4266.stderr @@ -1,18 +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 + --> $DIR/issue_4266.rs:8:5 | -LL | async fn sink1<'a>(_: &'a str) {} // lint - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +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 + --> $DIR/issue_4266.rs:12:5 | -LL | / async fn one_to_one<'a>(s: &'a str) -> &'a str { -LL | | s -LL | | } - | |_^ +LL | / async fn one_to_one<'a>(s: &'a str) -> &'a str { +LL | | s +LL | | } + | |_____^ error: aborting due to 2 previous errors From 434f83a6c7e6973b12bd59918b059f5d35fe3075 Mon Sep 17 00:00:00 2001 From: uHOOCCOOHu Date: Tue, 23 Jul 2019 02:57:49 +0800 Subject: [PATCH 5/6] Revert "Revert global fmt config and use `rustfmt::skip`" This reverts commit b70b3b14aa3125fe4f74a6a71fb7a7b7e78ab13f. --- rustfmt.toml | 2 +- tests/ui/issue_4266.rs | 54 ++++++++++++++++++-------------------- tests/ui/issue_4266.stderr | 16 +++++------ 3 files changed, 34 insertions(+), 38 deletions(-) diff --git a/rustfmt.toml b/rustfmt.toml index 797eccdad99e..f1241e74b0a3 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -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 diff --git a/tests/ui/issue_4266.rs b/tests/ui/issue_4266.rs index 737e718c4c08..953879f7bed0 100644 --- a/tests/ui/issue_4266.rs +++ b/tests/ui/issue_4266.rs @@ -2,41 +2,37 @@ #![feature(async_await)] #![allow(dead_code)] -// No edition 2018 -#[rustfmt::skip] -mod m { - async fn sink1<'a>(_: &'a str) {} // lint - async fn sink1_elided(_: &str) {} // ok +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 - } +// lint +async fn one_to_one<'a>(s: &'a str) -> &'a str { + s +} - // ok - async fn all_to_one<'a>(a: &'a str, _b: &'a str) -> &'a str { - a - } +// ok +async fn one_to_one_elided(s: &str) -> &str { + s +} - // async fn unrelated(_: &str, _: &str) {} // Not allowed in async fn +// ok +async fn all_to_one<'a>(a: &'a str, _b: &'a str) -> &'a str { + a +} - // #3988 - struct Foo; - impl Foo { - // ok - pub async fn foo(&mut self) {} - } +// async fn unrelated(_: &str, _: &str) {} // Not allowed in async fn - // rust-lang/rust#61115 +// #3988 +struct Foo; +impl Foo { // ok - async fn print(s: &str) { - println!("{}", s); - } + pub async fn foo(&mut self) {} +} + +// rust-lang/rust#61115 +// ok +async fn print(s: &str) { + println!("{}", s); } fn main() {} diff --git a/tests/ui/issue_4266.stderr b/tests/ui/issue_4266.stderr index 649d01dca1ef..8b4e70eb9c22 100644 --- a/tests/ui/issue_4266.stderr +++ b/tests/ui/issue_4266.stderr @@ -1,18 +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:8:5 + --> $DIR/issue_4266.rs:5:1 | -LL | async fn sink1<'a>(_: &'a str) {} // lint - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +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:12:5 + --> $DIR/issue_4266.rs:9:1 | -LL | / async fn one_to_one<'a>(s: &'a str) -> &'a str { -LL | | s -LL | | } - | |_____^ +LL | / async fn one_to_one<'a>(s: &'a str) -> &'a str { +LL | | s +LL | | } + | |_^ error: aborting due to 2 previous errors From 5265ab8723d675262fe065bbb2bd0ff3225b5255 Mon Sep 17 00:00:00 2001 From: uHOOCCOOHu Date: Tue, 23 Jul 2019 03:59:09 +0800 Subject: [PATCH 6/6] Fix tests for edition 2018 compatibility --- tests/ui/cognitive_complexity.rs | 18 +++++++++--------- tests/ui/cognitive_complexity.stderr | 8 ++++---- tests/ui/dlist.rs | 2 +- tests/ui/dlist.stderr | 6 +++--- tests/ui/if_same_then_else.rs | 4 ++-- tests/ui/if_same_then_else.stderr | 4 ++-- tests/ui/unused_io_amount.rs | 4 ++-- tests/ui/unused_io_amount.stderr | 8 ++++---- 8 files changed, 27 insertions(+), 27 deletions(-) diff --git a/tests/ui/cognitive_complexity.rs b/tests/ui/cognitive_complexity.rs index 4e4016e78c2a..a1f1c586eb0b 100644 --- a/tests/ui/cognitive_complexity.rs +++ b/tests/ui/cognitive_complexity.rs @@ -313,7 +313,7 @@ fn mcarton_sees_all() { } #[clippy::cognitive_complexity = "0"] -fn try() -> Result { +fn try_() -> Result { match 5 { 5 => Ok(5), _ => return Err("bla"), @@ -322,14 +322,14 @@ fn try() -> Result { #[clippy::cognitive_complexity = "0"] fn try_again() -> Result { - 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"), diff --git a/tests/ui/cognitive_complexity.stderr b/tests/ui/cognitive_complexity.stderr index 168653b97116..e1c5863f4942 100644 --- a/tests/ui/cognitive_complexity.stderr +++ b/tests/ui/cognitive_complexity.stderr @@ -216,7 +216,7 @@ LL | | } error: the function has a cognitive complexity of 1 --> $DIR/cognitive_complexity.rs:316:1 | -LL | / fn try() -> Result { +LL | / fn try_() -> Result { LL | | match 5 { LL | | 5 => Ok(5), LL | | _ => return Err("bla"), @@ -230,9 +230,9 @@ error: the function has a cognitive complexity of 1 --> $DIR/cognitive_complexity.rs:324:1 | LL | / fn try_again() -> Result { -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 | | } diff --git a/tests/ui/dlist.rs b/tests/ui/dlist.rs index 5af79f9c58ed..2940d2d29011 100644 --- a/tests/ui/dlist.rs +++ b/tests/ui/dlist.rs @@ -7,7 +7,7 @@ use alloc::collections::linked_list::LinkedList; trait Foo { type Baz = LinkedList; - fn foo(LinkedList); + fn foo(_: LinkedList); const BAR: Option>; } diff --git a/tests/ui/dlist.stderr b/tests/ui/dlist.stderr index e4712e5d07f8..1f6646ec9ade 100644 --- a/tests/ui/dlist.stderr +++ b/tests/ui/dlist.stderr @@ -8,10 +8,10 @@ LL | type Baz = LinkedList; = 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); - | ^^^^^^^^^^^^^^ +LL | fn foo(_: LinkedList); + | ^^^^^^^^^^^^^^ | = help: a VecDeque might work diff --git a/tests/ui/if_same_then_else.rs b/tests/ui/if_same_then_else.rs index d1213e5e5fda..f9923c9bb480 100644 --- a/tests/ui/if_same_then_else.rs +++ b/tests/ui/if_same_then_else.rs @@ -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 { diff --git a/tests/ui/if_same_then_else.stderr b/tests/ui/if_same_then_else.stderr index fa42afff0be0..f1710382bfa7 100644 --- a/tests/ui/if_same_then_else.stderr +++ b/tests/ui/if_same_then_else.stderr @@ -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 | | } | |_____^ | @@ -206,7 +206,7 @@ note: same as this | LL | if true { | _____________^ -LL | | try!(Ok("foo")); +LL | | r#try!(Ok("foo")); LL | | } else { | |_____^ diff --git a/tests/ui/unused_io_amount.rs b/tests/ui/unused_io_amount.rs index c8a38f9fe57a..40968822493f 100644 --- a/tests/ui/unused_io_amount.rs +++ b/tests/ui/unused_io_amount.rs @@ -4,9 +4,9 @@ use std::io; fn try_macro(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(()) } diff --git a/tests/ui/unused_io_amount.stderr b/tests/ui/unused_io_amount.stderr index 2d00338193c4..dbf701e06f9a 100644 --- a/tests/ui/unused_io_amount.stderr +++ b/tests/ui/unused_io_amount.stderr @@ -1,8 +1,8 @@ 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) @@ -10,8 +10,8 @@ LL | try!(s.write(b"test")); 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)