Skip to content

Commit 91fd86e

Browse files
Rollup merge of #164761 - estebank:short-lifetime-in-return-expr, r=mati865
[tiny] Properly format return type in lifetime error with backticks ``` error: lifetime may not live long enough --> $DIR/issue-55394.rs:9:9 | LL | fn new(bar: &mut Bar) -> Self { | - ---- return type is `Foo<'2>` | | | let's call the lifetime of this reference `'1` LL | Foo { bar } | ^^^^^^^^^^^ associated function was supposed to return data with lifetime `'2` but it is returning data with lifetime `'1` ```
2 parents db87751 + 8aed22c commit 91fd86e

16 files changed

Lines changed: 19 additions & 19 deletions

‎compiler/rustc_borrowck/src/diagnostics/region_name.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ impl RegionName {
170170
RegionNameHighlight::CannotMatchHirTy(span, type_name),
171171
mir_description,
172172
) => {
173-
diag.span_label(*span, format!("return type{mir_description} is {type_name}"));
173+
diag.span_label(*span, format!("return type{mir_description} is `{type_name}`"));
174174
}
175175
RegionNameSource::AnonRegionFromYieldTy(span, type_name) => {
176176
diag.span_label(*span, format!("yield type is {type_name}"));

‎tests/ui/async-await/async-closures/not-lending.stderr‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ error: lifetime may not live long enough
1515
LL | let x = async move || { &s };
1616
| ------------- ^^^^^^ returning this value requires that `'1` must outlive `'2`
1717
| | |
18-
| | return type of async closure is &'2 String
18+
| | return type of async closure is `&'2 String`
1919
| lifetime `'1` represents this closure's body
2020
|
2121
= note: closure implements `AsyncFn`, so references to captured variables can't escape the closure

‎tests/ui/async-await/issue-74072-lifetime-name-annotations.stderr‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ error: lifetime may not live long enough
3434
LL | (async move || {
3535
| ______-------------_^
3636
| | | |
37-
| | | return type of async closure is &'2 i32
37+
| | | return type of async closure is `&'2 i32`
3838
| | lifetime `'1` represents this closure's body
3939
LL | |
4040
LL | |
@@ -50,7 +50,7 @@ error[E0506]: cannot assign to `*x` because it is borrowed
5050
--> $DIR/issue-74072-lifetime-name-annotations.rs:17:9
5151
|
5252
LL | (async move || {
53-
| - return type of async closure is &'1 i32
53+
| - return type of async closure is `&'1 i32`
5454
...
5555
LL | let y = &*x;
5656
| --- `*x` is borrowed here
@@ -99,7 +99,7 @@ error[E0506]: cannot assign to `*x` because it is borrowed
9999
--> $DIR/issue-74072-lifetime-name-annotations.rs:27:9
100100
|
101101
LL | (async move || -> &i32 {
102-
| - return type of async closure is &'1 i32
102+
| - return type of async closure is `&'1 i32`
103103
...
104104
LL | let y = &*x;
105105
| --- `*x` is borrowed here
@@ -112,7 +112,7 @@ error[E0506]: cannot assign to `*x` because it is borrowed
112112
--> $DIR/issue-74072-lifetime-name-annotations.rs:35:9
113113
|
114114
LL | async move {
115-
| - return type of async block is &'1 i32
115+
| - return type of async block is `&'1 i32`
116116
LL | let y = &*x;
117117
| --- `*x` is borrowed here
118118
LL | *x += 1;

‎tests/ui/borrowck/implementation-not-general-enough-ice-133252.stderr‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ error[E0597]: `not_static` does not live long enough
1515
--> $DIR/implementation-not-general-enough-ice-133252.rs:9:31
1616
|
1717
LL | async {
18-
| - return type of async block is &(dyn Owned + '1)
18+
| - return type of async block is `&(dyn Owned + '1)`
1919
LL | let not_static = 0;
2020
| ---------- binding `not_static` declared here
2121
LL | force_send(async_load(&not_static));

‎tests/ui/borrowck/unmatched-arg-and-hir-arg-issue-126385.stderr‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ error: lifetime may not live long enough
2424
--> $DIR/unmatched-arg-and-hir-arg-issue-126385.rs:10:9
2525
|
2626
LL | pub fn f(field: &[u32]) -> Self<u32> {
27-
| - --------- return type is MyStruct<'2>
27+
| - --------- return type is `MyStruct<'2>`
2828
| |
2929
| let's call the lifetime of this reference `'1`
3030
LL | Self { field }

‎tests/ui/closures/return-value-lifetime-error.stderr‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: lifetime may not live long enough
44
LL | let _ = counts.iter().max_by_key(|(_, v)| v);
55
| ------- ^ returning this value requires that `'1` must outlive `'2`
66
| | |
7-
| | return type of closure is &'2 &i32
7+
| | return type of closure is `&'2 &i32`
88
| has type `&'1 (&i32, &i32)`
99
|
1010
help: dereference the return value

‎tests/ui/error-codes/E0621-does-not-trigger-for-closures.stderr‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: lifetime may not live long enough
44
LL | invoke(&x, |a, b| if a > b { a } else { b });
55
| -- ^ returning this value requires that `'1` must outlive `'2`
66
| ||
7-
| |return type of closure is &'2 i32
7+
| |return type of closure is `&'2 i32`
88
| has type `&'1 i32`
99

1010
error: aborting due to 1 previous error

‎tests/ui/lifetimes/issue-79187-2.stderr‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ error: lifetime may not live long enough
5252
LL | take_foo(|a: &i32| a);
5353
| - - ^ returning this value requires that `'1` must outlive `'2`
5454
| | |
55-
| | return type of closure is &'2 i32
55+
| | return type of closure is `&'2 i32`
5656
| let's call the lifetime of this reference `'1`
5757

5858
error[E0308]: mismatched types

‎tests/ui/nll/issue-48238.stderr‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ error: lifetime may not live long enough
44
LL | move || use_val(&orig);
55
| ------- ^^^^^^^^^^^^^^ returning this value requires that `'1` must outlive `'2`
66
| | |
7-
| | return type of closure is &'2 u8
7+
| | return type of closure is `&'2 u8`
88
| lifetime `'1` represents this closure's body
99
|
1010
= note: closure implements `Fn`, so references to captured variables can't escape the closure

‎tests/ui/nll/issue-55394.stderr‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error: lifetime may not live long enough
22
--> $DIR/issue-55394.rs:9:9
33
|
44
LL | fn new(bar: &mut Bar) -> Self {
5-
| - ---- return type is Foo<'2>
5+
| - ---- return type is `Foo<'2>`
66
| |
77
| let's call the lifetime of this reference `'1`
88
LL | Foo { bar }

0 commit comments

Comments
 (0)