1
Fork 0

Separate bounds and predicates for associated/opaque types

This commit is contained in:
Matthew Jasper 2020-06-27 21:36:35 +01:00
parent d297147e62
commit f958e6c246
107 changed files with 923 additions and 1117 deletions

View file

@ -194,11 +194,14 @@ where
// The intent is to treat `impl Trait1 + Trait2` identically to
// `dyn Trait1 + Trait2`. Therefore we ignore def-id of the opaque type itself
// (it either has no visibility, or its visibility is insignificant, like
// visibilities of type aliases) and recurse into predicates instead to go
// visibilities of type aliases) and recurse into bounds instead to go
// through the trait list (default type visitor doesn't visit those traits).
// All traits in the list are considered the "primary" part of the type
// and are visited by shallow visitors.
if self.visit_predicates(tcx.predicates_of(def_id)) {
if self.visit_predicates(ty::GenericPredicates {
parent: None,
predicates: tcx.explicit_item_bounds(def_id),
}) {
return true;
}
}
@ -1800,6 +1803,14 @@ impl SearchInterfaceForPrivateItemsVisitor<'tcx> {
self
}
fn bounds(&mut self) -> &mut Self {
self.visit_predicates(ty::GenericPredicates {
parent: None,
predicates: self.tcx.explicit_item_bounds(self.item_def_id),
});
self
}
fn ty(&mut self) -> &mut Self {
self.visit(self.tcx.type_of(self.item_def_id));
self
@ -1975,7 +1986,7 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx>
hir::ItemKind::OpaqueTy(..) => {
// `ty()` for opaque types is the underlying type,
// it's not a part of interface, so we skip it.
self.check(item.hir_id, item_visibility).generics().predicates();
self.check(item.hir_id, item_visibility).generics().bounds();
}
hir::ItemKind::Trait(.., trait_item_refs) => {
self.check(item.hir_id, item_visibility).generics().predicates();
@ -1987,6 +1998,10 @@ impl<'a, 'tcx> Visitor<'tcx> for PrivateItemsInPublicInterfacesVisitor<'a, 'tcx>
trait_item_ref.defaultness,
item_visibility,
);
if let AssocItemKind::Type = trait_item_ref.kind {
self.check(trait_item_ref.id.hir_id, item_visibility).bounds();
}
}
}
hir::ItemKind::TraitAlias(..) => {