Skip to content

Commit 1f00265

Browse files
committed
Account for impl/trait difference
1 parent 1493072 commit 1f00265

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

compiler/rustc_trait_selection/src/error_reporting/infer/need_type_info.rs

+11-2
Original file line numberDiff line numberDiff line change
@@ -833,9 +833,18 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
833833

834834
// We're at the `impl` level, but we want to get the same method we
835835
// called *on this `impl`*, in order to get the right DefId and args.
836-
let Some(assoc) = assocs.filter_by_name_unhygienic(name).next() else {
837-
// The method isn't in this `impl`? Not useful to us then.
836+
let assoc = if let Some(assoc) = assocs.filter_by_name_unhygienic(name).next() {
837+
// Method in the `impl`.
838+
assoc
839+
} else {
840+
let assocs = tcx.associated_items(trait_def_id);
841+
if let Some(assoc) = assocs.filter_by_name_unhygienic(name).next() {
842+
// Method in the `trait`.
843+
assoc
844+
} else {
845+
// The method isn't in this `impl` or `trait`? Not useful to us then.
838846
return;
847+
}
839848
};
840849
let Some(trait_assoc_item) = assoc.trait_item_def_id else {
841850
return;

tests/ui/inference/issue-80816.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ LL | impl<T, A: Access<T>, P: Deref<Target = A>> Access<T> for P {
2121
| unsatisfied trait bound introduced here
2222
help: try using a fully qualified path to specify the expected types
2323
|
24-
LL | let guard: Guard<Arc<usize>> = <Arc<ArcSwapAny<Arc<usize>>> as Access<T>>::load(&s);
25-
| ++++++++++++++++++++++++++++++++++++++++++++++++++ ~
24+
LL | let guard: Guard<Arc<usize>> = <_ as Access<_>>::load(&s);
25+
| ++++++++++++++++++++++++ ~
2626

2727
error: aborting due to 1 previous error
2828

0 commit comments

Comments
 (0)