Skip to content

Commit b1d092c

Browse files
committed
Auto merge of #75867 - estebank:async-lt-sugg-fix, r=matthewjasper
Account for async functions when suggesting new named lifetime Fix #75850.
2 parents 360eb34 + 35e166e commit b1d092c

File tree

3 files changed

+39
-12
lines changed

3 files changed

+39
-12
lines changed

src/librustc_resolve/late/diagnostics.rs

+3
Original file line numberDiff line numberDiff line change
@@ -1222,6 +1222,9 @@ impl<'tcx> LifetimeContext<'_, 'tcx> {
12221222
synthetic: Some(hir::SyntheticTyParamKind::ImplTrait),
12231223
..
12241224
} => false,
1225+
hir::GenericParamKind::Lifetime {
1226+
kind: hir::LifetimeParamKind::Elided,
1227+
} => false,
12251228
_ => true,
12261229
}) {
12271230
(param.span.shrink_to_lo(), format!("{}, ", lifetime_ref))

src/test/ui/regions/regions-name-undeclared.rs

+8
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// edition:2018
12
// Check that lifetime resolver enforces the lifetime name scoping
23
// rules correctly in various scenarios.
34

@@ -47,4 +48,11 @@ fn fn_types(a: &'a isize, //~ ERROR undeclared lifetime
4748
{
4849
}
4950

51+
struct Bug {}
52+
impl Bug {
53+
async fn buggy(&self) -> &'a str { //~ ERROR use of undeclared lifetime name `'a`
54+
todo!()
55+
}
56+
}
57+
5058
pub fn main() {}

src/test/ui/regions/regions-name-undeclared.stderr

+28-12
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0261]: use of undeclared lifetime name `'b`
2-
--> $DIR/regions-name-undeclared.rs:15:24
2+
--> $DIR/regions-name-undeclared.rs:16:24
33
|
44
LL | fn m4(&self, arg: &'b isize) { }
55
| ^^ undeclared lifetime
@@ -15,7 +15,7 @@ LL | fn m4<'b>(&self, arg: &'b isize) { }
1515
| ^^^^
1616

1717
error[E0261]: use of undeclared lifetime name `'b`
18-
--> $DIR/regions-name-undeclared.rs:16:12
18+
--> $DIR/regions-name-undeclared.rs:17:12
1919
|
2020
LL | fn m5(&'b self) { }
2121
| ^^ undeclared lifetime
@@ -31,7 +31,7 @@ LL | fn m5<'b>(&'b self) { }
3131
| ^^^^
3232

3333
error[E0261]: use of undeclared lifetime name `'b`
34-
--> $DIR/regions-name-undeclared.rs:17:27
34+
--> $DIR/regions-name-undeclared.rs:18:27
3535
|
3636
LL | fn m6(&self, arg: Foo<'b>) { }
3737
| ^^ undeclared lifetime
@@ -47,7 +47,7 @@ LL | fn m6<'b>(&self, arg: Foo<'b>) { }
4747
| ^^^^
4848

4949
error[E0261]: use of undeclared lifetime name `'a`
50-
--> $DIR/regions-name-undeclared.rs:25:22
50+
--> $DIR/regions-name-undeclared.rs:26:22
5151
|
5252
LL | type X = Option<&'a isize>;
5353
| - ^^ undeclared lifetime
@@ -57,7 +57,7 @@ LL | type X = Option<&'a isize>;
5757
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
5858

5959
error[E0261]: use of undeclared lifetime name `'a`
60-
--> $DIR/regions-name-undeclared.rs:27:13
60+
--> $DIR/regions-name-undeclared.rs:28:13
6161
|
6262
LL | enum E {
6363
| - help: consider introducing lifetime `'a` here: `<'a>`
@@ -67,7 +67,7 @@ LL | E1(&'a isize)
6767
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
6868

6969
error[E0261]: use of undeclared lifetime name `'a`
70-
--> $DIR/regions-name-undeclared.rs:30:13
70+
--> $DIR/regions-name-undeclared.rs:31:13
7171
|
7272
LL | struct S {
7373
| - help: consider introducing lifetime `'a` here: `<'a>`
@@ -77,7 +77,7 @@ LL | f: &'a isize
7777
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
7878

7979
error[E0261]: use of undeclared lifetime name `'a`
80-
--> $DIR/regions-name-undeclared.rs:32:14
80+
--> $DIR/regions-name-undeclared.rs:33:14
8181
|
8282
LL | fn f(a: &'a isize) { }
8383
| - ^^ undeclared lifetime
@@ -87,7 +87,7 @@ LL | fn f(a: &'a isize) { }
8787
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
8888

8989
error[E0261]: use of undeclared lifetime name `'a`
90-
--> $DIR/regions-name-undeclared.rs:40:17
90+
--> $DIR/regions-name-undeclared.rs:41:17
9191
|
9292
LL | fn fn_types(a: &'a isize,
9393
| - ^^ undeclared lifetime
@@ -97,7 +97,7 @@ LL | fn fn_types(a: &'a isize,
9797
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
9898

9999
error[E0261]: use of undeclared lifetime name `'b`
100-
--> $DIR/regions-name-undeclared.rs:42:36
100+
--> $DIR/regions-name-undeclared.rs:43:36
101101
|
102102
LL | ... &'b isize,
103103
| ^^ undeclared lifetime
@@ -114,7 +114,7 @@ LL | b: Box<dyn for<'a, 'b> FnOnce(&'a isize,
114114
| ^^^^
115115

116116
error[E0261]: use of undeclared lifetime name `'b`
117-
--> $DIR/regions-name-undeclared.rs:45:36
117+
--> $DIR/regions-name-undeclared.rs:46:36
118118
|
119119
LL | ... &'b isize)>,
120120
| ^^ undeclared lifetime
@@ -131,7 +131,7 @@ LL | b: Box<dyn for<'a, 'b> FnOnce(&'a isize,
131131
| ^^^^
132132

133133
error[E0261]: use of undeclared lifetime name `'a`
134-
--> $DIR/regions-name-undeclared.rs:46:17
134+
--> $DIR/regions-name-undeclared.rs:47:17
135135
|
136136
LL | fn fn_types(a: &'a isize,
137137
| - help: consider introducing lifetime `'a` here: `<'a>`
@@ -141,6 +141,22 @@ LL | c: &'a isize)
141141
|
142142
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
143143

144-
error: aborting due to 11 previous errors
144+
error[E0261]: use of undeclared lifetime name `'a`
145+
--> $DIR/regions-name-undeclared.rs:53:31
146+
|
147+
LL | async fn buggy(&self) -> &'a str {
148+
| ^^ undeclared lifetime
149+
|
150+
= help: if you want to experiment with in-band lifetime bindings, add `#![feature(in_band_lifetimes)]` to the crate attributes
151+
help: consider introducing lifetime `'a` here
152+
|
153+
LL | impl<'a> Bug {
154+
| ^^^^
155+
help: consider introducing lifetime `'a` here
156+
|
157+
LL | async fn buggy<'a>(&self) -> &'a str {
158+
| ^^^^
159+
160+
error: aborting due to 12 previous errors
145161

146162
For more information about this error, try `rustc --explain E0261`.

0 commit comments

Comments
 (0)