Skip to content

Commit

Permalink
Auto merge of #99860 - oli-obk:revert_97346, r=pnkfelix
Browse files Browse the repository at this point in the history
Revert "Rollup merge of #97346 - JohnTitor:remove-back-compat-hacks, …

…r=oli-obk"

This reverts commit c703d11, reversing
changes made to 64eb9ab.

it didn't apply cleanly, so now it works the same for RPIT and for TAIT instead of just working for RPIT, but we should keep those in sync anyway. It also exposed a TAIT bug (see the feature gated test that now ICEs).

r? `@pnkfelix`

fixes #99536
  • Loading branch information
bors committed Aug 18, 2022
2 parents bb99e6f + a85eb3d commit 8064a49
Show file tree
Hide file tree
Showing 12 changed files with 69 additions and 67 deletions.
14 changes: 8 additions & 6 deletions compiler/rustc_infer/src/infer/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,23 +40,25 @@ 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| {
def_id
.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,
Expand Down
18 changes: 14 additions & 4 deletions compiler/rustc_trait_selection/src/traits/project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 8 additions & 1 deletion src/test/ui/impl-trait/issues/issue-86800.rs
Original file line number Diff line number Diff line change
@@ -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;

Expand All @@ -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,
Expand Down
25 changes: 17 additions & 8 deletions src/test/ui/impl-trait/issues/issue-86800.stderr
Original file line number Diff line number Diff line change
@@ -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
10 changes: 6 additions & 4 deletions src/test/ui/impl-trait/nested-return-type2-tait.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#![feature(type_alias_impl_trait)]

// check-pass

trait Duh {}

impl Duh for i32 {}
Expand All @@ -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
}

Expand Down
16 changes: 0 additions & 16 deletions src/test/ui/impl-trait/nested-return-type2-tait.stderr

This file was deleted.

2 changes: 1 addition & 1 deletion src/test/ui/impl-trait/nested-return-type2-tait2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/impl-trait/nested-return-type2-tait2.stderr
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/impl-trait/nested-return-type2-tait3.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
8 changes: 4 additions & 4 deletions src/test/ui/impl-trait/nested-return-type2-tait3.stderr
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down
8 changes: 6 additions & 2 deletions src/test/ui/impl-trait/nested-return-type2.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
// check-pass

trait Duh {}

impl Duh for i32 {}
Expand All @@ -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() {
}
16 changes: 0 additions & 16 deletions src/test/ui/impl-trait/nested-return-type2.stderr

This file was deleted.

0 comments on commit 8064a49

Please sign in to comment.