Revert "Rollup merge of #97346 - JohnTitor:remove-back-compat-hacks, r=oli-obk"
This reverts commitc703d11dcc
, reversing changes made to64eb9ab869
.
This commit is contained in:
parent
05e678ccca
commit
a85eb3d9df
@ -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 @@ pub fn replace_opaque_types_with_inference_vars(
|
||||
.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,
|
||||
|
@ -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)
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
|
@ -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`.
|
@ -24,8 +24,8 @@ impl<R: Duh, F: FnMut() -> R> Trait for F {
|
||||
// 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() {
|
||||
|
@ -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 {
|
||||
|
@ -23,8 +23,8 @@ impl<R: Duh, F: FnMut() -> R> Trait for F {
|
||||
// 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() {
|
||||
|
@ -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 {
|
||||
|
@ -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() {
|
||||
}
|
||||
|
@ -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`.
|
Loading…
Reference in New Issue
Block a user