Skip to content

Commit

Permalink
stop feed vis when cant access for trait item
Browse files Browse the repository at this point in the history
  • Loading branch information
bvanjoi committed Jan 3, 2024
1 parent 2e79c8d commit 7a5aae2
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 1 deletion.
10 changes: 9 additions & 1 deletion compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3092,7 +3092,15 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {

let res = binding.res();
let Res::Def(def_kind, id_in_trait) = res else { bug!() };
feed_visibility(self, id_in_trait);

if !self.r.is_accessible_from(binding.vis, self.parent_scope.module) {
self.r.dcx().span_delayed_bug(
span,
"privacy error should be emitted when a private trait is used",
);
} else {
feed_visibility(self, id_in_trait);
}

match seen_trait_items.entry(id_in_trait) {
Entry::Occupied(entry) => {
Expand Down
3 changes: 3 additions & 0 deletions tests/ui/privacy/auxiliary/issue-119463-extern.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
trait PrivateTrait {
const FOO: usize;
}
11 changes: 11 additions & 0 deletions tests/ui/privacy/issue-119463.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// aux-build:issue-119463-extern.rs

extern crate issue_119463_extern;

struct S;

impl issue_119463_extern::PrivateTrait for S { //~ ERROR: trait `PrivateTrait` is private
const FOO: usize = 1;
}

fn main() {}
15 changes: 15 additions & 0 deletions tests/ui/privacy/issue-119463.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
error[E0603]: trait `PrivateTrait` is private
--> $DIR/issue-119463.rs:7:27
|
LL | impl issue_119463_extern::PrivateTrait for S {
| ^^^^^^^^^^^^ private trait
|
note: the trait `PrivateTrait` is defined here
--> $DIR/auxiliary/issue-119463-extern.rs:1:1
|
LL | trait PrivateTrait {
| ^^^^^^^^^^^^^^^^^^

error: aborting due to 1 previous error

For more information about this error, try `rustc --explain E0603`.

0 comments on commit 7a5aae2

Please sign in to comment.