about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2022-07-28 15:22:02 +0000
committerOli Scherer <git-spam-no-reply9815368754983@oli-obk.de>2022-07-28 15:22:02 +0000
commita85eb3d9df9f845b3ee166c8fa270efe20b4c82c (patch)
treeacc41199c423410398d79d2cb642509a48457050
parent05e678ccca974a8d0c26991083fb4cf8fff84e74 (diff)
downloadrust-a85eb3d9df9f845b3ee166c8fa270efe20b4c82c.tar.gz
rust-a85eb3d9df9f845b3ee166c8fa270efe20b4c82c.zip
Revert "Rollup merge of #97346 - JohnTitor:remove-back-compat-hacks, r=oli-obk"
This reverts commit c703d11dccb4a895c7aead3b2fcd8cea8c483184, reversing
changes made to 64eb9ab869bc3f9ef3645302fbf22e706eea16cf.
-rw-r--r--compiler/rustc_infer/src/infer/opaque_types.rs14
-rw-r--r--compiler/rustc_trait_selection/src/traits/project.rs18
-rw-r--r--src/test/ui/impl-trait/issues/issue-86800.rs9
-rw-r--r--src/test/ui/impl-trait/issues/issue-86800.stderr25
-rw-r--r--src/test/ui/impl-trait/nested-return-type2-tait.rs10
-rw-r--r--src/test/ui/impl-trait/nested-return-type2-tait.stderr16
-rw-r--r--src/test/ui/impl-trait/nested-return-type2-tait2.rs2
-rw-r--r--src/test/ui/impl-trait/nested-return-type2-tait2.stderr8
-rw-r--r--src/test/ui/impl-trait/nested-return-type2-tait3.rs2
-rw-r--r--src/test/ui/impl-trait/nested-return-type2-tait3.stderr8
-rw-r--r--src/test/ui/impl-trait/nested-return-type2.rs8
-rw-r--r--src/test/ui/impl-trait/nested-return-type2.stderr16
12 files changed, 69 insertions, 67 deletions
diff --git a/compiler/rustc_infer/src/infer/opaque_types.rs b/compiler/rustc_infer/src/infer/opaque_types.rs
index a1c7b70bd9c..e579afbf389 100644
--- a/compiler/rustc_infer/src/infer/opaque_types.rs
+++ b/compiler/rustc_infer/src/infer/opaque_types.rs
@@ -40,15 +40,17 @@ pub struct OpaqueTypeDecl<'tcx> {
 }
 
 impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
