]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #62542 - Centril:rollup-5mpb8tu, r=Centril
authorbors <bors@rust-lang.org>
Tue, 9 Jul 2019 22:02:58 +0000 (22:02 +0000)
committerbors <bors@rust-lang.org>
Tue, 9 Jul 2019 22:02:58 +0000 (22:02 +0000)
Rollup of 9 pull requests

Successful merges:

 - #62417 (Fix ICEs when `Self` is used in type aliases)
 - #62450 (Raise the default recursion limit to 128)
 - #62470 (Prevent shrinking of "crate select" element on Firefox)
 - #62515 (cli: make help output for -l and -L consistent)
 - #62520 (Regression test for issue 42574.)
 - #62526 (normalize use of backticks in compiler messages for libsyntax/feature_gate.rs)
 - #62527 (clarify that debug_assert does not completely omits the code)
 - #62535 (ci: Configure $CI_JOB_NAME correctly)
 - #62541 (Add spastorino for rustc-guide toolstate)

Failed merges:

r? @ghost

src/librustc/infer/opaque_types/mod.rs
src/librustc_typeck/check/mod.rs
src/test/ui/async-await/bound-normalization.rs [new file with mode: 0644]
src/test/ui/impl-trait/bound-normalization-fail.rs [new file with mode: 0644]
src/test/ui/impl-trait/bound-normalization-fail.stderr [new file with mode: 0644]
src/test/ui/impl-trait/bound-normalization-pass.rs [new file with mode: 0644]
src/test/ui/impl-trait/bound-normalization-pass.stderr [new file with mode: 0644]

