Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion compiler/rustc_borrowck/src/diagnostics/region_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,12 +791,18 @@ impl<'tcx> MirBorrowckCtxt<'_, '_, 'tcx> {
fn give_name_if_anonymous_region_appears_in_output(&self, fr: RegionVid) -> Option<RegionName> {
let tcx = self.infcx.tcx;

let return_ty = self.regioncx.universal_regions().unnormalized_output_ty;
let mut return_ty = self.regioncx.universal_regions().unnormalized_output_ty;
debug!("give_name_if_anonymous_region_appears_in_output: return_ty = {:?}", return_ty);
if !tcx.any_free_region_meets(&return_ty, |r| r.as_var() == fr) {
return None;
}

if let ty::Coroutine(_, args) = return_ty.kind() {
// When the return type is identified to be `{async closure body}`, we instead care
// about the actual return type of that coroutine.
return_ty = args.as_coroutine().return_ty();
}

let mir_hir_id = self.mir_hir_id();

let (return_span, mir_description, hir_ty) = match tcx.hir_node(mir_hir_id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ error: lifetime may not live long enough
--> $DIR/higher-ranked-return.rs:11:46
|
LL | let x = async move |x: &str| -> &str {
| ________________________________-________----_^
| ________________________________-________-____^
| | | |
| | | return type of async closure `{async closure body@$DIR/higher-ranked-return.rs:11:46: 13:10}` contains a lifetime `'2`
| | | let's call the lifetime of this reference `'2`
| | let's call the lifetime of this reference `'1`
LL | | x
LL | | };
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/async-await/async-closures/not-lending.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ error: lifetime may not live long enough
LL | let x = async move || -> &String { &s };
| ------------------------ ^^^^^^ returning this value requires that `'1` must outlive `'2`
| | |
| | return type of async closure `{async closure body@$DIR/not-lending.rs:12:42: 12:48}` contains a lifetime `'2`
| | let's call the lifetime of this reference `'2`
| lifetime `'1` represents this closure's body
|
= note: closure implements `AsyncFn`, so references to captured variables can't escape the closure
Expand All @@ -15,7 +15,7 @@ error: lifetime may not live long enough
LL | let x = async move || { &s };
| ------------- ^^^^^^ returning this value requires that `'1` must outlive `'2`
| | |
| | return type of async closure `{async closure body@$DIR/not-lending.rs:16:31: 16:37}` contains a lifetime `'2`
| | return type of async closure is &'2 String
| lifetime `'1` represents this closure's body
|
= note: closure implements `AsyncFn`, so references to captured variables can't escape the closure
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ error: lifetime may not live long enough
LL | (async move || {
| ______-------------_^
| | | |
| | | return type of async closure `{async closure body@$DIR/issue-74072-lifetime-name-annotations.rs:13:20: 19:6}` contains a lifetime `'2`
| | | return type of async closure is &'2 i32
| | lifetime `'1` represents this closure's body
LL | |
LL | |
Expand Down Expand Up @@ -78,7 +78,7 @@ error: lifetime may not live long enough
LL | (async move || -> &i32 {
| ______---------------------_^
| | | |
| | | return type of async closure `{async closure body@$DIR/issue-74072-lifetime-name-annotations.rs:23:28: 29:6}` contains a lifetime `'2`
| | | let's call the lifetime of this reference `'2`
| | lifetime `'1` represents this closure's body
LL | |
LL | |
Expand Down
Loading