Skip to content

Commit 08edee8

Browse files
authored
Unrolled build for rust-lang#119553
Rollup merge of rust-lang#119553 - bvanjoi:fix-119463, r=petrochenkov stop feed vis when cant access for trait item Fixes rust-lang#119463 It's not necessary to feed visibility when use a private trait. r? ``@petrochenkov``
2 parents 090d5ea + 862368d commit 08edee8

File tree

4 files changed

+50
-1
lines changed

4 files changed

+50
-1
lines changed

compiler/rustc_resolve/src/late.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -3076,7 +3076,16 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
30763076
}
30773077

30783078
let feed_visibility = |this: &mut Self, def_id| {
3079-
let vis = this.r.tcx.visibility(def_id).expect_local();
3079+
let vis = this.r.tcx.visibility(def_id);
3080+
let vis = if vis.is_visible_locally() {
3081+
vis.expect_local()
3082+
} else {
3083+
this.r.dcx().span_delayed_bug(
3084+
span,
3085+
"error should be emitted when an unexpected trait item is used",
3086+
);
3087+
rustc_middle::ty::Visibility::Public
3088+
};
30803089
this.r.feed_visibility(this.r.local_def_id(id), vis);
30813090
};
30823091

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
trait PrivateTrait {
2+
const FOO: usize;
3+
}

tests/ui/privacy/issue-119463.rs

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// aux-build:issue-119463-extern.rs
2+
3+
extern crate issue_119463_extern;
4+
5+
struct S;
6+
7+
impl issue_119463_extern::PrivateTrait for S {
8+
//~^ ERROR: trait `PrivateTrait` is private
9+
const FOO: usize = 1;
10+
11+
fn nonexistent() {}
12+
//~^ ERROR: method `nonexistent` is not a member of trait
13+
}
14+
15+
fn main() {}

tests/ui/privacy/issue-119463.stderr

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error[E0407]: method `nonexistent` is not a member of trait `issue_119463_extern::PrivateTrait`
2+
--> $DIR/issue-119463.rs:11:5
3+
|
4+
LL | fn nonexistent() {}
5+
| ^^^^^^^^^^^^^^^^^^^ not a member of trait `issue_119463_extern::PrivateTrait`
6+
7+
error[E0603]: trait `PrivateTrait` is private
8+
--> $DIR/issue-119463.rs:7:27
9+
|
10+
LL | impl issue_119463_extern::PrivateTrait for S {
11+
| ^^^^^^^^^^^^ private trait
12+
|
13+
note: the trait `PrivateTrait` is defined here
14+
--> $DIR/auxiliary/issue-119463-extern.rs:1:1
15+
|
16+
LL | trait PrivateTrait {
17+
| ^^^^^^^^^^^^^^^^^^
18+
19+
error: aborting due to 2 previous errors
20+
21+
Some errors have detailed explanations: E0407, E0603.
22+
For more information about an error, try `rustc --explain E0407`.

0 commit comments

Comments
 (0)