-    pub fn replace_opaque_types_with_inference_vars(
+    /// This is a backwards compatibility hack to prevent breaking changes from
+    /// lazy TAIT around RPIT handling.
+    pub fn replace_opaque_types_with_inference_vars<T: TypeFoldable<'tcx>>(
         &self,
-        ty: Ty<'tcx>,
+        value: T,
         body_id: HirId,
         span: Span,
         param_env: ty::ParamEnv<'tcx>,
-    ) -> InferOk<'tcx, Ty<'tcx>> {
-        if !ty.has_opaque_types() {
-            return InferOk { value: ty, obligations: vec![] };
+    ) -> InferOk<'tcx, T> {
+        if !value.has_opaque_types() {
+            return InferOk { value, obligations: vec![] };
         }
         let mut obligations = vec![];
         let replace_opaque_type = |def_id: DefId| {
@@ -56,7 +58,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
                 .as_local()
                 .map_or(false, |def_id| self.opaque_type_origin(def_id, span).is_some())
         };
-        let value = ty.fold_with(&mut ty::fold::BottomUpFolder {
+        let value = value.fold_with(&mut ty::fold::BottomUpFolder {
             tcx: self.tcx,
             lt_op: |lt| lt,
             ct_op: |ct| ct,
diff --git a/compiler/rustc_trait_selection/src/traits/project.rs b/compiler/rustc_trait_selection/src/traits/project.rs
index 9de4d3a646c..ad5817d2716 100644
--- a/compiler/rustc_trait_selection/src/traits/project.rs
+++ b/compiler/rustc_trait_selection/src/traits/project.rs
@@ -252,10 +252,20 @@ fn project_and_unify_type<'cx, 'tcx>(
         Err(InProgress) => return ProjectAndUnifyResult::Recursive,
     };
     debug!(?normalized, ?obligations, "project_and_unify_type result");
-    match infcx
-        .at(&obligation.cause, obligation.param_env)
-        .eq(normalized, obligation.predicate.term)
-    {
+    let actual = obligation.predicate.term;
+    // For an example where this is neccessary see src/test/ui/impl-trait/nested-return-type2.rs
+    // This allows users to omit re-mentioning all bounds on an associated type and just use an
+    // `impl Trait` for the assoc type to add more bounds.
+    let InferOk { value: actual, obligations: new } =
+        selcx.infcx().replace_opaque_types_with_inference_vars(
+            actual,
+            obligation.cause.body_id,
+            obligation.cause.span,
+            obligation.param_env,
+        );
+    obligations.extend(new);
+
+    match infcx.at(&obligation.cause, obligation.param_env).eq(normalized, actual) {
         Ok(InferOk { obligations: inferred_obligations, value: () }) => {
             obligations.extend(inferred_obligations);
             ProjectAndUnifyResult::Holds(obligations)
diff --git a/src/test/ui/impl-trait/issues/issue-86800.rs b/src/test/ui/impl-trait/issues/issue-86800.rs
index 19edeaffc49..351243c6727 100644
--- a/src/test/ui/impl-trait/issues/issue-86800.rs
+++ b/src/test/ui/impl-trait/issues/issue-86800.rs
@@ -1,6 +1,14 @@
 #![feature(type_alias_impl_trait)]
 
 // edition:2021
+// unset-rustc-env:RUST_BACKTRACE
+// compile-flags:-Z treat-err-as-bug=1
+// error-pattern:stack backtrace:
+// failure-status:101
+// normalize-stderr-test "note: .*" -> ""
+// normalize-stderr-test "thread 'rustc' .*" -> ""
+// normalize-stderr-test " +[0-9]+:.*\n" -> ""
+// normalize-stderr-test " +at .*\n" -> ""
 
 use std::future::Future;
 
@@ -23,7 +31,6 @@ struct Context {
 type TransactionResult<O> = Result<O, ()>;
 
 type TransactionFuture<'__, O> = impl '__ + Future<Output = TransactionResult<O>>;
-//~^ ERROR unconstrained opaque type
 
 fn execute_transaction_fut<'f, F, O>(
     f: F,
diff --git a/src/test/ui/impl-trait/issues/issue-86800.stderr b/src/test/ui/impl-trait/issues/issue-86800.stderr
index 787aecc5b84..135d06d44ad 100644
--- a/src/test/ui/impl-trait/issues/issue-86800.stderr
+++ b/src/test/ui/impl-trait/issues/issue-86800.stderr
@@ -1,10 +1,19 @@
-error: unconstrained opaque type
-  --> $DIR/issue-86800.rs:25:34
-   |
-LL | type TransactionFuture<'__, O> = impl '__ + Future<Output = TransactionResult<O>>;
-   |                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-   |
-   = note: `TransactionFuture` must be used in combination with a concrete type within the same module
 
-error: aborting due to previous error
+stack backtrace:
 
+error: internal compiler error: unexpected panic
+
+
+
+
+
+
+
+
+
+query stack during panic:
+#0 [mir_borrowck] borrow-checking `execute_transaction_fut`
+#1 [type_of] computing type of `TransactionFuture::{opaque#0}`
+#2 [check_mod_item_types] checking item types in top-level module
+#3 [analysis] running analysis passes on this crate
+end of query stack
diff --git a/src/test/ui/impl-trait/nested-return-type2-tait.rs b/src/test/ui/impl-trait/nested-return-type2-tait.rs
index a2a49c5535d..42613d5ccd9 100644
--- a/src/test/ui/impl-trait/nested-return-type2-tait.rs
+++ b/src/test/ui/impl-trait/nested-return-type2-tait.rs
@@ -1,5 +1,7 @@
 #![feature(type_alias_impl_trait)]
 
+// check-pass
+
 trait Duh {}
 
 impl Duh for i32 {}
@@ -17,13 +19,13 @@ impl<R: Duh, F: FnMut() -> R> Trait for F {
 
 type Sendable = impl Send;
 
-// The `Sendable` here is then later compared against the inference var
-// created, causing the inference var to be set to `Sendable` instead of
+// The `Sendable` here is converted to an inference var and then later compared
+// against the inference var created, causing the inference var to be set to
+// the hidden type of `Sendable` instead of
 // the hidden type. We already have obligations registered on the inference
 // var to make it uphold the `: Duh` bound on `Trait::Assoc`. The opaque
-// type does not implement `Duh`, even if its hidden type does. So we error out.
+// type does not implement `Duh`, but if its hidden type does.
 fn foo() -> impl Trait<Assoc = Sendable> {
-    //~^ ERROR `Sendable: Duh` is not satisfied
     || 42
 }
 
diff --git a/src/test/ui/impl-trait/nested-return-type2-tait.stderr b/src/test/ui/impl-trait/nested-return-type2-tait.stderr
deleted file mode 100644
index 1079a86ce9e..00000000000
--- a/src/test/ui/impl-trait/nested-return-type2-tait.stderr
+++ /dev/null
@@ -1,16 +0,0 @@
-error[E0277]: the trait bound `Sendable: Duh` is not satisfied
-  --> $DIR/nested-return-type2-tait.rs:25:13
-   |
-LL | fn foo() -> impl Trait<Assoc = Sendable> {
-   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Duh` is not implemented for `Sendable`
-   |
-   = help: the trait `Duh` is implemented for `i32`
-note: required because of the requirements on the impl of `Trait` for `[closure@$DIR/nested-return-type2-tait.rs:27:5: 27:7]`
-  --> $DIR/nested-return-type2-tait.rs:14:31
-   |
-LL | impl<R: Duh, F: FnMut() -> R> Trait for F {
-   |                               ^^^^^     ^
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0277`.
diff --git a/src/test/ui/impl-trait/nested-return-type2-tait2.rs b/src/test/ui/impl-trait/nested-return-type2-tait2.rs
index fcc077ec18e..af8e0663054 100644
--- a/src/test/ui/impl-trait/nested-return-type2-tait2.rs
+++ b/src/test/ui/impl-trait/nested-return-type2-tait2.rs
@@ -24,8 +24,8 @@ type Traitable = impl Trait<Assoc = Sendable>;
 // var to make it uphold the `: Duh` bound on `Trait::Assoc`. The opaque
 // type does not implement `Duh`, even if its hidden type does. So we error out.
 fn foo() -> Traitable {
-    //~^ ERROR `Sendable: Duh` is not satisfied
     || 42
+    //~^ ERROR `Sendable: Duh` is not satisfied
 }
 
 fn main() {
diff --git a/src/test/ui/impl-trait/nested-return-type2-tait2.stderr b/src/test/ui/impl-trait/nested-return-type2-tait2.stderr
index 847b9400085..fe1ae4fcb08 100644
--- a/src/test/ui/impl-trait/nested-return-type2-tait2.stderr
+++ b/src/test/ui/impl-trait/nested-return-type2-tait2.stderr
@@ -1,11 +1,11 @@
 error[E0277]: the trait bound `Sendable: Duh` is not satisfied
-  --> $DIR/nested-return-type2-tait2.rs:26:13
+  --> $DIR/nested-return-type2-tait2.rs:27:5
    |
-LL | fn foo() -> Traitable {
-   |             ^^^^^^^^^ the trait `Duh` is not implemented for `Sendable`
+LL |     || 42
+   |     ^^^^^ the trait `Duh` is not implemented for `Sendable`
    |
    = help: the trait `Duh` is implemented for `i32`
-note: required because of the requirements on the impl of `Trait` for `[closure@$DIR/nested-return-type2-tait2.rs:28:5: 28:7]`
+note: required because of the requirements on the impl of `Trait` for `[closure@$DIR/nested-return-type2-tait2.rs:27:5: 27:7]`
   --> $DIR/nested-return-type2-tait2.rs:14:31
    |
 LL | impl<R: Duh, F: FnMut() -> R> Trait for F {
diff --git a/src/test/ui/impl-trait/nested-return-type2-tait3.rs b/src/test/ui/impl-trait/nested-return-type2-tait3.rs
index 665c7a8cab9..74fd8a9dda0 100644
--- a/src/test/ui/impl-trait/nested-return-type2-tait3.rs
+++ b/src/test/ui/impl-trait/nested-return-type2-tait3.rs
@@ -23,8 +23,8 @@ type Traitable = impl Trait<Assoc = impl Send>;
 // var to make it uphold the `: Duh` bound on `Trait::Assoc`. The opaque
 // type does not implement `Duh`, even if its hidden type does. So we error out.
 fn foo() -> Traitable {
-    //~^ ERROR `impl Send: Duh` is not satisfied
     || 42
+    //~^ ERROR `impl Send: Duh` is not satisfied
 }
 
 fn main() {
diff --git a/src/test/ui/impl-trait/nested-return-type2-tait3.stderr b/src/test/ui/impl-trait/nested-return-type2-tait3.stderr
index 7b7f06b8e13..c0695d627eb 100644
--- a/src/test/ui/impl-trait/nested-return-type2-tait3.stderr
+++ b/src/test/ui/impl-trait/nested-return-type2-tait3.stderr
@@ -1,11 +1,11 @@
 error[E0277]: the trait bound `impl Send: Duh` is not satisfied
-  --> $DIR/nested-return-type2-tait3.rs:25:13
+  --> $DIR/nested-return-type2-tait3.rs:26:5
    |
-LL | fn foo() -> Traitable {
-   |             ^^^^^^^^^ the trait `Duh` is not implemented for `impl Send`
+LL |     || 42
+   |     ^^^^^ the trait `Duh` is not implemented for `impl Send`
    |
    = help: the trait `Duh` is implemented for `i32`
-note: required because of the requirements on the impl of `Trait` for `[closure@$DIR/nested-return-type2-tait3.rs:27:5: 27:7]`
+note: required because of the requirements on the impl of `Trait` for `[closure@$DIR/nested-return-type2-tait3.rs:26:5: 26:7]`
   --> $DIR/nested-return-type2-tait3.rs:14:31
    |
 LL | impl<R: Duh, F: FnMut() -> R> Trait for F {
diff --git a/src/test/ui/impl-trait/nested-return-type2.rs b/src/test/ui/impl-trait/nested-return-type2.rs
index 279641a46c3..39928d543e1 100644
--- a/src/test/ui/impl-trait/nested-return-type2.rs
+++ b/src/test/ui/impl-trait/nested-return-type2.rs
@@ -1,3 +1,5 @@
+// check-pass
+
 trait Duh {}
 
 impl Duh for i32 {}
@@ -18,9 +20,11 @@ impl<R: Duh, F: FnMut() -> R> Trait for F {
 // the hidden type. We already have obligations registered on the inference
 // var to make it uphold the `: Duh` bound on `Trait::Assoc`. The opaque
 // type does not implement `Duh`, even if its hidden type does.
+// Lazy TAIT would error out, but we inserted a hack to make it work again,
+// keeping backwards compatibility.
 fn foo() -> impl Trait<Assoc = impl Send> {
-    //~^ ERROR `impl Send: Duh` is not satisfied
     || 42
 }
 
-fn main() {}
+fn main() {
+}
diff --git a/src/test/ui/impl-trait/nested-return-type2.stderr b/src/test/ui/impl-trait/nested-return-type2.stderr
deleted file mode 100644
index f28a084af89..00000000000
--- a/src/test/ui/impl-trait/nested-return-type2.stderr
+++ /dev/null
@@ -1,16 +0,0 @@
-error[E0277]: the trait bound `impl Send: Duh` is not satisfied
-  --> $DIR/nested-return-type2.rs:21:13
-   |
-LL | fn foo() -> impl Trait<Assoc = impl Send> {
-   |             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Duh` is not implemented for `impl Send`
-   |
-   = help: the trait `Duh` is implemented for `i32`
-note: required because of the requirements on the impl of `Trait` for `[closure@$DIR/nested-return-type2.rs:23:5: 23:7]`
-  --> $DIR/nested-return-type2.rs:12:31
-   |
-LL | impl<R: Duh, F: FnMut() -> R> Trait for F {
-   |                               ^^^^^     ^
-
-error: aborting due to previous error
-
-For more information about this error, try `rustc --explain E0277`.