diff --git a/src/test/ui/in-band-lifetimes/elided-lifetimes.fixed b/src/test/ui/in-band-lifetimes/elided-lifetimes.fixed index ca70242ef3d..35e0701103c 100644 --- a/src/test/ui/in-band-lifetimes/elided-lifetimes.fixed +++ b/src/test/ui/in-band-lifetimes/elided-lifetimes.fixed @@ -51,6 +51,15 @@ fn inspect_matched_set(set: MatchedSet<'_, '_>) { println!("{} {}", set.one, set.another); } +// Verify that the lint does not fire, because the added `'_` wouldn't be resolved correctly. +fn match_sets() -> MatchedSet<'static, 'static> { + //~^ ERROR missing lifetime specifiers + //~| NOTE expected 2 lifetime parameters + //~| HELP this function's return type contains a borrowed value + //~| HELP consider using the `'static` lifetime + MatchedSet { one: "one", another: "another" } +} + macro_rules! autowrapper { ($type_name:ident, $fn_name:ident, $lt:lifetime) => { struct $type_name<$lt> { @@ -61,6 +70,9 @@ macro_rules! autowrapper { //~^ ERROR hidden lifetime parameters in types are deprecated //~| NOTE expected named lifetime parameter //~| HELP consider using the `'_` lifetime + //~| ERROR hidden lifetime parameters in types are deprecated + //~| NOTE expected named lifetime parameter + //~| HELP consider using the `'_` lifetime $type_name { gift } } } @@ -70,6 +82,11 @@ autowrapper!(Autowrapped, autowrap_gift, 'a); //~^ NOTE in this expansion of autowrapper! //~| NOTE in this expansion of autowrapper! +// Verify that rustfix does not try to apply the fix twice. +autowrapper!(AutowrappedAgain, autowrap_gift_again, 'a); +//~^ NOTE in this expansion of autowrapper! +//~| NOTE in this expansion of autowrapper! + macro_rules! anytuple_ref_ty { ($($types:ty),*) => { Ref<'_, ($($types),*)> diff --git a/src/test/ui/in-band-lifetimes/elided-lifetimes.rs b/src/test/ui/in-band-lifetimes/elided-lifetimes.rs index d55eb854ed2..4ad6141eda5 100644 --- a/src/test/ui/in-band-lifetimes/elided-lifetimes.rs +++ b/src/test/ui/in-band-lifetimes/elided-lifetimes.rs @@ -51,6 +51,15 @@ fn inspect_matched_set(set: MatchedSet) { println!("{} {}", set.one, set.another); } +// Verify that the lint does not fire, because the added `'_` wouldn't be resolved correctly. +fn match_sets() -> MatchedSet { + //~^ ERROR missing lifetime specifiers + //~| NOTE expected 2 lifetime parameters + //~| HELP this function's return type contains a borrowed value + //~| HELP consider using the `'static` lifetime + MatchedSet { one: "one", another: "another" } +} + macro_rules! autowrapper { ($type_name:ident, $fn_name:ident, $lt:lifetime) => { struct $type_name<$lt> { @@ -61,6 +70,9 @@ macro_rules! autowrapper { //~^ ERROR hidden lifetime parameters in types are deprecated //~| NOTE expected named lifetime parameter //~| HELP consider using the `'_` lifetime + //~| ERROR hidden lifetime parameters in types are deprecated + //~| NOTE expected named lifetime parameter + //~| HELP consider using the `'_` lifetime $type_name { gift } } } @@ -70,6 +82,11 @@ autowrapper!(Autowrapped, autowrap_gift, 'a); //~^ NOTE in this expansion of autowrapper! //~| NOTE in this expansion of autowrapper! +// Verify that rustfix does not try to apply the fix twice. +autowrapper!(AutowrappedAgain, autowrap_gift_again, 'a); +//~^ NOTE in this expansion of autowrapper! +//~| NOTE in this expansion of autowrapper! + macro_rules! anytuple_ref_ty { ($($types:ty),*) => { Ref<($($types),*)> diff --git a/src/test/ui/in-band-lifetimes/elided-lifetimes.stderr b/src/test/ui/in-band-lifetimes/elided-lifetimes.stderr index c7cfaa9a018..b6994a3673a 100644 --- a/src/test/ui/in-band-lifetimes/elided-lifetimes.stderr +++ b/src/test/ui/in-band-lifetimes/elided-lifetimes.stderr @@ -47,8 +47,20 @@ help: consider using the `'_` lifetime LL | fn inspect_matched_set(set: MatchedSet<'_, '_>) { | ~~~~~~~~~~~~~~~~~~ +error[E0106]: missing lifetime specifiers + --> $DIR/elided-lifetimes.rs:55:20 + | +LL | fn match_sets() -> MatchedSet { + | ^^^^^^^^^^ expected 2 lifetime parameters + | + = help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from +help: consider using the `'static` lifetime + | +LL | fn match_sets() -> MatchedSet<'static, 'static> { + | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + error: hidden lifetime parameters in types are deprecated - --> $DIR/elided-lifetimes.rs:60:36 + --> $DIR/elided-lifetimes.rs:69:36 | LL | fn $fn_name(gift: &str) -> $type_name { | ^^^^^^^^^^ expected named lifetime parameter @@ -63,7 +75,22 @@ LL | fn $fn_name(gift: &str) -> $type_name<'_> { | ~~~~~~~~~~~~~~ error: hidden lifetime parameters in types are deprecated - --> $DIR/elided-lifetimes.rs:84:22 + --> $DIR/elided-lifetimes.rs:69:36 + | +LL | fn $fn_name(gift: &str) -> $type_name { + | ^^^^^^^^^^ expected named lifetime parameter +... +LL | autowrapper!(AutowrappedAgain, autowrap_gift_again, 'a); + | ------------------------------------------------------- in this macro invocation + | + = note: this error originates in the macro `autowrapper` (in Nightly builds, run with -Z macro-backtrace for more info) +help: consider using the `'_` lifetime + | +LL | fn $fn_name(gift: &str) -> $type_name<'_> { + | ~~~~~~~~~~~~~~ + +error: hidden lifetime parameters in types are deprecated + --> $DIR/elided-lifetimes.rs:101:22 | LL | let loyalty: Ref<(u32, char)> = honesty.borrow(); | ^ expected named lifetime parameter @@ -74,7 +101,7 @@ LL | let loyalty: Ref<'_, (u32, char)> = honesty.borrow(); | +++ error: hidden lifetime parameters in types are deprecated - --> $DIR/elided-lifetimes.rs:75:13 + --> $DIR/elided-lifetimes.rs:92:13 | LL | Ref<($($types),*)> | ^ expected named lifetime parameter @@ -88,5 +115,6 @@ help: consider using the `'_` lifetime LL | Ref<'_, ($($types),*)> | +++ -error: aborting due to 7 previous errors +error: aborting due to 9 previous errors +For more information about this error, try `rustc --explain E0106`.