Skip to content

Commit f64daff

Browse files
committed
Fix #[rustc_must_implement_one_of]
This adds the old, pre 90639 `is_implemented` that previously only was true if the implementation of the item was from the given impl block and not from the trait default.
1 parent 96b2f8a commit f64daff

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

compiler/rustc_typeck/src/check/check.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -993,10 +993,16 @@ fn check_impl_items_against_trait<'tcx>(
993993
}
994994

995995
if let Some(required_items) = &must_implement_one_of {
996-
let trait_item = tcx.associated_item(trait_item_id);
997-
998-
if is_implemented && required_items.contains(&trait_item.ident) {
999-
must_implement_one_of = None;
996+
// true if this item is specifically implemented in this impl
997+
let is_implemented_here = ancestors
998+
.leaf_def(tcx, trait_item_id)
999+
.map_or(false, |node_item| !node_item.defining_node.is_from_trait());
1000+
1001+
if is_implemented_here {
1002+
let trait_item = tcx.associated_item(trait_item_id);
1003+
if required_items.contains(&trait_item.ident) {
1004+
must_implement_one_of = None;
1005+
}
10001006
}
10011007
}
10021008
}

0 commit comments

Comments
 (0)