Skip to content

Commit 41228d5

Browse files
Rollup merge of rust-lang#119134 - petrochenkov:feedvis2, r=compiler-errors
resolve: Feed visibilities for unresolved trait impl items Fixes rust-lang#119073
2 parents f06ab92 + 7571f6f commit 41228d5

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

compiler/rustc_resolve/src/late.rs

+8-2
Original file line numberDiff line numberDiff line change
@@ -3078,17 +3078,25 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
30783078
binding = self.r.resolution(module, key).try_borrow().ok().and_then(|r| r.binding);
30793079
debug!(?binding);
30803080
}
3081+
3082+
let feed_visibility = |this: &mut Self, def_id| {
3083+
let vis = this.r.tcx.visibility(def_id).expect_local();
3084+
this.r.feed_visibility(this.r.local_def_id(id), vis);
3085+
};
3086+
30813087
let Some(binding) = binding else {
30823088
// We could not find the method: report an error.
30833089
let candidate = self.find_similarly_named_assoc_item(ident.name, kind);
30843090
let path = &self.current_trait_ref.as_ref().unwrap().1.path;
30853091
let path_names = path_names_to_string(path);
30863092
self.report_error(span, err(ident, path_names, candidate));
3093+
feed_visibility(self, module.def_id());
30873094
return;
30883095
};
30893096

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

30933101
match seen_trait_items.entry(id_in_trait) {
30943102
Entry::Occupied(entry) => {
@@ -3112,8 +3120,6 @@ impl<'a: 'ast, 'b, 'ast, 'tcx> LateResolutionVisitor<'a, 'b, 'ast, 'tcx> {
31123120
| (DefKind::AssocFn, AssocItemKind::Fn(..))
31133121
| (DefKind::AssocConst, AssocItemKind::Const(..)) => {
31143122
self.r.record_partial_res(id, PartialRes::new(res));
3115-
let vis = self.r.tcx.visibility(id_in_trait).expect_local();
3116-
self.r.feed_visibility(self.r.local_def_id(id), vis);
31173123
return;
31183124
}
31193125
_ => {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// edition:2018
2+
3+
trait MyTrait {
4+
async fn resolved(&self);
5+
const RESOLVED_WRONG: u8 = 0;
6+
}
7+
8+
impl MyTrait for i32 {
9+
async fn resolved(&self) {}
10+
11+
async fn unresolved(&self) {} //~ ERROR method `unresolved` is not a member of trait `MyTrait`
12+
async fn RESOLVED_WRONG() {} //~ ERROR doesn't match its trait `MyTrait`
13+
}
14+
15+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
error[E0407]: method `unresolved` is not a member of trait `MyTrait`
2+
--> $DIR/unresolved-trait-impl-item.rs:11:5
3+
|
4+
LL | async fn unresolved(&self) {}
5+
| ^^^^^^^^^----------^^^^^^^^^^
6+
| | |
7+
| | help: there is an associated function with a similar name: `resolved`
8+
| not a member of trait `MyTrait`
9+
10+
error[E0324]: item `RESOLVED_WRONG` is an associated method, which doesn't match its trait `MyTrait`
11+
--> $DIR/unresolved-trait-impl-item.rs:12:5
12+
|
13+
LL | const RESOLVED_WRONG: u8 = 0;
14+
| ----------------------------- item in trait
15+
...
16+
LL | async fn RESOLVED_WRONG() {}
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ does not match trait
18+
19+
error: aborting due to 2 previous errors
20+
21+
Some errors have detailed explanations: E0324, E0407.
22+
For more information about an error, try `rustc --explain E0324`.

0 commit comments

Comments
 (0)