Skip to content

Commit c703d11

Browse files
authored
Rollup merge of rust-lang#97346 - JohnTitor:remove-back-compat-hacks, r=oli-obk
Remove a back-compat hack on lazy TAIT This PR's motivation is here: rust-lang#72614 (comment) ~~But removing a hack doesn't seem to reject the code on the issue, there're some more hacks?~~ r? ``@oli-obk``
2 parents 64eb9ab + c24f063 commit c703d11

File tree

4 files changed

+28
-31
lines changed

4 files changed

+28
-31
lines changed

compiler/rustc_infer/src/infer/opaque_types.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -39,21 +39,19 @@ pub struct OpaqueTypeDecl<'tcx> {
3939
}
4040

4141
impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
42-
/// This is a backwards compatibility hack to prevent breaking changes from
43-
/// lazy TAIT around RPIT handling.
44-
pub fn replace_opaque_types_with_inference_vars<T: TypeFoldable<'tcx>>(
42+
pub fn replace_opaque_types_with_inference_vars(
4543
&self,
46-
value: T,
44+
ty: Ty<'tcx>,
4745
body_id: HirId,
4846
span: Span,
4947
code: ObligationCauseCode<'tcx>,
5048
param_env: ty::ParamEnv<'tcx>,
51-
) -> InferOk<'tcx, T> {
52-
if !value.has_opaque_types() {
53-
return InferOk { value, obligations: vec![] };
49+
) -> InferOk<'tcx, Ty<'tcx>> {
50+
if !ty.has_opaque_types() {
51+
return InferOk { value: ty, obligations: vec![] };
5452
}
5553
let mut obligations = vec![];
56-
let value = value.fold_with(&mut ty::fold::BottomUpFolder {
54+
let value = ty.fold_with(&mut ty::fold::BottomUpFolder {
5755
tcx: self.tcx,
5856
lt_op: |lt| lt,
5957
ct_op: |ct| ct,

compiler/rustc_trait_selection/src/traits/project.rs

+4-17
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ use rustc_hir::def::DefKind;
2828
use rustc_hir::def_id::DefId;
2929
use rustc_hir::lang_items::LangItem;
3030
use rustc_infer::infer::resolve::OpportunisticRegionResolver;
31-
use rustc_infer::traits::ObligationCauseCode;
3231
use rustc_middle::traits::select::OverflowError;
3332
use rustc_middle::ty::fold::{MaxUniverse, TypeFoldable, TypeFolder, TypeSuperFoldable};
3433
use rustc_middle::ty::subst::Subst;
@@ -252,22 +251,10 @@ fn project_and_unify_type<'cx, 'tcx>(
252251
Err(InProgress) => return ProjectAndUnifyResult::Recursive,
253252
};
254253
debug!(?normalized, ?obligations, "project_and_unify_type result");
255-
let actual = obligation.predicate.term;
256-
// HACK: lazy TAIT would regress src/test/ui/impl-trait/nested-return-type2.rs, so we add
257-
// a back-compat hack hat converts the RPITs into inference vars, just like they were before
258-
// lazy TAIT.
259-
// This does not affect TAITs in general, as tested in the nested-return-type-tait* tests.
260-
let InferOk { value: actual, obligations: new } =
261-
selcx.infcx().replace_opaque_types_with_inference_vars(
262-
actual,
263-
obligation.cause.body_id,
264-
obligation.cause.span,
265-
ObligationCauseCode::MiscObligation,
266-
obligation.param_env,
267-
);
268-
obligations.extend(new);
269-
270-
match infcx.at(&obligation.cause, obligation.param_env).eq(normalized, actual) {
254+
match infcx
255+
.at(&obligation.cause, obligation.param_env)
256+
.eq(normalized, obligation.predicate.term)
257+
{
271258
Ok(InferOk { obligations: inferred_obligations, value: () }) => {
272259
obligations.extend(inferred_obligations);
273260
ProjectAndUnifyResult::Holds(obligations)

src/test/ui/impl-trait/nested-return-type2.rs

+2-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// check-pass
2-
31
trait Duh {}
42

53
impl Duh for i32 {}
@@ -20,11 +18,9 @@ impl<R: Duh, F: FnMut() -> R> Trait for F {
2018
// the hidden type. We already have obligations registered on the inference
2119
// var to make it uphold the `: Duh` bound on `Trait::Assoc`. The opaque
2220
// type does not implement `Duh`, even if its hidden type does.
23-
// Lazy TAIT would error out, but we inserted a hack to make it work again,
24-
// keeping backwards compatibility.
2521
fn foo() -> impl Trait<Assoc = impl Send> {
22+
//~^ ERROR `impl Send: Duh` is not satisfied
2623
|| 42
2724
}
2825

29-
fn main() {
30-
}
26+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
error[E0277]: the trait bound `impl Send: Duh` is not satisfied
2+
--> $DIR/nested-return-type2.rs:21:13
3+
|
4+
LL | fn foo() -> impl Trait<Assoc = impl Send> {
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the trait `Duh` is not implemented for `impl Send`
6+
|
7+
= help: the trait `Duh` is implemented for `i32`
8+
note: required because of the requirements on the impl of `Trait` for `[closure@$DIR/nested-return-type2.rs:23:5: 23:10]`
9+
--> $DIR/nested-return-type2.rs:12:31
10+
|
11+
LL | impl<R: Duh, F: FnMut() -> R> Trait for F {
12+
| ^^^^^ ^
13+
14+
error: aborting due to previous error
15+
16+
For more information about this error, try `rustc --explain E0277`.

0 commit comments

Comments
 (0)