Skip to content

Commit fd04250

Browse files
committed
Revert "Rollup merge of rust-lang#92006 - oli-obk:welcome_opaque_types_into_the_fold, r=nikomatsakis"
This reverts commit b45a819, reversing changes made to e045c79.
1 parent 38c22af commit fd04250

File tree

4 files changed

+80
-61
lines changed

4 files changed

+80
-61
lines changed

compiler/rustc_infer/src/infer/opaque_types.rs

+4-16
Original file line numberDiff line numberDiff line change
@@ -555,22 +555,6 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
555555
let predicate = predicate.subst(tcx, substs);
556556
debug!(?predicate);
557557

558-
let predicate = predicate.fold_with(&mut BottomUpFolder {
559-
tcx,
560-
ty_op: |ty| match *ty.kind() {
561-
// Replace all other mentions of the same opaque type with the hidden type,
562-
// as the bounds must hold on the hidden type after all.
563-
ty::Opaque(def_id2, substs2) if def_id == def_id2 && substs == substs2 => {
564-
ty_var
565-
}
566-
// Instantiate nested instances of `impl Trait`.
567-
ty::Opaque(..) => self.instantiate_opaque_types_in_map(ty),
568-
_ => ty,
569-
},
570-
lt_op: |lt| lt,
571-
ct_op: |ct| ct,
572-
});
573-
574558
// We can't normalize associated types from `rustc_infer`, but we can eagerly register inference variables for them.
575559
let predicate = predicate.fold_with(&mut BottomUpFolder {
576560
tcx,
@@ -595,6 +579,10 @@ impl<'a, 'tcx> Instantiator<'a, 'tcx> {
595579
return tcx.ty_error();
596580
}
597581
}
582+
// Change the predicate to refer to the type variable,
583+
// which will be the concrete type instead of the opaque type.
584+
// This also instantiates nested instances of `impl Trait`.
585+
let predicate = self.instantiate_opaque_types_in_map(predicate);
598586

599587
let cause =
600588
traits::ObligationCause::new(self.value_span, self.body_id, traits::OpaqueType);

compiler/rustc_trait_selection/src/traits/query/type_op/mod.rs

+19-42
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,7 @@ use crate::infer::canonical::{
44
use crate::infer::{InferCtxt, InferOk};
55
use crate::traits::query::Fallible;
66
use crate::traits::ObligationCause;
7-
use rustc_infer::infer::canonical::{Canonical, Certainty};
8-
use rustc_infer::traits::query::NoSolution;
9-
use rustc_infer::traits::PredicateObligations;
7+
use rustc_infer::infer::canonical::Canonical;
108
use rustc_middle::ty::fold::TypeFoldable;
119
use rustc_middle::ty::{ParamEnvAnd, TyCtxt};
1210
use std::fmt;
@@ -19,6 +17,7 @@ pub mod implied_outlives_bounds;
1917
pub mod normalize;
2018
pub mod outlives;
2119
pub mod prove_predicate;
20+
use self::prove_predicate::ProvePredicate;
2221
pub mod subtype;
2322

2423
pub use rustc_middle::traits::query::type_op::*;
@@ -81,14 +80,9 @@ pub trait QueryTypeOp<'tcx>: fmt::Debug + Copy + TypeFoldable<'tcx> + 'tcx {
8180
query_key: ParamEnvAnd<'tcx, Self>,
8281
infcx: &InferCtxt<'_, 'tcx>,
8382
output_query_region_constraints: &mut QueryRegionConstraints<'tcx>,
84-
) -> Fallible<(
85-
Self::QueryResponse,
86-
Option<Canonical<'tcx, ParamEnvAnd<'tcx, Self>>>,
87-
PredicateObligations<'tcx>,
88-
Certainty,
89-
)> {
83+
) -> Fallible<(Self::QueryResponse, Option<Canonical<'tcx, ParamEnvAnd<'tcx, Self>>>)> {
9084
if let Some(result) = QueryTypeOp::try_fast_path(infcx.tcx, &query_key) {
91-
return Ok((result, None, vec![], Certainty::Proven));
85+
return Ok((result, None));
9286
}
9387

9488
// FIXME(#33684) -- We need to use
@@ -110,7 +104,20 @@ pub trait QueryTypeOp<'tcx>: fmt::Debug + Copy + TypeFoldable<'tcx> + 'tcx {
110104
output_query_region_constraints,
111105
)?;
112106

113-
Ok((value, Some(canonical_self), obligations, canonical_result.value.certainty))
107+
// Typically, instantiating NLL query results does not
108+
// create obligations. However, in some cases there
109+
// are unresolved type variables, and unify them *can*
110+
// create obligations. In that case, we have to go
111+
// fulfill them. We do this via a (recursive) query.
112+
for obligation in obligations {
113+
let ((), _) = ProvePredicate::fully_perform_into(
114+
obligation.param_env.and(ProvePredicate::new(obligation.predicate)),
115+
infcx,
116+
output_query_region_constraints,
117+
)?;
118+
}
119+
120+
Ok((value, Some(canonical_self)))
114121
}
115122
}
116123

@@ -122,39 +129,9 @@ where
122129

