Skip to content

stop feed vis when cant access for trait item #119553

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion compiler/rustc_resolve/src/late.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3076,7 +3076,16 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
}

let feed_visibility = |this: &mut Self, def_id| {
let vis = this.r.tcx.visibility(def_id).expect_local();
let vis = this.r.tcx.visibility(def_id);
let vis = if vis.is_visible_locally() {
vis.expect_local()
} else {
this.r.dcx().span_delayed_bug(
span,
"error should be emitted when an unexpected trait item is used",
);
rustc_middle::ty::Visibility::Public
};
this.r.feed_visibility(this.r.local_def_id(id), vis);
};

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;
}
15 changes: 15 additions & 0 deletions tests/ui/privacy/issue-119463.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// 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 nonexistent() {}
//~^ ERROR: method `nonexistent` is not a member of trait
}

fn main() {}
22 changes: 22 additions & 0 deletions tests/ui/privacy/issue-119463.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
error[E0407]: method `nonexistent` is not a member of trait `issue_119463_extern::PrivateTrait`
--> $DIR/issue-119463.rs:11:5
|
LL | fn nonexistent() {}
| ^^^^^^^^^^^^^^^^^^^ not a member of trait `issue_119463_extern::PrivateTrait`

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 2 previous errors

Some errors have detailed explanations: E0407, E0603.
For more information about an error, try `rustc --explain E0407`.