]> git.lizzy.rs Git - rust.git/commitdiff
partially revert 904a0bde93f0348f69914ee90b1f8b6e4e0d7cbc
authorNiko Matsakis <niko@alum.mit.edu>
Thu, 21 Feb 2019 17:14:30 +0000 (12:14 -0500)
committerNiko Matsakis <niko@alum.mit.edu>
Thu, 21 Feb 2019 17:50:13 +0000 (12:50 -0500)
This preserves the error you currently get on stable for the
old-lub-glb-object.rs test.

src/librustc/traits/select.rs
src/test/ui/lub-glb/old-lub-glb-object.rs
src/test/ui/lub-glb/old-lub-glb-object.stderr [new file with mode: 0644]

index 4a02b0331478ffc771880a701600a34b19dc7473..05fb40ac10a075147dd6927596103df34214d14b 100644 (file)
@@ -3315,9 +3315,27 @@ fn confirm_builtin_unsize_candidate(
                     tcx.mk_existential_predicates(iter)
                 });
                 let source_trait = tcx.mk_dynamic(existential_predicates, r_b);
+
+                // Require that the traits involved in this upcast are **equal**;
+                // only the **lifetime bound** is changed.
+                //
+                // FIXME: This condition is arguably too strong -- it
+                // would suffice for the source trait to be a
+                // *subtype* of the target trait. In particular
+                // changing from something like `for<'a, 'b> Foo<'a,
+                // 'b>` to `for<'a> Foo<'a, 'a>` should be
+                // permitted. And, indeed, in the in commit
+                // 904a0bde93f0348f69914ee90b1f8b6e4e0d7cbc, this
+                // condition was loosened. However, when the leak check was added
+                // back, using subtype here actually guies the coercion code in
+                // such a way that it accepts `old-lub-glb-object.rs`. This is probably
+                // a good thing, but I've modified this to `.eq` because I want
+                // to continue rejecting that test (as we have done for quite some time)
+                // before we are firmly comfortable with what our behavior
+                // should be there. -nikomatsakis
                 let InferOk { obligations, .. } = self.infcx
                     .at(&obligation.cause, obligation.param_env)
-                    .sup(target, source_trait)
+                    .eq(target, source_trait) // FIXME -- see below
                     .map_err(|_| Unimplemented)?;
                 nested.extend(obligations);
 
index 3e95a7111e0cd35fd086c158a25ce49e4f40e0f5..dcd604a5157e26b39d35cfa9ea4541cafeae79bc 100644 (file)
@@ -1,9 +1,5 @@
 // Test that we give a note when the old LUB/GLB algorithm would have
 // succeeded but the new code (which is stricter) gives an error.
-//
-// compile-pass
-//
-// TODO -- why does this test pass?
 
 trait Foo<T, U> { }
 
@@ -13,7 +9,7 @@ fn foo(
 ) {
     let z = match 22 {
         0 => x,
-        _ => y,
+        _ => y, //~ ERROR match arms have incompatible types
     };
 }
 
diff --git a/src/test/ui/lub-glb/old-lub-glb-object.stderr b/src/test/ui/lub-glb/old-lub-glb-object.stderr
new file mode 100644 (file)
index 0000000..056f913
--- /dev/null
@@ -0,0 +1,18 @@
+error[E0308]: match arms have incompatible types
+  --> $DIR/old-lub-glb-object.rs:12:14
+   |
+LL |       let z = match 22 {
+   |  _____________-
+LL | |         0 => x,
+   | |              - this is found to be of type `&dyn for<'a, 'b> Foo<&'a u8, &'b u8>`
+LL | |         _ => y, //~ ERROR match arms have incompatible types
+   | |              ^ expected bound lifetime parameter 'a, found concrete lifetime
+LL | |     };
+   | |_____- `match` arms have incompatible types
+   |
+   = note: expected type `&dyn for<'a, 'b> Foo<&'a u8, &'b u8>`
+              found type `&dyn for<'a> Foo<&'a u8, &'a u8>`
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0308`.