forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rollup merge of rust-lang#76468 - SNCPlay42:lifetime-names, r=Mark-Si…
…mulacrum Improve lifetime name annotations for closures & async functions * Don't refer to async functions as "generators" in error output * Where possible, emit annotations pointing exactly at the `&` in the return type of closures (when they have explicit return types) and async functions, like we do for arguments. Addresses rust-lang#74072, but I wouldn't call that *closed* until annotations are identical for async and non-async functions. * Emit a better annotation when the lifetime doesn't appear in the full name type, which currently happens for opaque types like `impl Future`. Addresses rust-lang#74497, but further improves could probably be made (why *doesn't* it appear in the type as `impl Future + '1`?) This is included in the same PR because the changes to `give_name_if_anonymous_region_appears_in_output` would introduce ICE otherwise (it would return `None` in cases where it didn't previously, which then gets `unwrap`ped)
- Loading branch information
Showing
7 changed files
with
282 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
src/test/ui/async-await/issue-74072-lifetime-name-annotations.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// edition:2018 | ||
#![feature(async_closure)] | ||
use std::future::Future; | ||
|
||
// test the quality of annotations giving lifetimes names (`'1`) when async constructs are involved | ||
|
||
pub async fn async_fn(x: &mut i32) -> &i32 { | ||
let y = &*x; | ||
*x += 1; //~ ERROR cannot assign to `*x` because it is borrowed | ||
y | ||
} | ||
|
||
pub fn async_closure(x: &mut i32) -> impl Future<Output=&i32> { | ||
(async move || { | ||
let y = &*x; | ||
*x += 1; //~ ERROR cannot assign to `*x` because it is borrowed | ||
y | ||
})() | ||
} | ||
|
||
pub fn async_closure_explicit_return_type(x: &mut i32) -> impl Future<Output=&i32> { | ||
(async move || -> &i32 { | ||
let y = &*x; | ||
*x += 1; //~ ERROR cannot assign to `*x` because it is borrowed | ||
y | ||
})() | ||
} | ||
|
||
pub fn async_block(x: &mut i32) -> impl Future<Output=&i32> { | ||
async move { | ||
let y = &*x; | ||
*x += 1; //~ ERROR cannot assign to `*x` because it is borrowed | ||
y | ||
} | ||
} | ||
|
||
fn main() {} |
Oops, something went wrong.