123130
fn fully_perform(self, infcx: &InferCtxt<'_, 'tcx>) -> Fallible<TypeOpOutput<'tcx, Self>> {
124131
let mut region_constraints = QueryRegionConstraints::default();
125-
let (output, canonicalized_query, mut obligations, _) =
132+
let (output, canonicalized_query) =
126133
Q::fully_perform_into(self, infcx, &mut region_constraints)?;
127134

128-
// Typically, instantiating NLL query results does not
129-
// create obligations. However, in some cases there
130-
// are unresolved type variables, and unify them *can*
131-
// create obligations. In that case, we have to go
132-
// fulfill them. We do this via a (recursive) query.
133-
while !obligations.is_empty() {
134-
trace!("{:#?}", obligations);
135-
let mut progress = false;
136-
for obligation in std::mem::take(&mut obligations) {
137-
let obligation = infcx.resolve_vars_if_possible(obligation);
138-
match ProvePredicate::fully_perform_into(
139-
obligation.param_env.and(ProvePredicate::new(obligation.predicate)),
140-
infcx,
141-
&mut region_constraints,
142-
) {
143-
Ok(((), _, new, certainty)) => {
144-
obligations.extend(new);
145-
progress = true;
146-
if let Certainty::Ambiguous = certainty {
147-
obligations.push(obligation);
148-
}
149-
}
150-
Err(_) => obligations.push(obligation),
151-
}
152-
}
153-
if !progress {
154-
return Err(NoSolution);
155-
}
156-
}
157-
158135
// Promote the final query-region-constraints into a
159136
// (optional) ref-counted vector:
160137
let region_constraints =

src/test/ui/type-alias-impl-trait/bound_reduction2.rs

+4
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,9 @@ impl<W> Trait<W> for () {}
1515

1616
fn foo_desugared<T: TraitWithAssoc>(_: T) -> Foo<T::Assoc> {
1717
//~^ ERROR non-defining opaque type use in defining scope
18+
//~| ERROR non-defining opaque type use in defining scope
19+
//~| ERROR non-defining opaque type use in defining scope
20+
//~| ERROR `T` is part of concrete type but not used in parameter list
21+
//~| ERROR `T` is part of concrete type but not used in parameter list
1822
()
1923
}
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,70 @@
1+
error: type parameter `T` is part of concrete type but not used in parameter list for the `impl Trait` type alias
2+
--> $DIR/bound_reduction2.rs:16:60
3+
|
4+
LL | fn foo_desugared<T: TraitWithAssoc>(_: T) -> Foo<T::Assoc> {
5+
| ____________________________________________________________^
6+
LL | |
7+
LL | |
8+
LL | |
9+
... |
10+
LL | | ()
11+
LL | | }
12+
| |_^
13+
14+
error: type parameter `T` is part of concrete type but not used in parameter list for the `impl Trait` type alias
15+
--> $DIR/bound_reduction2.rs:16:60
16+
|
17+
LL | fn foo_desugared<T: TraitWithAssoc>(_: T) -> Foo<T::Assoc> {
18+
| ____________________________________________________________^
19+
LL | |
20+
LL | |
21+
LL | |
22+
... |
23+
LL | | ()
24+
LL | | }
25+
| |_^
26+
127
error: non-defining opaque type use in defining scope
2-
--> $DIR/bound_reduction2.rs:16:46
28+
--> $DIR/bound_reduction2.rs:16:1
329
|
430
LL | fn foo_desugared<T: TraitWithAssoc>(_: T) -> Foo<T::Assoc> {
5-
| ^^^^^^^^^^^^^
31+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
632
|
733
note: used non-generic type `<T as TraitWithAssoc>::Assoc` for generic parameter
834
--> $DIR/bound_reduction2.rs:9:10
935
|
1036
LL | type Foo<V> = impl Trait<V>;
1137
| ^
1238

39+
error: non-defining opaque type use in defining scope
40+
--> $DIR/bound_reduction2.rs:16:1
41+
|
42+
LL | fn foo_desugared<T: TraitWithAssoc>(_: T) -> Foo<T::Assoc> {
43+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
44+
|
45+
note: used non-generic type `_` for generic parameter
46+
--> $DIR/bound_reduction2.rs:9:10
47+
|
48+
LL | type Foo<V> = impl Trait<V>;
49+
| ^
50+
51+
error: non-defining opaque type use in defining scope
52+
--> $DIR/bound_reduction2.rs:16:1
53+
|
54+
LL | fn foo_desugared<T: TraitWithAssoc>(_: T) -> Foo<T::Assoc> {
55+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
56+
|
57+
note: used non-generic type `_` for generic parameter
58+
--> $DIR/bound_reduction2.rs:9:10
59+
|
60+
LL | type Foo<V> = impl Trait<V>;
61+
| ^
62+
1363
error: could not find defining uses
1464
--> $DIR/bound_reduction2.rs:9:15
1565
|
1666
LL | type Foo<V> = impl Trait<V>;
1767
| ^^^^^^^^^^^^^
1868

19-
error: aborting due to 2 previous errors
69+
error: aborting due to 6 previous errors
2070

0 commit comments

Comments
 (0)