From a85eb3d9df9f845b3ee166c8fa270efe20b4c82c Mon Sep 17 00:00:00 2001 From: Oli Scherer Date: Thu, 28 Jul 2022 15:22:02 +0000 Subject: [PATCH] Revert "Rollup merge of #97346 - JohnTitor:remove-back-compat-hacks, r=oli-obk" This reverts commit c703d11dccb4a895c7aead3b2fcd8cea8c483184, reversing changes made to 64eb9ab869bc3f9ef3645302fbf22e706eea16cf. --- .../rustc_infer/src/infer/opaque_types.rs | 14 ++++++----- .../src/traits/project.rs | 18 ++++++++++--- src/test/ui/impl-trait/issues/issue-86800.rs | 9 ++++++- .../ui/impl-trait/issues/issue-86800.stderr | 25 +++++++++++++------ .../ui/impl-trait/nested-return-type2-tait.rs | 10 +++++--- .../nested-return-type2-tait.stderr | 16 ------------ .../impl-trait/nested-return-type2-tait2.rs | 2 +- .../nested-return-type2-tait2.stderr | 8 +++--- .../impl-trait/nested-return-type2-tait3.rs | 2 +- .../nested-return-type2-tait3.stderr | 8 +++--- src/test/ui/impl-trait/nested-return-type2.rs | 8 ++++-- .../ui/impl-trait/nested-return-type2.stderr | 16 ------------ 12 files changed, 69 insertions(+), 67 deletions(-) delete mode 100644 src/test/ui/impl-trait/nested-return-type2-tait.stderr delete mode 100644 src/test/ui/impl-trait/nested-return-type2.stderr diff --git a/compiler/rustc_infer/src/infer/opaque_types.rs b/compiler/rustc_infer/src/infer/opaque_types.rs index a1c7b70bd9cdf..e579afbf38954 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>( &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 9de4d3a646cb3..ad5817d2716e8 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 19edeaffc496f..351243c6727da 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 = Result; type TransactionFuture<'__, O> = impl '__ + Future>; -//~^ 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 787aecc5b84bf..135d06d44adae 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>; - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - | - = 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 a2a49c5535d3d..42613d5ccd9a4 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> 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 { - //~^ 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 1079a86ce9e73..0000000000000 --- 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 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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> 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 fcc077ec18ece..af8e066305471 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; // 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 847b940008531..fe1ae4fcb08b1 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> 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 665c7a8cab91f..74fd8a9dda0bf 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; // 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 7b7f06b8e13e1..c0695d627eb6d 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> 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 279641a46c3d0..39928d543e15d 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> 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 { - //~^ 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 f28a084af89a4..0000000000000 --- 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 { - | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ 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> Trait for F { - | ^^^^^ ^ - -error: aborting due to previous error - -For more information about this error, try `rustc --explain E0277`.