From 10cf626d0ea7be3eb971691772b5eb30013d4f02 Mon Sep 17 00:00:00 2001 From: Camille GILLOT Date: Wed, 29 Dec 2021 09:19:57 +0100 Subject: [PATCH] Bless nll tests. --- .../rustc_borrowck/src/region_infer/mod.rs | 18 ++++++++++++++++++ .../ret-impl-trait-one.nll.stderr | 18 ++++++++---------- .../dropck/drop-with-active-borrows-2.stderr | 5 ++--- src/test/ui/issues/issue-13497-2.rs | 4 ++-- src/test/ui/issues/issue-13497-2.stderr | 14 +++++--------- ...ypes_pin_lifetime_mismatch-async.nll.stderr | 5 ++--- 6 files changed, 37 insertions(+), 27 deletions(-) diff --git a/compiler/rustc_borrowck/src/region_infer/mod.rs b/compiler/rustc_borrowck/src/region_infer/mod.rs index d9120ff245735..0f0d3eaa2938b 100644 --- a/compiler/rustc_borrowck/src/region_infer/mod.rs +++ b/compiler/rustc_borrowck/src/region_infer/mod.rs @@ -2156,6 +2156,24 @@ impl<'tcx> RegionInferenceContext<'tcx> { } } + // When in async fn, prefer errors that come from inside the closure. + if !categorized_path[i].from_closure { + let span = categorized_path.iter().find_map(|p| { + if p.from_closure + && p.category == categorized_path[i].category + && categorized_path[i].cause.span.contains(p.cause.span) + { + Some(p.cause.span) + } else { + None + } + }); + + if let Some(span) = span { + categorized_path[i].cause.span = span; + } + } + return categorized_path[i].clone(); } diff --git a/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.nll.stderr b/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.nll.stderr index 2722c72c20a33..b0ea6af005004 100644 --- a/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.nll.stderr +++ b/src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.nll.stderr @@ -1,15 +1,13 @@ error: lifetime may not live long enough - --> $DIR/ret-impl-trait-one.rs:10:85 + --> $DIR/ret-impl-trait-one.rs:12:5 | -LL | async fn async_ret_impl_trait3<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> + 'b { - | ________________________________--__--_______________________________________________^ - | | | | - | | | lifetime `'b` defined here - | | lifetime `'a` defined here -LL | | -LL | | (a, b) -LL | | } - | |_^ function was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a` +LL | async fn async_ret_impl_trait3<'a, 'b>(a: &'a u8, b: &'b u8) -> impl Trait<'a> + 'b { + | -- -- lifetime `'b` defined here + | | + | lifetime `'a` defined here +LL | +LL | (a, b) + | ^^^^^^ function was supposed to return data with lifetime `'b` but it is returning data with lifetime `'a` | = help: consider adding the following bound: `'a: 'b` diff --git a/src/test/ui/dropck/drop-with-active-borrows-2.stderr b/src/test/ui/dropck/drop-with-active-borrows-2.stderr index 24650dfac02d9..d5b747d42fb18 100644 --- a/src/test/ui/dropck/drop-with-active-borrows-2.stderr +++ b/src/test/ui/dropck/drop-with-active-borrows-2.stderr @@ -1,10 +1,9 @@ error[E0515]: cannot return value referencing local variable `raw_lines` - --> $DIR/drop-with-active-borrows-2.rs:3:5 + --> $DIR/drop-with-active-borrows-2.rs:3:30 | LL | raw_lines.iter().map(|l| l.trim()).collect() - | ----------------^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + | ---------------- ^^^^^^^^ returns a value referencing data owned by the current function | | - | returns a value referencing data owned by the current function | `raw_lines` is borrowed here error: aborting due to previous error diff --git a/src/test/ui/issues/issue-13497-2.rs b/src/test/ui/issues/issue-13497-2.rs index c82da0f0096ad..32abe2b854312 100644 --- a/src/test/ui/issues/issue-13497-2.rs +++ b/src/test/ui/issues/issue-13497-2.rs @@ -1,7 +1,7 @@ fn read_lines_borrowed<'a>() -> Vec<&'a str> { let rawLines: Vec = vec!["foo ".to_string(), " bar".to_string()]; - rawLines //~ ERROR cannot return value referencing local variable `rawLines` - .iter().map(|l| l.trim()).collect() + rawLines.iter().map(|l| l.trim()).collect() + //~^ ERROR cannot return value referencing local variable `rawLines` } fn main() {} diff --git a/src/test/ui/issues/issue-13497-2.stderr b/src/test/ui/issues/issue-13497-2.stderr index 6f72b79f2a5e0..1b78e7ec1c64d 100644 --- a/src/test/ui/issues/issue-13497-2.stderr +++ b/src/test/ui/issues/issue-13497-2.stderr @@ -1,14 +1,10 @@ error[E0515]: cannot return value referencing local variable `rawLines` - --> $DIR/issue-13497-2.rs:3:5 + --> $DIR/issue-13497-2.rs:3:29 | -LL | rawLines - | _____^ - | |_____| - | || -LL | || .iter().map(|l| l.trim()).collect() - | ||_______________-___________________________^ returns a value referencing data owned by the current function - | |________________| - | `rawLines` is borrowed here +LL | rawLines.iter().map(|l| l.trim()).collect() + | --------------- ^^^^^^^^ returns a value referencing data owned by the current function + | | + | `rawLines` is borrowed here error: aborting due to previous error diff --git a/src/test/ui/self/arbitrary_self_types_pin_lifetime_mismatch-async.nll.stderr b/src/test/ui/self/arbitrary_self_types_pin_lifetime_mismatch-async.nll.stderr index 57374b7e3bb27..aaed3665149a2 100644 --- a/src/test/ui/self/arbitrary_self_types_pin_lifetime_mismatch-async.nll.stderr +++ b/src/test/ui/self/arbitrary_self_types_pin_lifetime_mismatch-async.nll.stderr @@ -20,9 +20,8 @@ error: lifetime may not live long enough --> $DIR/arbitrary_self_types_pin_lifetime_mismatch-async.rs:17:64 | LL | async fn bar<'a>(self: Alias<&Self>, arg: &'a ()) -> &() { arg } - | -- - ^^^ associated function was supposed to return data with lifetime `'1` but it is returning data with lifetime `'a` - | | | - | | let's call the lifetime of this reference `'1` + | -- ---- has type `Pin<&'1 Foo>` ^^^ associated function was supposed to return data with lifetime `'1` but it is returning data with lifetime `'a` + | | | lifetime `'a` defined here error: aborting due to 3 previous errors