Auto merge of #144479 - cjgillot:incr-privacy-mod, r=petrochenkov
Perform check_private_in_public by module. Based on https://github.com/rust-lang/rust/pull/116316
This commit is contained in:
commit
c23f07d8c5
5 changed files with 68 additions and 65 deletions
|
|
@ -1423,8 +1423,6 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
|
|||
};
|
||||
|
||||
let vis = self.tcx.local_visibility(local_def_id);
|
||||
let span = self.tcx.def_span(self.item_def_id.to_def_id());
|
||||
let vis_span = self.tcx.def_span(def_id);
|
||||
if self.in_assoc_ty && !vis.is_at_least(self.required_visibility, self.tcx) {
|
||||
let vis_descr = match vis {
|
||||
ty::Visibility::Public => "public",
|
||||
|
|
@ -1441,6 +1439,8 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
|
|||
}
|
||||
};
|
||||
|
||||
let span = self.tcx.def_span(self.item_def_id.to_def_id());
|
||||
let vis_span = self.tcx.def_span(def_id);
|
||||
self.tcx.dcx().emit_err(InPublicInterface {
|
||||
span,
|
||||
vis_descr,
|
||||
|
|
@ -1463,6 +1463,8 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> {
|
|||
} else {
|
||||
lint::builtin::PRIVATE_BOUNDS
|
||||
};
|
||||
let span = self.tcx.def_span(self.item_def_id.to_def_id());
|
||||
let vis_span = self.tcx.def_span(def_id);
|
||||
self.tcx.emit_node_span_lint(
|
||||
lint,
|
||||
self.tcx.local_def_id_to_hir_id(self.item_def_id),
|
||||
|
|
@ -1594,7 +1596,7 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'_, 'tcx> {
|
|||
self.effective_visibilities.effective_vis(def_id).copied()
|
||||
}
|
||||
|
||||
fn check_item(&mut self, id: ItemId) {
|
||||
fn check_item(&self, id: ItemId) {
|
||||
let tcx = self.tcx;
|
||||
let def_id = id.owner_id.def_id;
|
||||
let item_visibility = tcx.local_visibility(def_id);
|
||||
|
|
@ -1722,7 +1724,7 @@ impl<'tcx> PrivateItemsInPublicInterfacesChecker<'_, 'tcx> {
|
|||
}
|
||||
}
|
||||
|
||||
fn check_foreign_item(&mut self, id: ForeignItemId) {
|
||||
fn check_foreign_item(&self, id: ForeignItemId) {
|
||||
let tcx = self.tcx;
|
||||
let def_id = id.owner_id.def_id;
|
||||
let item_visibility = tcx.local_visibility(def_id);
|
||||
|
|
@ -1854,16 +1856,12 @@ fn effective_visibilities(tcx: TyCtxt<'_>, (): ()) -> &EffectiveVisibilities {
|
|||
tcx.arena.alloc(visitor.effective_visibilities)
|
||||
}
|
||||
|
||||
fn check_private_in_public(tcx: TyCtxt<'_>, (): ()) {
|
||||
fn check_private_in_public(tcx: TyCtxt<'_>, module_def_id: LocalModDefId) {
|
||||
let effective_visibilities = tcx.effective_visibilities(());
|
||||
// Check for private types in public interfaces.
|
||||
let mut checker = PrivateItemsInPublicInterfacesChecker { tcx, effective_visibilities };
|
||||
let checker = PrivateItemsInPublicInterfacesChecker { tcx, effective_visibilities };
|
||||
|
||||
let crate_items = tcx.hir_crate_items(());
|
||||
for id in crate_items.free_items() {
|
||||
checker.check_item(id);
|
||||
}
|
||||
for id in crate_items.foreign_items() {
|
||||
checker.check_foreign_item(id);
|
||||
}
|
||||
let crate_items = tcx.hir_module_items(module_def_id);
|
||||
let _ = crate_items.par_items(|id| Ok(checker.check_item(id)));
|
||||
let _ = crate_items.par_foreign_items(|id| Ok(checker.check_foreign_item(id)));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue