]> git.lizzy.rs Git - rust.git/commitdiff
Improve SubSupConflict case with one named, one anonymous lifetime parameter #42701
authorCengiz Can <123910+cengizIO@users.noreply.github.com>
Mon, 28 Aug 2017 23:01:53 +0000 (02:01 +0300)
committerCengiz Can <cengizc@gmail.com>
Sun, 12 Nov 2017 15:56:45 +0000 (18:56 +0300)
23 files changed:
src/librustc/infer/error_reporting/different_lifetimes.rs
src/librustc/infer/error_reporting/named_anon_conflict.rs
src/test/compile-fail/associated-types-project-from-hrtb-in-fn-body.rs
src/test/compile-fail/associated-types/cache/project-fn-ret-contravariant.rs
src/test/compile-fail/associated-types/cache/project-fn-ret-invariant.rs
src/test/compile-fail/borrowck/borrowck-reborrow-from-shorter-lived-andmut.rs
src/test/compile-fail/issue-17728.rs
src/test/compile-fail/issue-40288-2.rs
src/test/compile-fail/object-lifetime-default-from-box-error.rs
src/test/compile-fail/region-lifetime-bounds-on-fns-where-clause.rs
src/test/compile-fail/region-multiple-lifetime-bounds-on-fns-where-clause.rs
src/test/compile-fail/regions-bounded-method-type-parameters-cross-crate.rs
src/test/compile-fail/regions-bounded-method-type-parameters-trait-bound.rs
src/test/compile-fail/regions-creating-enums3.rs
src/test/compile-fail/regions-free-region-ordering-callee.rs
src/test/compile-fail/regions-lifetime-bounds-on-fns.rs
src/test/compile-fail/regions-reborrow-from-shorter-mut-ref-mut-ref.rs
src/test/compile-fail/regions-reborrow-from-shorter-mut-ref.rs
src/test/ui/lifetime-errors/42701_one_named_and_one_anonymous.rs [new file with mode: 0644]
src/test/ui/lifetime-errors/42701_one_named_and_one_anonymous.stderr [new file with mode: 0644]
src/test/ui/lifetime-errors/ex2c-push-inference-variable.stderr
src/test/ui/lifetime-errors/ex2d-push-inference-variable-2.stderr
src/test/ui/lifetime-errors/ex2e-push-inference-variable-3.stderr

