about summary refs log tree commit diff
diff options
context:
space:
mode:
authorCamille GILLOT <gillot.camille@gmail.com>2021-12-29 09:19:57 +0100
committerCamille GILLOT <gillot.camille@gmail.com>2022-02-12 01:26:17 +0100
commit10cf626d0ea7be3eb971691772b5eb30013d4f02 (patch)
tree467a503f0fff9afabdc84dcf5f6067452cff67d3
parentc6a3f5d6062f55779e52de24a6465cf87ffbdd19 (diff)
downloadrust-10cf626d0ea7be3eb971691772b5eb30013d4f02.tar.gz
rust-10cf626d0ea7be3eb971691772b5eb30013d4f02.zip
Bless nll tests.
-rw-r--r--compiler/rustc_borrowck/src/region_infer/mod.rs18
-rw-r--r--src/test/ui/async-await/multiple-lifetimes/ret-impl-trait-one.nll.stderr18
-rw-r--r--src/test/ui/dropck/drop-with-active-borrows-2.stderr5
-rw-r--r--src/test/ui/issues/issue-13497-2.rs4
-rw-r--r--src/test/ui/issues/issue-13497-2.stderr14
-rw-r--r--src/test/ui/self/arbitrary_self_types_pin_lifetime_mismatch-async.nll.stderr5
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 d9120ff2457..0f0d3eaa293 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 2722c72c20a..b0ea6af0050 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 24650dfac02..d5b747d42fb 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 c82da0f0096..32abe2b8543 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<String> = 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 6f72b79f2a5..1b78e7ec1c6 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 57374b7e3bb..aaed3665149 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