Skip to content

Commit c07a6d2

Browse files
committed
Complete test.
1 parent b621133 commit c07a6d2

File tree

3 files changed

+66
-4
lines changed

3 files changed

+66
-4
lines changed

src/test/ui/in-band-lifetimes/elided-lifetimes.fixed

+17
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ fn inspect_matched_set(set: MatchedSet<'_, '_>) {
5151
println!("{} {}", set.one, set.another);
5252
}
5353

54+
// Verify that the lint does not fire, because the added `'_` wouldn't be resolved correctly.
55+
fn match_sets() -> MatchedSet<'static, 'static> {
56+
//~^ ERROR missing lifetime specifiers
57+
//~| NOTE expected 2 lifetime parameters
58+
//~| HELP this function's return type contains a borrowed value
59+
//~| HELP consider using the `'static` lifetime
60+
MatchedSet { one: "one", another: "another" }
61+
}
62+
5463
macro_rules! autowrapper {
5564
($type_name:ident, $fn_name:ident, $lt:lifetime) => {
5665
struct $type_name<$lt> {
@@ -61,6 +70,9 @@ macro_rules! autowrapper {
6170
//~^ ERROR hidden lifetime parameters in types are deprecated
6271
//~| NOTE expected named lifetime parameter
6372
//~| HELP consider using the `'_` lifetime
73+
//~| ERROR hidden lifetime parameters in types are deprecated
74+
//~| NOTE expected named lifetime parameter
75+
//~| HELP consider using the `'_` lifetime
6476
$type_name { gift }
6577
}
6678
}
@@ -70,6 +82,11 @@ autowrapper!(Autowrapped, autowrap_gift, 'a);
7082
//~^ NOTE in this expansion of autowrapper!
7183
//~| NOTE in this expansion of autowrapper!
7284

85+
// Verify that rustfix does not try to apply the fix twice.
86+
autowrapper!(AutowrappedAgain, autowrap_gift_again, 'a);
87+
//~^ NOTE in this expansion of autowrapper!
88+
//~| NOTE in this expansion of autowrapper!
89+
7390
macro_rules! anytuple_ref_ty {
7491
($($types:ty),*) => {
7592
Ref<'_, ($($types),*)>

src/test/ui/in-band-lifetimes/elided-lifetimes.rs

+17
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,15 @@ fn inspect_matched_set(set: MatchedSet) {
5151
println!("{} {}", set.one, set.another);
5252
}
5353

54+
// Verify that the lint does not fire, because the added `'_` wouldn't be resolved correctly.
55+
fn match_sets() -> MatchedSet {
56+
//~^ ERROR missing lifetime specifiers
57+
//~| NOTE expected 2 lifetime parameters
58+
//~| HELP this function's return type contains a borrowed value
59+
//~| HELP consider using the `'static` lifetime
60+
MatchedSet { one: "one", another: "another" }
61+
}
62+
5463
macro_rules! autowrapper {
5564
($type_name:ident, $fn_name:ident, $lt:lifetime) => {
5665
struct $type_name<$lt> {
@@ -61,6 +70,9 @@ macro_rules! autowrapper {
6170
//~^ ERROR hidden lifetime parameters in types are deprecated
6271
//~| NOTE expected named lifetime parameter
6372
//~| HELP consider using the `'_` lifetime
73+
//~| ERROR hidden lifetime parameters in types are deprecated
74+
//~| NOTE expected named lifetime parameter
75+
//~| HELP consider using the `'_` lifetime
6476
$type_name { gift }
6577
}
6678
}
@@ -70,6 +82,11 @@ autowrapper!(Autowrapped, autowrap_gift, 'a);
7082
//~^ NOTE in this expansion of autowrapper!
7183
//~| NOTE in this expansion of autowrapper!
7284

85+
// Verify that rustfix does not try to apply the fix twice.
86+
autowrapper!(AutowrappedAgain, autowrap_gift_again, 'a);
87+
//~^ NOTE in this expansion of autowrapper!
88+
//~| NOTE in this expansion of autowrapper!
89+
7390
macro_rules! anytuple_ref_ty {
7491
($($types:ty),*) => {
7592
Ref<($($types),*)>

src/test/ui/in-band-lifetimes/elided-lifetimes.stderr

+32-4
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,20 @@ help: consider using the `'_` lifetime
4747
LL | fn inspect_matched_set(set: MatchedSet<'_, '_>) {
4848
| ~~~~~~~~~~~~~~~~~~
4949

50+
error[E0106]: missing lifetime specifiers
51+
--> $DIR/elided-lifetimes.rs:55:20
52+
|
53+
LL | fn match_sets() -> MatchedSet {
54+
| ^^^^^^^^^^ expected 2 lifetime parameters
55+
|
56+
= help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
57+
help: consider using the `'static` lifetime
58+
|
59+
LL | fn match_sets() -> MatchedSet<'static, 'static> {
60+
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
61+
5062
error: hidden lifetime parameters in types are deprecated
51-
--> $DIR/elided-lifetimes.rs:60:36
63+
--> $DIR/elided-lifetimes.rs:69:36
5264
|
5365
LL | fn $fn_name(gift: &str) -> $type_name {
5466
| ^^^^^^^^^^ expected named lifetime parameter
@@ -63,7 +75,22 @@ LL | fn $fn_name(gift: &str) -> $type_name<'_> {
6375
| ~~~~~~~~~~~~~~
6476

6577
error: hidden lifetime parameters in types are deprecated
66-
--> $DIR/elided-lifetimes.rs:84:22
78+
--> $DIR/elided-lifetimes.rs:69:36
79+
|
80+
LL | fn $fn_name(gift: &str) -> $type_name {
81+
| ^^^^^^^^^^ expected named lifetime parameter
82+
...
83+
LL | autowrapper!(AutowrappedAgain, autowrap_gift_again, 'a);
84+
| ------------------------------------------------------- in this macro invocation
85+
|
86+
= note: this error originates in the macro `autowrapper` (in Nightly builds, run with -Z macro-backtrace for more info)
87+
help: consider using the `'_` lifetime
88+
|
89+
LL | fn $fn_name(gift: &str) -> $type_name<'_> {
90+
| ~~~~~~~~~~~~~~
91+
92+
error: hidden lifetime parameters in types are deprecated
93+
--> $DIR/elided-lifetimes.rs:101:22
6794
|
6895
LL | let loyalty: Ref<(u32, char)> = honesty.borrow();
6996
| ^ expected named lifetime parameter
@@ -74,7 +101,7 @@ LL | let loyalty: Ref<'_, (u32, char)> = honesty.borrow();
74101
| +++
75102

76103
error: hidden lifetime parameters in types are deprecated
77-
--> $DIR/elided-lifetimes.rs:75:13
104+
--> $DIR/elided-lifetimes.rs:92:13
78105
|
79106
LL | Ref<($($types),*)>
80107
| ^ expected named lifetime parameter
@@ -88,5 +115,6 @@ help: consider using the `'_` lifetime
88115
LL | Ref<'_, ($($types),*)>
89116
| +++
90117

91-
error: aborting due to 7 previous errors
118+
error: aborting due to 9 previous errors
92119

120+
For more information about this error, try `rustc --explain E0106`.

0 commit comments

Comments
 (0)