diff options
| author | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2022-06-21 15:42:25 +0000 |
|---|---|---|
| committer | Oli Scherer <git-spam-no-reply9815368754983@oli-obk.de> | 2022-09-21 13:15:24 +0000 |
| commit | 20d962cfa5511eece711684ff83cb721eacd60dc (patch) | |
| tree | 562186b7bc7e00fbd1a2cbb0fb62179778ecf3da | |
| parent | 615c9e8647b0ce46c1b1755201c8e2799a3ca2bc (diff) | |
| download | rust-20d962cfa5511eece711684ff83cb721eacd60dc.tar.gz rust-20d962cfa5511eece711684ff83cb721eacd60dc.zip | |
Simplify insert_outlives_predicate opaque type logic
| -rw-r--r-- | compiler/rustc_typeck/src/outlives/utils.rs | 46 | ||||
| -rw-r--r-- | src/test/ui/type-alias-impl-trait/unbounded_opaque_type.rs | 8 |
2 files changed, 23 insertions, 31 deletions
diff --git a/compiler/rustc_typeck/src/outlives/utils.rs b/compiler/rustc_typeck/src/outlives/utils.rs index 4c32a1e81ba..f582fdf903d 100644 --- a/compiler/rustc_typeck/src/outlives/utils.rs +++ b/compiler/rustc_typeck/src/outlives/utils.rs @@ -1,6 +1,6 @@ use rustc_infer::infer::outlives::components::{push_outlives_components, Component}; use rustc_middle::ty::subst::{GenericArg, GenericArgKind}; -use rustc_middle::ty::{self, EarlyBinder, Region, Ty, TyCtxt}; +use rustc_middle::ty::{self, Region, Ty, TyCtxt}; use rustc_span::Span; use smallvec::smallvec; use std::collections::BTreeMap; @@ -97,36 +97,20 @@ pub(crate) fn insert_outlives_predicate<'tcx>( } Component::Opaque(def_id, substs) => { - for predicate in tcx.item_bounds(def_id) { - let predicate = EarlyBinder(predicate).subst(tcx, substs); - // FIXME(oli-obk): fishy skip-binder - match predicate.kind().skip_binder() { - ty::PredicateKind::Trait(tp) => { - for subst in tp.trait_ref.substs { - insert_outlives_predicate( - tcx, - subst, - outlived_region, - span, - required_predicates, - ) - } - } - ty::PredicateKind::RegionOutlives(_) - | ty::PredicateKind::TypeOutlives(_) - | ty::PredicateKind::Projection(_) - | ty::PredicateKind::WellFormed(_) - | ty::PredicateKind::ObjectSafe(_) - | ty::PredicateKind::ClosureKind(_, _, _) - | ty::PredicateKind::Subtype(_) - | ty::PredicateKind::Coerce(_) - | ty::PredicateKind::ConstEvaluatable(_) - | ty::PredicateKind::ConstEquate(_, _) - | ty::PredicateKind::TypeWellFormedFromEnv(_) => { - todo!("{:#?}", predicate) - } - } - } + // This would arise from something like: + // + // ```rust + // type Opaque<T> = impl Sized; + // fn defining<T>() -> Opaque<T> {} + // struct Ss<'a, T>(&'a Opaque<T>); + // ``` + // + // Here we want to require an explicit `where Opaque<T>: 'a` + + let ty = tcx.mk_opaque(def_id, substs); + required_predicates + .entry(ty::OutlivesPredicate(ty.into(), outlived_region)) + .or_insert(span); } Component::EscapingProjection(_) => { diff --git a/src/test/ui/type-alias-impl-trait/unbounded_opaque_type.rs b/src/test/ui/type-alias-impl-trait/unbounded_opaque_type.rs new file mode 100644 index 00000000000..a5ab3e1acae --- /dev/null +++ b/src/test/ui/type-alias-impl-trait/unbounded_opaque_type.rs @@ -0,0 +1,8 @@ +// check-pass + +#![feature(type_alias_impl_trait)] +type Opaque<T> = impl Sized; +fn defining<T>() -> Opaque<T> {} +struct Ss<'a, T>(&'a Opaque<T>); + +fn main() {} |