index f3dc4d3f72a9b37129c46cbfbcdffc82b4f2f1d7..5acc3fd2fbcfd0d6db87ad37db97765322291eef 100644 (file)
@@ -1111,6 +1111,12 @@ fn fold_opaque_ty(
         let predicates_of = tcx.predicates_of(def_id);
         debug!("instantiate_opaque_types: predicates={:#?}", predicates_of,);
         let bounds = predicates_of.instantiate(tcx, substs);
+
+        let param_env = tcx.param_env(def_id);
+        let InferOk { value: bounds, obligations } =
+            infcx.partially_normalize_associated_types_in(span, self.body_id, param_env, &bounds);
+        self.obligations.extend(obligations);
+
         debug!("instantiate_opaque_types: bounds={:?}", bounds);
 
         let required_region_bounds = tcx.required_region_bounds(ty, bounds.predicates.clone());
index d8c73b2be8258d7416ebd0aea69facb56cede685..4acba6d38fa25e993d3f5e20b9f033e4c26eea3c 100644 (file)
@@ -1065,6 +1065,7 @@ fn check_fn<'a, 'tcx>(
         &declared_ret_ty,
         decl.output.span(),
     );
+    debug!("check_fn: declared_ret_ty: {}, revealed_ret_ty: {}", declared_ret_ty, revealed_ret_ty);
     fcx.ret_coercion = Some(RefCell::new(CoerceMany::new(revealed_ret_ty)));
     fn_sig = fcx.tcx.mk_fn_sig(
         fn_sig.inputs().iter().cloned(),
diff --git a/src/test/ui/async-await/bound-normalization.rs b/src/test/ui/async-await/bound-normalization.rs
new file mode 100644 (file)
index 0000000..8026350
--- /dev/null
@@ -0,0 +1,16 @@
+// check-pass
+// edition:2018
+
+#![feature(async_await)]
+
+// See issue 60414
+
+trait Trait {
+    type Assoc;
+}
+
+async fn foo<T: Trait<Assoc=()>>() -> T::Assoc {
+    ()
+}
+
+fn main() {}
diff --git a/src/test/ui/impl-trait/bound-normalization-fail.rs b/src/test/ui/impl-trait/bound-normalization-fail.rs
new file mode 100644 (file)
index 0000000..476ae62
--- /dev/null
@@ -0,0 +1,53 @@
+// compile-fail
+// edition:2018
+
+#![feature(async_await)]
+#![feature(existential_type)]
+#![feature(impl_trait_in_bindings)]
+//~^ WARNING the feature `impl_trait_in_bindings` is incomplete
+
+// See issue 60414
+
+/////////////////////////////////////////////
+// Reduction to `impl Trait`
+
+struct Foo<T>(T);
+
+trait FooLike { type Output; }
+
+impl<T> FooLike for Foo<T> {
+    type Output = T;
+}
+
+mod impl_trait {
+    use super::*;
+
+    trait Trait {
+        type Assoc;
+    }
+
+    /// `T::Assoc` can't be normalized any further here.
+    fn foo_fail<T: Trait>() -> impl FooLike<Output=T::Assoc> {
+        //~^ ERROR: type mismatch
+        Foo(())
+    }
+}
+
+/////////////////////////////////////////////
+// Same with lifetimes in the trait
+
+mod lifetimes {
+    use super::*;
+
+    trait Trait<'a> {
+        type Assoc;
+    }
+
+    /// Missing bound constraining `Assoc`, `T::Assoc` can't be normalized further.
+    fn foo2_fail<'a, T: Trait<'a>>() -> impl FooLike<Output=T::Assoc> {
+        //~^ ERROR: type mismatch
+        Foo(())
+    }
+}
+
+fn main() {}
diff --git a/src/test/ui/impl-trait/bound-normalization-fail.stderr b/src/test/ui/impl-trait/bound-normalization-fail.stderr
new file mode 100644 (file)
index 0000000..fa2dd20
--- /dev/null
@@ -0,0 +1,29 @@
+warning: the feature `impl_trait_in_bindings` is incomplete and may cause the compiler to crash
+  --> $DIR/bound-normalization-fail.rs:6:12
+   |
+LL | #![feature(impl_trait_in_bindings)]
+   |            ^^^^^^^^^^^^^^^^^^^^^^
+
+error[E0271]: type mismatch resolving `<Foo<()> as FooLike>::Output == <T as impl_trait::Trait>::Assoc`
+  --> $DIR/bound-normalization-fail.rs:30:32
+   |
+LL |     fn foo_fail<T: Trait>() -> impl FooLike<Output=T::Assoc> {
+   |                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected (), found associated type
+   |
+   = note: expected type `()`
+              found type `<T as impl_trait::Trait>::Assoc`
+   = note: the return type of a function must have a statically known size
+
+error[E0271]: type mismatch resolving `<Foo<()> as FooLike>::Output == <T as lifetimes::Trait<'static>>::Assoc`
+  --> $DIR/bound-normalization-fail.rs:47:41
+   |
+LL |     fn foo2_fail<'a, T: Trait<'a>>() -> impl FooLike<Output=T::Assoc> {
+   |                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected (), found associated type
+   |
+   = note: expected type `()`
+              found type `<T as lifetimes::Trait<'static>>::Assoc`
+   = note: the return type of a function must have a statically known size
+
+error: aborting due to 2 previous errors
+
+For more information about this error, try `rustc --explain E0271`.
diff --git a/src/test/ui/impl-trait/bound-normalization-pass.rs b/src/test/ui/impl-trait/bound-normalization-pass.rs
new file mode 100644 (file)
index 0000000..3fdd7c0
--- /dev/null
@@ -0,0 +1,109 @@
+// check-pass
+// edition:2018
+
+#![feature(async_await)]
+#![feature(existential_type)]
+#![feature(impl_trait_in_bindings)]
+//~^ WARNING the feature `impl_trait_in_bindings` is incomplete
+
+// See issue 60414
+
+/////////////////////////////////////////////
+// Reduction to `impl Trait`
+
+struct Foo<T>(T);
+
+trait FooLike { type Output; }
+
+impl<T> FooLike for Foo<T> {
+    type Output = T;
+}
+
+mod impl_trait {
+    use super::*;
+
+    trait Trait {
+        type Assoc;
+    }
+
+    /// `T::Assoc` should be normalized to `()` here.
+    fn foo_pass<T: Trait<Assoc=()>>() -> impl FooLike<Output=T::Assoc> {
+        Foo(())
+    }
+}
+
+/////////////////////////////////////////////
+// Same with lifetimes in the trait
+
+mod lifetimes {
+    use super::*;
+
+    trait Trait<'a> {
+        type Assoc;
+    }
+
+    /// Like above.
+    ///
+    /// FIXME(#51525) -- the shorter notation `T::Assoc` winds up referencing `'static` here
+    fn foo2_pass<'a, T: Trait<'a, Assoc=()> + 'a>(
+    ) -> impl FooLike<Output=<T as Trait<'a>>::Assoc> + 'a {
+        Foo(())
+    }
+
+    /// Normalization to type containing bound region.
+    ///
+    /// FIXME(#51525) -- the shorter notation `T::Assoc` winds up referencing `'static` here
+    fn foo2_pass2<'a, T: Trait<'a, Assoc=&'a ()> + 'a>(
+    ) -> impl FooLike<Output=<T as Trait<'a>>::Assoc> + 'a {
+        Foo(&())
+    }
+}
+
+/////////////////////////////////////////////
+// Reduction using `impl Trait` in bindings
+
+mod impl_trait_in_bindings {
+    struct Foo;
+
+    trait FooLike { type Output; }
+
+    impl FooLike for Foo {
+        type Output = u32;
+    }
+
+    trait Trait {
+        type Assoc;
+    }
+
+    fn foo<T: Trait<Assoc=u32>>() {
+        let _: impl FooLike<Output=T::Assoc> = Foo;
+    }
+}
+
+/////////////////////////////////////////////
+// The same applied to `existential type`s
+
+mod existential_types {
+    trait Implemented {
+        type Assoc;
+    }
+    impl<T> Implemented for T {
+        type Assoc = u8;
+    }
+
+    trait Trait {
+        type Out;
+    }
+
+    impl Trait for () {
+        type Out = u8;
+    }
+
+    existential type Ex: Trait<Out = <() as Implemented>::Assoc>;
+
+    fn define() -> Ex {
+        ()
+    }
+}
+
+fn main() {}
diff --git a/src/test/ui/impl-trait/bound-normalization-pass.stderr b/src/test/ui/impl-trait/bound-normalization-pass.stderr
new file mode 100644 (file)
index 0000000..c1b7fb2
--- /dev/null
@@ -0,0 +1,6 @@
+warning: the feature `impl_trait_in_bindings` is incomplete and may cause the compiler to crash
+  --> $DIR/bound-normalization-pass.rs:6:12
+   |
+LL | #![feature(impl_trait_in_bindings)]
+   |            ^^^^^^^^^^^^^^^^^^^^^^
+