Skip to content

Commit e5d022f

Browse files
authored
Rollup merge of #95471 - oli-obk:tait_ice, r=estebank
Don't ICE when opaque types get their hidden type constrained again. Contrary to popular belief, `codegen_fulfill_obligation` does not get used solely in codegen, so we cannot rely on `param_env` being set to RevealAll and thus revealing the hidden types instead of constraining them. Fixes #89312 (for real this time)
2 parents d7b0032 + 1144677 commit e5d022f

File tree

2 files changed

+30
-13
lines changed

2 files changed

+30
-13
lines changed

compiler/rustc_trait_selection/src/traits/codegen.rs

+6-13
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use rustc_middle::ty::{self, TyCtxt};
1919
/// obligations *could be* resolved if we wanted to.
2020
///
2121
/// This also expects that `trait_ref` is fully normalized.
22+
#[instrument(level = "debug", skip(tcx))]
2223
pub fn codegen_fulfill_obligation<'tcx>(
2324
tcx: TyCtxt<'tcx>,
2425
(param_env, trait_ref): (ty::ParamEnv<'tcx>, ty::PolyTraitRef<'tcx>),
@@ -27,11 +28,6 @@ pub fn codegen_fulfill_obligation<'tcx>(
2728
let trait_ref = tcx.erase_regions(trait_ref);
2829
// We expect the input to be fully normalized.
2930
debug_assert_eq!(trait_ref, tcx.normalize_erasing_regions(param_env, trait_ref));
30-
debug!(
31-
"codegen_fulfill_obligation(trait_ref={:?}, def_id={:?})",
32-
(param_env, trait_ref),
33-
trait_ref.def_id()
34-
);
3531

3632
// Do the initial selection for the obligation. This yields the
3733
// shallow result we are looking for -- that is, what specific impl.
@@ -80,25 +76,22 @@ pub fn codegen_fulfill_obligation<'tcx>(
8076
}
8177
};
8278

83-
debug!("fulfill_obligation: selection={:?}", selection);
79+
debug!(?selection);
8480

8581
// Currently, we use a fulfillment context to completely resolve
8682
// all nested obligations. This is because they can inform the
8783
// inference of the impl's type parameters.
8884
let mut fulfill_cx = FulfillmentContext::new();
8985
let impl_source = selection.map(|predicate| {
90-
debug!("fulfill_obligation: register_predicate_obligation {:?}", predicate);
9186
fulfill_cx.register_predicate_obligation(&infcx, predicate);
9287
});
9388
let impl_source = drain_fulfillment_cx_or_panic(&infcx, &mut fulfill_cx, impl_source);
9489

95-
// There should be no opaque types during codegen, they all get revealed.
96-
let opaque_types = infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types();
97-
if !opaque_types.is_empty() {
98-
bug!("{:#?}", opaque_types);
99-
}
90+
// Opaque types may have gotten their hidden types constrained, but we can ignore them safely
91+
// as they will get constrained elsewhere, too.
92+
let _opaque_types = infcx.inner.borrow_mut().opaque_type_storage.take_opaque_types();
10093

101-
debug!("Cache miss: {:?} => {:?}", trait_ref, impl_source);
94+
debug!("Cache miss: {trait_ref:?} => {impl_source:?}");
10295
Ok(&*tcx.arena.alloc(impl_source))
10396
})
10497
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#![feature(type_alias_impl_trait)]
2+
3+
// build-pass
4+
5+
trait T { type Item; }
6+
7+
type Alias<'a> = impl T<Item = &'a ()>;
8+
9+
struct S;
10+
impl<'a> T for &'a S {
11+
type Item = &'a ();
12+
}
13+
14+
fn filter_positive<'a>() -> Alias<'a> {
15+
&S
16+
}
17+
18+
fn with_positive(fun: impl Fn(Alias<'_>)) {
19+
fun(filter_positive());
20+
}
21+
22+
fn main() {
23+
with_positive(|_| ());
24+
}

0 commit comments

Comments
 (0)