Skip to content

Commit 20d962c

Browse files
committed
Simplify insert_outlives_predicate opaque type logic
1 parent 615c9e8 commit 20d962c

File tree

2 files changed

+23
-31
lines changed

2 files changed

+23
-31
lines changed

compiler/rustc_typeck/src/outlives/utils.rs

+15-31
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use rustc_infer::infer::outlives::components::{push_outlives_components, Component};
22
use rustc_middle::ty::subst::{GenericArg, GenericArgKind};
3-
use rustc_middle::ty::{self, EarlyBinder, Region, Ty, TyCtxt};
3+
use rustc_middle::ty::{self, Region, Ty, TyCtxt};
44
use rustc_span::Span;
55
use smallvec::smallvec;
66
use std::collections::BTreeMap;
@@ -97,36 +97,20 @@ pub(crate) fn insert_outlives_predicate<'tcx>(
9797
}
9898

9999
Component::Opaque(def_id, substs) => {
100-
for predicate in tcx.item_bounds(def_id) {
101-
let predicate = EarlyBinder(predicate).subst(tcx, substs);
102-
// FIXME(oli-obk): fishy skip-binder
103-
match predicate.kind().skip_binder() {
104-
ty::PredicateKind::Trait(tp) => {
105-
for subst in tp.trait_ref.substs {
106-
insert_outlives_predicate(
107-
tcx,
108-
subst,
109-
outlived_region,
110-
span,
111-
required_predicates,
112-
)
113-
}
114-
}
115-
ty::PredicateKind::RegionOutlives(_)
116-
| ty::PredicateKind::TypeOutlives(_)
117-
| ty::PredicateKind::Projection(_)
118-
| ty::PredicateKind::WellFormed(_)
119-
| ty::PredicateKind::ObjectSafe(_)
120-
| ty::PredicateKind::ClosureKind(_, _, _)
121-
| ty::PredicateKind::Subtype(_)
122-
| ty::PredicateKind::Coerce(_)
123-
| ty::PredicateKind::ConstEvaluatable(_)
124-
| ty::PredicateKind::ConstEquate(_, _)
125-
| ty::PredicateKind::TypeWellFormedFromEnv(_) => {
126-
todo!("{:#?}", predicate)
127-
}
128-
}
129-
}
100+
// This would arise from something like:
101+
//
102+
// ```rust
103+
// type Opaque<T> = impl Sized;
104+
// fn defining<T>() -> Opaque<T> {}
105+
// struct Ss<'a, T>(&'a Opaque<T>);
106+
// ```
107+
//
108+
// Here we want to require an explicit `where Opaque<T>: 'a`
109+
110+
let ty = tcx.mk_opaque(def_id, substs);
111+
required_predicates
112+
.entry(ty::OutlivesPredicate(ty.into(), outlived_region))
113+
.or_insert(span);
130114
}
131115

132116
Component::EscapingProjection(_) => {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// check-pass
2+
3+
#![feature(type_alias_impl_trait)]
4+
type Opaque<T> = impl Sized;
5+
fn defining<T>() -> Opaque<T> {}
6+
struct Ss<'a, T>(&'a Opaque<T>);
7+
8+
fn main() {}

0 commit comments

Comments
 (0)