summaryrefslogtreecommitdiff
path: root/compiler/rustc_ty_utils/src/implied_bounds.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_ty_utils/src/implied_bounds.rs')
-rw-r--r--compiler/rustc_ty_utils/src/implied_bounds.rs18
1 files changed, 15 insertions, 3 deletions
diff --git a/compiler/rustc_ty_utils/src/implied_bounds.rs b/compiler/rustc_ty_utils/src/implied_bounds.rs
index 56d6cc28bc8..081be065864 100644
--- a/compiler/rustc_ty_utils/src/implied_bounds.rs
+++ b/compiler/rustc_ty_utils/src/implied_bounds.rs
@@ -1,8 +1,9 @@
use rustc_hir::{def::DefKind, def_id::DefId};
+use rustc_middle::query::Providers;
use rustc_middle::ty::{self, Ty, TyCtxt};
-pub fn provide(providers: &mut ty::query::Providers) {
- *providers = ty::query::Providers { assumed_wf_types, ..*providers };
+pub fn provide(providers: &mut Providers) {
+ *providers = Providers { assumed_wf_types, ..*providers };
}
fn assumed_wf_types(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::List<Ty<'_>> {
@@ -31,6 +32,18 @@ fn assumed_wf_types(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::List<Ty<'_>> {
}
}
DefKind::AssocConst | DefKind::AssocTy => tcx.assumed_wf_types(tcx.parent(def_id)),
+ DefKind::OpaqueTy => match tcx.def_kind(tcx.parent(def_id)) {
+ DefKind::TyAlias => ty::List::empty(),
+ DefKind::AssocTy => tcx.assumed_wf_types(tcx.parent(def_id)),
+ // Nested opaque types only occur in associated types:
+ // ` type Opaque<T> = impl Trait<&'static T, AssocTy = impl Nested>; `
+ // assumed_wf_types should include those of `Opaque<T>`, `Opaque<T>` itself
+ // and `&'static T`.
+ DefKind::OpaqueTy => bug!("unimplemented implied bounds for neseted opaque types"),
+ def_kind @ _ => {
+ bug!("unimplemented implied bounds for opaque types with parent {def_kind:?}")
+ }
+ },
DefKind::Mod
| DefKind::Struct
| DefKind::Union
@@ -51,7 +64,6 @@ fn assumed_wf_types(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::List<Ty<'_>> {
| DefKind::ForeignMod
| DefKind::AnonConst
| DefKind::InlineConst
- | DefKind::OpaqueTy
| DefKind::ImplTraitPlaceholder
| DefKind::Field
| DefKind::LifetimeParam