in which the elided-lifetimes-in-paths lint undergoes a revolution
The existing elided-lifetimes-in-paths lint (introduced in Nov. 2017's
accd997b5 / #46254) lacked stuctured suggestions and—much more
alarmingly—produced false positives on associated functions (like
`Ref::clone`) and on anonymous '_ lifetimes (!!—yes, the very
anonymous lifetimes that we meant to suggest "instead"). That this
went apparently unnoticed for so long maybe tells you something about
how many people actually bother to flip on allow-by-default lints.
After many hours of good old-fashioned American elbow grease—and a
little help from expert reviewers—it turns out that getting the right
answer is a lot easier if we fire the lint while lowering the Higher
Intermediate Representation.
The lint is promoted to the idioms-2018 group.
Also, in the matter of test filenames, "elided" only has one 'l' (see,
e.g., https://en.wiktionary.org/wiki/elide).
Resolves #52041.
This commit is contained in:
parent
d3b3bc5767
commit
41d5c0ce1f
9 changed files with 324 additions and 53 deletions
97
src/test/ui/in-band-lifetimes/elided-lifetimes.fixed
Normal file
97
src/test/ui/in-band-lifetimes/elided-lifetimes.fixed
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
// 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.
|
||||
|
||||
// run-rustfix
|
||||
// compile-flags: --edition 2018
|
||||
|
||||
#![allow(unused)]
|
||||
#![deny(elided_lifetimes_in_paths)]
|
||||
//~^ NOTE lint level defined here
|
||||
|
||||
use std::cell::{RefCell, Ref};
|
||||
|
||||
|
||||
struct Foo<'a> { x: &'a u32 }
|
||||
|
||||
fn foo(x: &Foo<'_>) {
|
||||
//~^ ERROR hidden lifetime parameters in types are deprecated
|
||||
//~| HELP indicate the anonymous lifetime
|
||||
}
|
||||
|
||||
fn bar(x: &Foo<'_>) {}
|
||||
|
||||
|
||||
struct Wrapped<'a>(&'a str);
|
||||
|
||||
struct WrappedWithBow<'a> {
|
||||
gift: &'a str
|
||||
}
|
||||
|
||||
struct MatchedSet<'a, 'b> {
|
||||
one: &'a str,
|
||||
another: &'b str,
|
||||
}
|
||||
|
||||
fn wrap_gift(gift: &str) -> Wrapped<'_> {
|
||||
//~^ ERROR hidden lifetime parameters in types are deprecated
|
||||
//~| HELP indicate the anonymous lifetime
|
||||
Wrapped(gift)
|
||||
}
|
||||
|
||||
fn wrap_gift_with_bow(gift: &str) -> WrappedWithBow<'_> {
|
||||
//~^ ERROR hidden lifetime parameters in types are deprecated
|
||||
//~| HELP indicate the anonymous lifetime
|
||||
WrappedWithBow { gift }
|
||||
}
|
||||
|
||||
fn inspect_matched_set(set: MatchedSet<'_, '_>) {
|
||||
//~^ ERROR hidden lifetime parameters in types are deprecated
|
||||
//~| HELP indicate the anonymous lifetime
|
||||
println!("{} {}", set.one, set.another);
|
||||
}
|
||||
|
||||
macro_rules! autowrapper {
|
||||
($type_name:ident, $fn_name:ident, $lt:lifetime) => {
|
||||
struct $type_name<$lt> {
|
||||
gift: &$lt str
|
||||
}
|
||||
|
||||
fn $fn_name(gift: &str) -> $type_name<'_> {
|
||||
//~^ ERROR hidden lifetime parameters in types are deprecated
|
||||
//~| HELP indicate the anonymous lifetime
|
||||
$type_name { gift }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
autowrapper!(Autowrapped, autowrap_gift, 'a);
|
||||
//~^ NOTE in this expansion of autowrapper!
|
||||
//~| NOTE in this expansion of autowrapper!
|
||||
|
||||
macro_rules! anytuple_ref_ty {
|
||||
($($types:ty),*) => {
|
||||
Ref<'_, ($($types),*)>
|
||||
//~^ ERROR hidden lifetime parameters in types are deprecated
|
||||
//~| HELP indicate the anonymous lifetime
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let honesty = RefCell::new((4, 'e'));
|
||||
let loyalty: Ref<'_, (u32, char)> = honesty.borrow();
|
||||
//~^ ERROR hidden lifetime parameters in types are deprecated
|
||||
//~| HELP indicate the anonymous lifetime
|
||||
let generosity = Ref::map(loyalty, |t| &t.0);
|
||||
|
||||
let laughter = RefCell::new((true, "magic"));
|
||||
let yellow: anytuple_ref_ty!(bool, &str) = laughter.borrow();
|
||||
//~^ NOTE in this expansion of anytuple_ref_ty!
|
||||
//~| NOTE in this expansion of anytuple_ref_ty!
|
||||
}
|
||||
97
src/test/ui/in-band-lifetimes/elided-lifetimes.rs
Normal file
97
src/test/ui/in-band-lifetimes/elided-lifetimes.rs
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
// 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.
|
||||
|
||||
// run-rustfix
|
||||
// compile-flags: --edition 2018
|
||||
|
||||
#![allow(unused)]
|
||||
#![deny(elided_lifetimes_in_paths)]
|
||||
//~^ NOTE lint level defined here
|
||||
|
||||
use std::cell::{RefCell, Ref};
|
||||
|
||||
|
||||
struct Foo<'a> { x: &'a u32 }
|
||||
|
||||
fn foo(x: &Foo) {
|
||||
//~^ ERROR hidden lifetime parameters in types are deprecated
|
||||
//~| HELP indicate the anonymous lifetime
|
||||
}
|
||||
|
||||
fn bar(x: &Foo<'_>) {}
|
||||
|
||||
|
||||
struct Wrapped<'a>(&'a str);
|
||||
|
||||
struct WrappedWithBow<'a> {
|
||||
gift: &'a str
|
||||
}
|
||||
|
||||
struct MatchedSet<'a, 'b> {
|
||||
one: &'a str,
|
||||
another: &'b str,
|
||||
}
|
||||
|
||||
fn wrap_gift(gift: &str) -> Wrapped {
|
||||
//~^ ERROR hidden lifetime parameters in types are deprecated
|
||||
//~| HELP indicate the anonymous lifetime
|
||||
Wrapped(gift)
|
||||
}
|
||||
|
||||
fn wrap_gift_with_bow(gift: &str) -> WrappedWithBow {
|
||||
//~^ ERROR hidden lifetime parameters in types are deprecated
|
||||
//~| HELP indicate the anonymous lifetime
|
||||
WrappedWithBow { gift }
|
||||
}
|
||||
|
||||
fn inspect_matched_set(set: MatchedSet) {
|
||||
//~^ ERROR hidden lifetime parameters in types are deprecated
|
||||
//~| HELP indicate the anonymous lifetime
|
||||
println!("{} {}", set.one, set.another);
|
||||
}
|
||||
|
||||
macro_rules! autowrapper {
|
||||
($type_name:ident, $fn_name:ident, $lt:lifetime) => {
|
||||
struct $type_name<$lt> {
|
||||
gift: &$lt str
|
||||
}
|
||||
|
||||
fn $fn_name(gift: &str) -> $type_name {
|
||||
//~^ ERROR hidden lifetime parameters in types are deprecated
|
||||
//~| HELP indicate the anonymous lifetime
|
||||
$type_name { gift }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
autowrapper!(Autowrapped, autowrap_gift, 'a);
|
||||
//~^ NOTE in this expansion of autowrapper!
|
||||
//~| NOTE in this expansion of autowrapper!
|
||||
|
||||
macro_rules! anytuple_ref_ty {
|
||||
($($types:ty),*) => {
|
||||
Ref<($($types),*)>
|
||||
//~^ ERROR hidden lifetime parameters in types are deprecated
|
||||
//~| HELP indicate the anonymous lifetime
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let honesty = RefCell::new((4, 'e'));
|
||||
let loyalty: Ref<(u32, char)> = honesty.borrow();
|
||||
//~^ ERROR hidden lifetime parameters in types are deprecated
|
||||
//~| HELP indicate the anonymous lifetime
|
||||
let generosity = Ref::map(loyalty, |t| &t.0);
|
||||
|
||||
let laughter = RefCell::new((true, "magic"));
|
||||
let yellow: anytuple_ref_ty!(bool, &str) = laughter.borrow();
|
||||
//~^ NOTE in this expansion of anytuple_ref_ty!
|
||||
//~| NOTE in this expansion of anytuple_ref_ty!
|
||||
}
|
||||
56
src/test/ui/in-band-lifetimes/elided-lifetimes.stderr
Normal file
56
src/test/ui/in-band-lifetimes/elided-lifetimes.stderr
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
error: hidden lifetime parameters in types are deprecated
|
||||
--> $DIR/elided-lifetimes.rs:23:12
|
||||
|
|
||||
LL | fn foo(x: &Foo) {
|
||||
| ^^^- help: indicate the anonymous lifetime: `<'_>`
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/elided-lifetimes.rs:15:9
|
||||
|
|
||||
LL | #![deny(elided_lifetimes_in_paths)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: hidden lifetime parameters in types are deprecated
|
||||
--> $DIR/elided-lifetimes.rs:42:29
|
||||
|
|
||||
LL | fn wrap_gift(gift: &str) -> Wrapped {
|
||||
| ^^^^^^^- help: indicate the anonymous lifetime: `<'_>`
|
||||
|
||||
error: hidden lifetime parameters in types are deprecated
|
||||
--> $DIR/elided-lifetimes.rs:48:38
|
||||
|
|
||||
LL | fn wrap_gift_with_bow(gift: &str) -> WrappedWithBow {
|
||||
| ^^^^^^^^^^^^^^- help: indicate the anonymous lifetime: `<'_>`
|
||||
|
||||
error: hidden lifetime parameters in types are deprecated
|
||||
--> $DIR/elided-lifetimes.rs:54:29
|
||||
|
|
||||
LL | fn inspect_matched_set(set: MatchedSet) {
|
||||
| ^^^^^^^^^^- help: indicate the anonymous lifetimes: `<'_, '_>`
|
||||
|
||||
error: hidden lifetime parameters in types are deprecated
|
||||
--> $DIR/elided-lifetimes.rs:66:36
|
||||
|
|
||||
LL | fn $fn_name(gift: &str) -> $type_name {
|
||||
| ^^^^^^^^^^- help: indicate the anonymous lifetime: `<'_>`
|
||||
...
|
||||
LL | autowrapper!(Autowrapped, autowrap_gift, 'a);
|
||||
| --------------------------------------------- in this macro invocation
|
||||
|
||||
error: hidden lifetime parameters in types are deprecated
|
||||
--> $DIR/elided-lifetimes.rs:88:18
|
||||
|
|
||||
LL | let loyalty: Ref<(u32, char)> = honesty.borrow();
|
||||
| ^^^^^^^^^^^^^^^^ help: indicate the anonymous lifetime: `Ref<'_, (u32, char)>`
|
||||
|
||||
error: hidden lifetime parameters in types are deprecated
|
||||
--> $DIR/elided-lifetimes.rs:80:9
|
||||
|
|
||||
LL | Ref<($($types),*)>
|
||||
| ^^^^^^^^^^^^^^^^^^ help: indicate the anonymous lifetime: `Ref<'_, ($($types),*)>`
|
||||
...
|
||||
LL | let yellow: anytuple_ref_ty!(bool, &str) = laughter.borrow();
|
||||
| ---------------------------- in this macro invocation
|
||||
|
||||
error: aborting due to 7 previous errors
|
||||
|
||||
|
|
@ -1,19 +0,0 @@
|
|||
// 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.
|
||||
#![allow(warnings)]
|
||||
#![allow(unused_variables, dead_code, unused, bad_style)]
|
||||
#![deny(elided_lifetimes_in_paths)]
|
||||
|
||||
struct Foo<'a> { x: &'a u32 }
|
||||
fn foo(x: &Foo) {
|
||||
//~^ ERROR: hidden lifetime parameters are deprecated, try `Foo<'_>`
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
error: hidden lifetime parameters are deprecated, try `Foo<'_>`
|
||||
--> $DIR/ellided-lifetimes.rs:15:12
|
||||
|
|
||||
LL | fn foo(x: &Foo) {
|
||||
| ^^^
|
||||
|
|
||||
note: lint level defined here
|
||||
--> $DIR/ellided-lifetimes.rs:12:9
|
||||
|
|
||||
LL | #![deny(elided_lifetimes_in_paths)]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue