Skip to content

Commit 558cfd2

Browse files
Enforce opaque WF during add_item_bounds_for_hidden_type
1 parent af69f4c commit 558cfd2

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

compiler/rustc_infer/src/infer/opaque_types/mod.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -610,6 +610,15 @@ impl<'tcx> InferCtxt<'tcx> {
610610
ty::ClauseKind::WellFormed(hidden_ty.into()),
611611
));
612612

613+
// This enforces the region obligations that link the bivariant
614+
// lifetimes of an opaque to their invariant copies.
615+
obligations.push(traits::Obligation::new(
616+
tcx,
617+
cause.clone(),
618+
param_env,
619+
ty::ClauseKind::WellFormed(Ty::new_opaque(self.tcx, def_id, args).into()),
620+
));
621+
613622
let item_bounds = tcx.explicit_item_bounds(def_id);
614623
for (predicate, _) in item_bounds.iter_instantiated_copied(tcx, args) {
615624
let predicate = predicate.fold_with(&mut BottomUpFolder {
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//@ check-pass
2+
3+
#![feature(type_alias_impl_trait)]
4+
#![allow(unconditional_recursion)]
5+
6+
type Opaque<'a> = impl Sized + 'a;
7+
8+
fn test<'a>() -> Opaque<'a> {
9+
let _: () = test::<'a>();
10+
}
11+
12+
fn main() {}

0 commit comments

Comments
 (0)