diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2024-01-04 15:34:01 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-01-04 15:34:01 +0100 |
| commit | ee882d628f831bce7e534d288fd7cacde281a94d (patch) | |
| tree | d25e79e30b1c1f03714025607ca636817b19e24e | |
| parent | e306cfb115b2e4351757b8282b402b0c736ef529 (diff) | |
| parent | 862368db9ff0db55940ef6543f246fd5d542a580 (diff) | |
| download | rust-ee882d628f831bce7e534d288fd7cacde281a94d.tar.gz rust-ee882d628f831bce7e534d288fd7cacde281a94d.zip | |
Rollup merge of #119553 - bvanjoi:fix-119463, r=petrochenkov
stop feed vis when cant access for trait item Fixes #119463 It's not necessary to feed visibility when use a private trait. r? ``@petrochenkov``
| -rw-r--r-- | compiler/rustc_resolve/src/late.rs | 11 | ||||
| -rw-r--r-- | tests/ui/privacy/auxiliary/issue-119463-extern.rs | 3 | ||||
| -rw-r--r-- | tests/ui/privacy/issue-119463.rs | 15 | ||||
| -rw-r--r-- | tests/ui/privacy/issue-119463.stderr | 22 |
4 files changed, 50 insertions, 1 deletions
diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index c3026e52430..a82f7bdfbf3 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -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); }; diff --git a/tests/ui/privacy/auxiliary/issue-119463-extern.rs b/tests/ui/privacy/auxiliary/issue-119463-extern.rs new file mode 100644 index 00000000000..e703a1fb2c2 --- /dev/null +++ b/tests/ui/privacy/auxiliary/issue-119463-extern.rs @@ -0,0 +1,3 @@ +trait PrivateTrait { + const FOO: usize; +} diff --git a/tests/ui/privacy/issue-119463.rs b/tests/ui/privacy/issue-119463.rs new file mode 100644 index 00000000000..e010bc9f536 --- /dev/null +++ b/tests/ui/privacy/issue-119463.rs @@ -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() {} diff --git a/tests/ui/privacy/issue-119463.stderr b/tests/ui/privacy/issue-119463.stderr new file mode 100644 index 00000000000..4a0684de613 --- /dev/null +++ b/tests/ui/privacy/issue-119463.stderr @@ -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`. |
