summaryrefslogtreecommitdiffstats
path: root/compiler/rustc_privacy/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'compiler/rustc_privacy/src/lib.rs')
-rw-r--r--compiler/rustc_privacy/src/lib.rs76
1 files changed, 46 insertions, 30 deletions
diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs
index 9a5d3cceb..50176c802 100644
--- a/compiler/rustc_privacy/src/lib.rs
+++ b/compiler/rustc_privacy/src/lib.rs
@@ -16,11 +16,13 @@ use rustc_ast::MacroDef;
use rustc_attr as attr;
use rustc_data_structures::fx::FxHashSet;
use rustc_data_structures::intern::Interned;
+use rustc_errors::{DiagnosticMessage, SubdiagnosticMessage};
use rustc_hir as hir;
use rustc_hir::def::{DefKind, Res};
-use rustc_hir::def_id::{DefId, LocalDefId, LocalDefIdSet, CRATE_DEF_ID};
+use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID};
use rustc_hir::intravisit::{self, Visitor};
use rustc_hir::{AssocItemKind, HirIdSet, ItemId, Node, PatKind};
+use rustc_macros::fluent_messages;
use rustc_middle::bug;
use rustc_middle::hir::nested_filter;
use rustc_middle::middle::privacy::{EffectiveVisibilities, Level};
@@ -44,6 +46,8 @@ use errors::{
UnnamedItemIsPrivate,
};
+fluent_messages! { "../locales/en-US.ftl" }
+
////////////////////////////////////////////////////////////////////////////////
/// Generic infrastructure used to implement specific visitors below.
////////////////////////////////////////////////////////////////////////////////
@@ -81,7 +85,10 @@ trait DefIdVisitor<'tcx> {
dummy: Default::default(),
}
}
- fn visit(&mut self, ty_fragment: impl TypeVisitable<'tcx>) -> ControlFlow<Self::BreakTy> {
+ fn visit(
+ &mut self,
+ ty_fragment: impl TypeVisitable<TyCtxt<'tcx>>,
+ ) -> ControlFlow<Self::BreakTy> {
ty_fragment.visit_with(&mut self.skeleton())
}
fn visit_trait(&mut self, trait_ref: TraitRef<'tcx>) -> ControlFlow<Self::BreakTy> {
@@ -159,9 +166,21 @@ where
_region,
))) => ty.visit_with(self),
ty::PredicateKind::Clause(ty::Clause::RegionOutlives(..)) => ControlFlow::Continue(()),
+ ty::PredicateKind::Clause(ty::Clause::ConstArgHasType(ct, ty)) => {
+ ct.visit_with(self)?;
+ ty.visit_with(self)
+ }
ty::PredicateKind::ConstEvaluatable(ct) => ct.visit_with(self),
ty::PredicateKind::WellFormed(arg) => arg.visit_with(self),
- _ => bug!("unexpected predicate: {:?}", predicate),
+
+ ty::PredicateKind::ObjectSafe(_)
+ | ty::PredicateKind::ClosureKind(_, _, _)
+ | ty::PredicateKind::Subtype(_)
+ | ty::PredicateKind::Coerce(_)
+ | ty::PredicateKind::ConstEquate(_, _)
+ | ty::PredicateKind::TypeWellFormedFromEnv(_)
+ | ty::PredicateKind::Ambiguous
+ | ty::PredicateKind::AliasEq(_, _) => bug!("unexpected predicate: {:?}", predicate),
}
}
@@ -174,7 +193,7 @@ where
}
}
-impl<'tcx, V> TypeVisitor<'tcx> for DefIdVisitorSkeleton<'_, 'tcx, V>
+impl<'tcx, V> TypeVisitor<TyCtxt<'tcx>> for DefIdVisitorSkeleton<'_, 'tcx, V>
where
V: DefIdVisitor<'tcx> + ?Sized,
{
@@ -198,7 +217,8 @@ where
// Something like `fn() -> Priv {my_func}` is considered a private type even if
// `my_func` is public, so we need to visit signatures.
if let ty::FnDef(..) = ty.kind() {
- tcx.fn_sig(def_id).visit_with(self)?;
+ // FIXME: this should probably use `substs` from `FnDef`
+ tcx.fn_sig(def_id).subst_identity().visit_with(self)?;
}
// Inherent static methods don't have self type in substs.
// Something like `fn() {my_method}` type of the method
@@ -206,7 +226,7 @@ where
// so we need to visit the self type additionally.
if let Some(assoc_item) = tcx.opt_associated_item(def_id) {
if let Some(impl_def_id) = assoc_item.impl_container(tcx) {
- tcx.type_of(impl_def_id).visit_with(self)?;
+ tcx.type_of(impl_def_id).subst_identity().visit_with(self)?;
}
}
}
@@ -269,9 +289,11 @@ where
| ty::Ref(..)
| ty::FnPtr(..)
| ty::Param(..)
+ | ty::Bound(..)
| ty::Error(_)
- | ty::GeneratorWitness(..) => {}
- ty::Bound(..) | ty::Placeholder(..) | ty::Infer(..) => {
+ | ty::GeneratorWitness(..)
+ | ty::GeneratorWitnessMIR(..) => {}
+ ty::Placeholder(..) | ty::Infer(..) => {
bug!("unexpected type: {:?}", ty)
}
}
@@ -339,7 +361,7 @@ trait VisibilityLike: Sized {
effective_visibilities: &EffectiveVisibilities,
) -> Self {
let mut find = FindMin { tcx, effective_visibilities, min: Self::MAX };
- find.visit(tcx.type_of(def_id));
+ find.visit(tcx.type_of(def_id).subst_identity());
if let Some(trait_ref) = tcx.impl_trait_ref(def_id) {
find.visit_trait(trait_ref.subst_identity());
}
@@ -591,7 +613,7 @@ impl<'tcx> EmbargoVisitor<'tcx> {
| DefKind::InlineConst
| DefKind::Field
| DefKind::GlobalAsm
- | DefKind::Impl
+ | DefKind::Impl { .. }
| DefKind::Closure
| DefKind::Generator => (),
}
@@ -835,11 +857,11 @@ impl ReachEverythingInTheInterfaceVisitor<'_, '_> {
GenericParamDefKind::Lifetime => {}
GenericParamDefKind::Type { has_default, .. } => {
if has_default {
- self.visit(self.ev.tcx.type_of(param.def_id));
+ self.visit(self.ev.tcx.type_of(param.def_id).subst_identity());
}
}
GenericParamDefKind::Const { has_default } => {
- self.visit(self.ev.tcx.type_of(param.def_id));
+ self.visit(self.ev.tcx.type_of(param.def_id).subst_identity());
if has_default {
self.visit(self.ev.tcx.const_param_default(param.def_id).subst_identity());
}
@@ -855,7 +877,7 @@ impl ReachEverythingInTheInterfaceVisitor<'_, '_> {
}
fn ty(&mut self) -> &mut Self {
- self.visit(self.ev.tcx.type_of(self.item_def_id));
+ self.visit(self.ev.tcx.type_of(self.item_def_id).subst_identity());
self
}
@@ -1266,7 +1288,7 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> {
// Method calls have to be checked specially.
self.span = segment.ident.span;
if let Some(def_id) = self.typeck_results().type_dependent_def_id(expr.hir_id) {
- if self.visit(self.tcx.type_of(def_id)).is_break() {
+ if self.visit(self.tcx.type_of(def_id).subst_identity()).is_break() {
return;
}
} else {
@@ -1314,7 +1336,7 @@ impl<'tcx> Visitor<'tcx> for TypePrivacyVisitor<'tcx> {
hir::QPath::Resolved(_, path) => Some(self.tcx.def_path_str(path.res.def_id())),
hir::QPath::TypeRelative(_, segment) => Some(segment.ident.to_string()),
};
- let kind = kind.descr(def_id);
+ let kind = self.tcx.def_descr(def_id);
let sess = self.tcx.sess;
let _ = match name {
Some(name) => {
@@ -1740,12 +1762,12 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
GenericParamDefKind::Lifetime => {}
GenericParamDefKind::Type { has_default, .. } => {
if has_default {
- self.visit(self.tcx.type_of(param.def_id));
+ self.visit(self.tcx.type_of(param.def_id).subst_identity());
}
}
// FIXME(generic_const_exprs): May want to look inside const here
GenericParamDefKind::Const { .. } => {
- self.visit(self.tcx.type_of(param.def_id));
+ self.visit(self.tcx.type_of(param.def_id).subst_identity());
}
}
}
@@ -1772,7 +1794,7 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
}
fn ty(&mut self) -> &mut Self {
- self.visit(self.tcx.type_of(self.item_def_id));
+ self.visit(self.tcx.type_of(self.item_def_id).subst_identity());
self
}
@@ -1877,7 +1899,7 @@ impl<'tcx> DefIdVisitor<'tcx> for SearchInterfaceForPrivateItemsVisitor<'tcx> {
struct PrivateItemsInPublicInterfacesChecker<'tcx> {
tcx: TyCtxt<'tcx>,
- old_error_set_ancestry: LocalDefIdSet,
+ old_error_set_ancestry: HirIdSet,
}
impl<'tcx> PrivateItemsInPublicInterfacesChecker<'tcx> {
@@ -1890,7 +1912,9 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'tcx> {
tcx: self.tcx,
item_def_id: def_id,
required_visibility,
- has_old_errors: self.old_error_set_ancestry.contains(&def_id),
+ has_old_errors: self
+ .old_error_set_ancestry
+ .contains(&self.tcx.hir().local_def_id_to_hir_id(def_id)),
in_assoc_ty: false,
}
}
@@ -1993,7 +2017,7 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'tcx> {
// Subitems of inherent impls have their own publicity.
// A trait impl is public when both its type and its trait are public
// Subitems of trait impls have inherited publicity.
- DefKind::Impl => {
+ DefKind::Impl { .. } => {
let item = tcx.hir().item(id);
if let hir::ItemKind::Impl(ref impl_) = item.kind {
let impl_vis =
@@ -2156,15 +2180,7 @@ fn check_private_in_public(tcx: TyCtxt<'_>, (): ()) {
}
// Check for private types and traits in public interfaces.
- let mut checker = PrivateItemsInPublicInterfacesChecker {
- tcx,
- // Only definition IDs are ever searched in `old_error_set_ancestry`,
- // so we can filter away all non-definition IDs at this point.
- old_error_set_ancestry: old_error_set_ancestry
- .into_iter()
- .filter_map(|hir_id| tcx.hir().opt_local_def_id(hir_id))
- .collect(),
- };
+ let mut checker = PrivateItemsInPublicInterfacesChecker { tcx, old_error_set_ancestry };
for id in tcx.hir().items() {
checker.check_item(id);