diff options
| author | Guillaume Gomez <guillaume1.gomez@gmail.com> | 2023-09-08 14:10:51 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-08 14:10:51 +0200 |
| commit | e3b61225307dc0e2fea088fe8a7678849074d1f4 (patch) | |
| tree | 08947edf7eae23de96605a269c4070e85b72b09a | |
| parent | 1fb672c7387fc597c93d0657c4892d254d7ab338 (diff) | |
| parent | 14e59bb317c3c901bce83deb16ee9bfa5cc90e28 (diff) | |
| download | rust-e3b61225307dc0e2fea088fe8a7678849074d1f4.tar.gz rust-e3b61225307dc0e2fea088fe8a7678849074d1f4.zip | |
Rollup merge of #115633 - compiler-errors:PRIVATE_BOUNDS-lint-node, r=petrochenkov
Lint node for `PRIVATE_BOUNDS`/`PRIVATE_INTERFACES` is the item which names the private type The HIR that the `PRIVATE_BOUNDS` lint should be attached to is the item that has the *bounds*, not the private type. This PR also aligns this behavior with the `EXPORTED_PRIVATE_DEPENDENCIES` lint, which also requires putting the `allow` on the item that names the private type. Fixes #115475 r? petrochenkov
| -rw-r--r-- | compiler/rustc_privacy/src/lib.rs | 7 | ||||
| -rw-r--r-- | tests/ui/privacy/private-bounds-locally-allowed.rs | 7 |
2 files changed, 11 insertions, 3 deletions
diff --git a/compiler/rustc_privacy/src/lib.rs b/compiler/rustc_privacy/src/lib.rs index 906a36cdb25..aedc7b22725 100644 --- a/compiler/rustc_privacy/src/lib.rs +++ b/compiler/rustc_privacy/src/lib.rs @@ -1463,14 +1463,15 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> { }; let vis = self.tcx.local_visibility(local_def_id); - let hir_id = self.tcx.hir().local_def_id_to_hir_id(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", ty::Visibility::Restricted(vis_def_id) => { - if vis_def_id == self.tcx.parent_module(hir_id).to_local_def_id() { + if vis_def_id + == self.tcx.parent_module_from_def_id(local_def_id).to_local_def_id() + { "private" } else if vis_def_id.is_top_level_module() { "crate-private" @@ -1504,7 +1505,7 @@ impl SearchInterfaceForPrivateItemsVisitor<'_> { }; self.tcx.emit_spanned_lint( lint, - hir_id, + self.tcx.hir().local_def_id_to_hir_id(self.item_def_id), span, PrivateInterfacesOrBoundsLint { item_span: span, diff --git a/tests/ui/privacy/private-bounds-locally-allowed.rs b/tests/ui/privacy/private-bounds-locally-allowed.rs new file mode 100644 index 00000000000..96a007a64f6 --- /dev/null +++ b/tests/ui/privacy/private-bounds-locally-allowed.rs @@ -0,0 +1,7 @@ +// check-pass +// compile-flags: --crate-type=lib + +#[allow(private_bounds)] +pub trait Foo: FooImpl {} + +trait FooImpl {} |