index d7e0877d95c2817e6df14700a9ecf9963d06690b..36370e23f216128f6f7e7c9c06eff16e95e464a4 100644 (file)
@@ -60,6 +60,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
     pub fn try_report_anon_anon_conflict(&self, error: &RegionResolutionError<'tcx>) -> bool {
         let (span, sub, sup) = match *error {
             ConcreteFailure(ref origin, sub, sup) => (origin.span(), sub, sup),
+            SubSupConflict(_, ref origin, sub, _, sup) => (origin.span(), sub, sup),
             _ => return false, // inapplicable
         };
 
index 6d3b950784097b54ed721e17bda261b79af298e0..e0b8a193ede0c15e27c2be1a7cadffef572e60c7 100644 (file)
@@ -21,6 +21,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
     pub fn try_report_named_anon_conflict(&self, error: &RegionResolutionError<'tcx>) -> bool {
         let (span, sub, sup) = match *error {
             ConcreteFailure(ref origin, sub, sup) => (origin.span(), sub, sup),
+            SubSupConflict(_, ref origin, sub, _, sup) => (origin.span(), sub, sup),
             _ => return false, // inapplicable
         };
 
index 285a77d6b657ae8bd35d012f2b320cab4441b2c2..5451a20d8166ff9838f28014984d01e22412711d 100644 (file)
@@ -30,7 +30,7 @@ fn bar<'a, 'b, I : for<'x> Foo<&'x isize>>(
 {
     // x and y here have two distinct lifetimes:
     let z: I::A = if cond { x } else { y };
-    //~^ ERROR cannot infer
+    //~^ ERROR lifetime mismatch
 }
 
 pub fn main() {}
index 0e822aff01e877771ef084835c72736bec3aeacc..a5e8f4068e6619711695c6310fdc4a8de6fe96c5 100644 (file)
@@ -50,9 +50,10 @@ fn baz<'a,'b>(x: &'a u32) -> &'static u32 {
 
 #[cfg(krisskross)] // two instantiations, mixing and matching: BAD
 fn transmute<'a,'b>(x: &'a u32, y: &'b u32) -> (&'a u32, &'b u32) {
-   let a = bar(foo, y); //[krisskross]~ ERROR E0495
-   let b = bar(foo, x); //[krisskross]~ ERROR E0495
-   (a, b)
+   let a = bar(foo, y);
+   let b = bar(foo, x);
+   (a, b) //[krisskross]~ ERROR 55:5: 55:6: lifetime mismatch [E0623]
+   //[krisskross]~^ ERROR 55:8: 55:9: lifetime mismatch [E0623]
 }
 
 #[rustc_error]
index 10fe612980d34a114cd374250926afcfb66e39e5..3920024c8e84e8bb53ff412fa1de17cce8ed6d54 100644 (file)
@@ -45,9 +45,9 @@ fn baz<'a,'b>(x: Type<'a>, y: Type<'b>) -> (Type<'a>, Type<'b>) {
 #[cfg(oneuse)] // one instantiation: BAD
 fn baz<'a,'b>(x: Type<'a>, y: Type<'b>) -> (Type<'a>, Type<'b>) {
    let f = foo; // <-- No consistent type can be inferred for `f` here.
-   let a = bar(f, x); //[oneuse]~^ ERROR E0495
+   let a = bar(f, x);
    let b = bar(f, y);
-   (a, b)
+   (a, b) //[oneuse]~ ERROR E0623
 }
 
 #[cfg(transmute)] // one instantiations: BAD
@@ -60,9 +60,10 @@ fn baz<'a,'b>(x: Type<'a>) -> Type<'static> {
 
 #[cfg(krisskross)] // two instantiations, mixing and matching: BAD
 fn transmute<'a,'b>(x: Type<'a>, y: Type<'b>) -> (Type<'a>, Type<'b>) {
-   let a = bar(foo, y); //[krisskross]~ ERROR E0495
-   let b = bar(foo, x); //[krisskross]~ ERROR E0495
-   (a, b)
+   let a = bar(foo, y);
+   let b = bar(foo, x);
+   (a, b) //[krisskross]~ ERROR E0623
+   //[krisskross]~^ ERROR E0623
 }
 
 #[rustc_error]
index eee407472bf14c12342ce07bf4d20200f88dcfc4..af85e68f5debe8b628ec6a58a913179c8676c34d 100644 (file)
@@ -17,7 +17,7 @@ struct S<'a> {
 
 fn copy_borrowed_ptr<'a,'b>(p: &'a mut S<'b>) -> S<'b> {
     S { pointer: &mut *p.pointer }
-    //~^ ERROR cannot infer
+    //~^ ERROR lifetime mismatch
 }
 
 fn main() {
index 9724d17bef1eaf446e77c95e0a0d7b59975fe0e1..8516a8ea52e42ddbefb5860043aad9f85781f488 100644 (file)
@@ -21,9 +21,9 @@ trait TraversesWorld {
     fn attemptTraverse(&self, room: &Room, directionStr: &str) -> Result<&Room, &str> {
         let direction = str_to_direction(directionStr);
         let maybe_room = room.direction_to_room.get(&direction);
-        //~^ ERROR cannot infer an appropriate lifetime for autoref due to conflicting requirements
         match maybe_room {
             Some(entry) => Ok(entry),
+            //~^ ERROR 25:28: 25:37: lifetime mismatch [E0623]
             _ => Err("Direction does not exist in room.")
         }
     }
index c1e8cb8b6defb231e9594736b31ae80165decbf8..e16a7ecf6b9087982ec09aa1a31fd79264d0a34c 100644 (file)
@@ -12,12 +12,12 @@ fn prove_static<T: 'static + ?Sized>(_: &'static T) {}
 
 fn lifetime_transmute_slice<'a, T: ?Sized>(x: &'a T, y: &T) -> &'a T {
     let mut out = [x];
-    //~^ ERROR cannot infer an appropriate lifetime due to conflicting requirements
     {
         let slice: &mut [_] = &mut out;
         slice[0] = y;
     }
     out[0]
+    //~^ ERROR 19:5: 19:11: explicit lifetime required in the type of `y` [E0621]
 }
 
 struct Struct<T, U: ?Sized> {
@@ -27,12 +27,12 @@ struct Struct<T, U: ?Sized> {
 
 fn lifetime_transmute_struct<'a, T: ?Sized>(x: &'a T, y: &T) -> &'a T {
     let mut out = Struct { head: x, _tail: [()] };
-    //~^ ERROR cannot infer an appropriate lifetime due to conflicting requirements
     {
         let dst: &mut Struct<_, [()]> = &mut out;
         dst.head = y;
     }
     out.head
+    //~^ ERROR 34:5: 34:13: explicit lifetime required in the type of `y` [E0621]
 }
 
 fn main() {
index c0dd5200f6cb4e97be5e24eddf6f1d699f27052a..c50f425b2c01d744cb41256a10fd0f726010c8bf 100644 (file)
@@ -38,7 +38,7 @@ fn store(ss: &mut SomeStruct, b: Box<SomeTrait>) {
 fn store1<'b>(ss: &mut SomeStruct, b: Box<SomeTrait+'b>) {
     // Here we override the lifetimes explicitly, and so naturally we get an error.
 
-    ss.r = b; //~ ERROR cannot infer an appropriate lifetime
+    ss.r = b; //~ ERROR 41:12: 41:13: explicit lifetime required in the type of `ss` [E0621]
 }
 
 fn main() {
index f886c0255ccbf08631500c18f692fafd98c6dd58..e3d96f52e817b857ba091bafaff9c5ecee71198b 100644 (file)
@@ -21,7 +21,7 @@ fn b<'a, 'b>(x: &mut &'a isize, y: &mut &'b isize) {
 fn c<'a,'b>(x: &mut &'a isize, y: &mut &'b isize) {
     // Here we try to call `foo` but do not know that `'a` and `'b` are
     // related as required.
-    a(x, y); //~ ERROR cannot infer
+    a(x, y); //~ ERROR 24:7: 24:8: lifetime mismatch [E0623]
 }
 
 fn d() {
index bae9608c3f05afa741e68eb59aa52676ec6379a0..d8d12444dddb34bae2979ee6c7086f0f0fa9ba77 100644 (file)
@@ -23,7 +23,7 @@ fn b<'a, 'b, 'c>(x: &mut &'a isize, y: &mut &'b isize, z: &mut &'c isize) {
 fn c<'a,'b, 'c>(x: &mut &'a isize, y: &mut &'b isize, z: &mut &'c isize) {
     // Here we try to call `foo` but do not know that `'a` and `'b` are
     // related as required.
-    a(x, y, z); //~ ERROR cannot infer
+    a(x, y, z); //~ ERROR 26:7: 26:8: lifetime mismatch [E0623]
 }
 
 fn d() {
index 1eb36e34ab32ee611ceaaa2e70b1547c93b93a07..24e4c5fbd91be47f345f39866404be8991d2f0c2 100644 (file)
@@ -27,7 +27,7 @@ fn call_into_maybe_owned<'x,F:IntoMaybeOwned<'x>>(f: F) {
 
 fn call_bigger_region<'x, 'y>(a: Inv<'x>, b: Inv<'y>) {
     // Here the value provided for 'y is 'y, and hence 'y:'x does not hold.
-    a.bigger_region(b) //~ ERROR cannot infer
+    a.bigger_region(b) //~ ERROR 30:7: 30:20: lifetime mismatch [E0623]
 }
 
 fn main() { }
index f13d8a60894cb6b7ae9e3f4162cd52b427e49167..3e9d2aa6c3bff4b04755d25f6a51985e0c075879 100644 (file)
@@ -27,7 +27,7 @@ fn caller1<'a,'b,F:Foo<'a>>(a: Inv<'a>, b: Inv<'b>, f: F) {
 
 fn caller2<'a,'b,F:Foo<'a>>(a: Inv<'a>, b: Inv<'b>, f: F) {
     // Here the value provided for 'y is 'b, and hence 'b:'a does not hold.
-    f.method(b); //~ ERROR cannot infer
+    f.method(b); //~ ERROR 30:7: 30:13: lifetime mismatch [E0623]
 }
 
 fn caller3<'a,'b:'a,F:Foo<'a>>(a: Inv<'a>, b: Inv<'b>, f: F) {
index 4c8484540aabbb1248695fc550c75ac159ae0908..dcc579d26c18f681f2e02bc1d89edb35233fb5c2 100644 (file)
@@ -14,7 +14,7 @@ enum ast<'a> {
 }
 
 fn mk_add_bad1<'a,'b>(x: &'a ast<'a>, y: &'b ast<'b>) -> ast<'a> {
-    ast::add(x, y) //~ ERROR cannot infer
+    ast::add(x, y) //~ ERROR 17:5: 17:19: lifetime mismatch [E0623]
 }
 
 fn main() {
index 1893395e2b0079e480edad4b4a6c0963e1b3b707..073a4f79b05f006d3143acd11b9862c873b62626 100644 (file)
@@ -20,13 +20,13 @@ fn ordering1<'a, 'b>(x: &'a &'b usize) -> &'a usize {
 
 fn ordering2<'a, 'b>(x: &'a &'b usize, y: &'a usize) -> &'b usize {
     // However, it is not safe to assume that 'b <= 'a
-    &*y //~ ERROR cannot infer
+    &*y //~ ERROR 23:5: 23:8: lifetime mismatch [E0623]
 }
 
 fn ordering3<'a, 'b>(x: &'a usize, y: &'b usize) -> &'a &'b usize {
     // Do not infer an ordering from the return value.
     let z: &'b usize = &*x;
-    //~^ ERROR cannot infer
+    //~^ ERROR 28:24: 28:27: lifetime mismatch [E0623]
     panic!();
 }
 
index ef1c58bf972e31ba07c8c9a185fae164f1262958..5955619ea92adde671d8e5a8caa7fa8ae30c2d32 100644 (file)
@@ -21,7 +21,7 @@ fn b<'a, 'b>(x: &mut &'a isize, y: &mut &'b isize) {
 fn c<'a,'b>(x: &mut &'a isize, y: &mut &'b isize) {
     // Here we try to call `foo` but do not know that `'a` and `'b` are
     // related as required.
-    a(x, y); //~ ERROR E0495
+    a(x, y); //~ ERROR 24:7: 24:8: lifetime mismatch [E0623]
 }
 
 fn d() {
index 9743f11c9667bc1dae70ed4e4a69a254c7b79598..f6f1a189e5ee14dbd5dc6cc57759ef71bd704284 100644 (file)
@@ -11,7 +11,7 @@
 // Issue #8624. Test for reborrowing with 3 levels, not just two.
 
 fn copy_borrowed_ptr<'a, 'b, 'c>(p: &'a mut &'b mut &'c mut isize) -> &'b mut isize {
-    &mut ***p //~ ERROR cannot infer
+    &mut ***p //~ ERROR 14:5: 14:14: lifetime mismatch [E0623]
 }
 
 fn main() {
index 399ebd6a2a72620431e4f89abb7a383b014ea8e7..7270b477d2d88df3badf5762577cc24b78c96d36 100644 (file)
@@ -13,7 +13,7 @@
 // for `'a` (which must be a sublifetime of `'b`).
 
 fn copy_borrowed_ptr<'a, 'b>(p: &'a mut &'b mut isize) -> &'b mut isize {
-    &mut **p //~ ERROR cannot infer
+    &mut **p //~ ERROR 16:5: 16:13: lifetime mismatch [E0623]
 }
 
 fn main() {
diff --git a/src/test/ui/lifetime-errors/42701_one_named_and_one_anonymous.rs b/src/test/ui/lifetime-errors/42701_one_named_and_one_anonymous.rs
new file mode 100644 (file)
index 0000000..04112c3
--- /dev/null
@@ -0,0 +1,24 @@
+// Copyright 2017 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+struct Foo {
+    field: i32,
+}
+
+fn foo2<'a>(a: &'a Foo, x: &i32) -> &'a i32 {
+    if true {
+        let p: &i32 = &a.field;
+        &*p
+    } else {
+        &*x
+    }
+}
+
+fn main() { }
diff --git a/src/test/ui/lifetime-errors/42701_one_named_and_one_anonymous.stderr b/src/test/ui/lifetime-errors/42701_one_named_and_one_anonymous.stderr
new file mode 100644 (file)
index 0000000..613c903
--- /dev/null
@@ -0,0 +1,11 @@
+error[E0621]: explicit lifetime required in the type of `x`
+  --> $DIR/42701_one_named_and_one_anonymous.rs:20:9
+   |
+15 | fn foo2<'a>(a: &'a Foo, x: &i32) -> &'a i32 {
+   |                         - consider changing the type of `x` to `&'a i32`
+...
+20 |         &*x
+   |         ^^^ lifetime `'a` required
+
+error: aborting due to previous error
+
index 7356fc11862f6e104d004cd642852161b18e5e1b..495af8ae208f640acc74d4a986432503449a515f 100644 (file)
@@ -1,35 +1,11 @@
-error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements
-  --> $DIR/ex2c-push-inference-variable.rs:16:13
-   |
-16 |     let z = Ref { data: y.data };
-   |             ^^^
-   |
-note: first, the lifetime cannot outlive the lifetime 'c as defined on the function body at 15:1...
-  --> $DIR/ex2c-push-inference-variable.rs:15:1
-   |
-15 | / fn foo<'a, 'b, 'c>(x: &'a mut Vec<Ref<'b, i32>>, y: Ref<'c, i32>) {
-16 | |     let z = Ref { data: y.data };
-17 | |     x.push(z);
-18 | | }
-   | |_^
-note: ...so that reference does not outlive borrowed content
-  --> $DIR/ex2c-push-inference-variable.rs:16:25
-   |
-16 |     let z = Ref { data: y.data };
-   |                         ^^^^^^
-note: but, the lifetime must be valid for the lifetime 'b as defined on the function body at 15:1...
-  --> $DIR/ex2c-push-inference-variable.rs:15:1
-   |
-15 | / fn foo<'a, 'b, 'c>(x: &'a mut Vec<Ref<'b, i32>>, y: Ref<'c, i32>) {
-16 | |     let z = Ref { data: y.data };
-17 | |     x.push(z);
-18 | | }
-   | |_^
-note: ...so that expression is assignable (expected Ref<'b, _>, found Ref<'_, _>)
+error[E0623]: lifetime mismatch
   --> $DIR/ex2c-push-inference-variable.rs:17:12
    |
+15 | fn foo<'a, 'b, 'c>(x: &'a mut Vec<Ref<'b, i32>>, y: Ref<'c, i32>) {
+   |                                   ------------      ------------ these two types are declared with different lifetimes...
+16 |     let z = Ref { data: y.data };
 17 |     x.push(z);
-   |            ^
+   |            ^ ...but data from `y` flows into `x` here
 
 error: aborting due to previous error
 
index 38b0acf9339e0e89595a6c0ee889abca1f2c221e..1f250a888472c55f43c03fcd82c8e56d8b789728 100644 (file)
@@ -1,37 +1,10 @@
-error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements
-  --> $DIR/ex2d-push-inference-variable-2.rs:17:13
-   |
-17 |     let b = Ref { data: y.data };
-   |             ^^^
-   |
-note: first, the lifetime cannot outlive the lifetime 'c as defined on the function body at 15:1...
-  --> $DIR/ex2d-push-inference-variable-2.rs:15:1
-   |
-15 | / fn foo<'a, 'b, 'c>(x: &'a mut Vec<Ref<'b, i32>>, y: Ref<'c, i32>) {
-16 | |     let a: &mut Vec<Ref<i32>> = x;
-17 | |     let b = Ref { data: y.data };
-18 | |     a.push(b);
-19 | | }
-   | |_^
-note: ...so that reference does not outlive borrowed content
-  --> $DIR/ex2d-push-inference-variable-2.rs:17:25
-   |
-17 |     let b = Ref { data: y.data };
-   |                         ^^^^^^
-note: but, the lifetime must be valid for the lifetime 'b as defined on the function body at 15:1...
-  --> $DIR/ex2d-push-inference-variable-2.rs:15:1
-   |
-15 | / fn foo<'a, 'b, 'c>(x: &'a mut Vec<Ref<'b, i32>>, y: Ref<'c, i32>) {
-16 | |     let a: &mut Vec<Ref<i32>> = x;
-17 | |     let b = Ref { data: y.data };
-18 | |     a.push(b);
-19 | | }
-   | |_^
-note: ...so that expression is assignable (expected &mut std::vec::Vec<Ref<'_, i32>>, found &mut std::vec::Vec<Ref<'b, i32>>)
+error[E0623]: lifetime mismatch
   --> $DIR/ex2d-push-inference-variable-2.rs:16:33
    |
+15 | fn foo<'a, 'b, 'c>(x: &'a mut Vec<Ref<'b, i32>>, y: Ref<'c, i32>) {
+   |                                   ------------      ------------ these two types are declared with different lifetimes...
 16 |     let a: &mut Vec<Ref<i32>> = x;
-   |                                 ^
+   |                                 ^ ...but data from `y` flows into `x` here
 
 error: aborting due to previous error
 
index 035e516e8628e9b933157645e651ef281f272c01..343c35b871edea38764ecdaa671978a50a32935c 100644 (file)
@@ -1,37 +1,10 @@
-error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'a` due to conflicting requirements
-  --> $DIR/ex2e-push-inference-variable-3.rs:17:13
-   |
-17 |     let b = Ref { data: y.data };
-   |             ^^^
-   |
-note: first, the lifetime cannot outlive the lifetime 'c as defined on the function body at 15:1...
-  --> $DIR/ex2e-push-inference-variable-3.rs:15:1
-   |
-15 | / fn foo<'a, 'b, 'c>(x: &'a mut Vec<Ref<'b, i32>>, y: Ref<'c, i32>) {
-16 | |     let a: &mut Vec<Ref<i32>> = x;
-17 | |     let b = Ref { data: y.data };
-18 | |     Vec::push(a, b);
-19 | | }
-   | |_^
-note: ...so that reference does not outlive borrowed content
-  --> $DIR/ex2e-push-inference-variable-3.rs:17:25
-   |
-17 |     let b = Ref { data: y.data };
-   |                         ^^^^^^
-note: but, the lifetime must be valid for the lifetime 'b as defined on the function body at 15:1...
-  --> $DIR/ex2e-push-inference-variable-3.rs:15:1
-   |
-15 | / fn foo<'a, 'b, 'c>(x: &'a mut Vec<Ref<'b, i32>>, y: Ref<'c, i32>) {
-16 | |     let a: &mut Vec<Ref<i32>> = x;
-17 | |     let b = Ref { data: y.data };
-18 | |     Vec::push(a, b);
-19 | | }
-   | |_^
-note: ...so that expression is assignable (expected &mut std::vec::Vec<Ref<'_, i32>>, found &mut std::vec::Vec<Ref<'b, i32>>)
+error[E0623]: lifetime mismatch
   --> $DIR/ex2e-push-inference-variable-3.rs:16:33
    |
+15 | fn foo<'a, 'b, 'c>(x: &'a mut Vec<Ref<'b, i32>>, y: Ref<'c, i32>) {
+   |                                   ------------      ------------ these two types are declared with different lifetimes...
 16 |     let a: &mut Vec<Ref<i32>> = x;
-   |                                 ^
+   |                                 ^ ...but data from `y` flows into `x` here
 
 error: aborting due to previous error