about summary refs log tree commit diff
diff options
context:
space:
mode:
authorMaybe Waffle <waffle.lapkin@gmail.com>2022-01-10 12:54:04 +0300
committerMaybe Waffle <waffle.lapkin@gmail.com>2022-01-10 12:54:04 +0300
commitf64daff0c6e400819c997c888ac2aca32168dd53 (patch)
tree4fe3597f747347683484caea1a4d80d5fa5229df
parent96b2f8ac3268f0aee4d10868f9e31a5f7b66641b (diff)
downloadrust-f64daff0c6e400819c997c888ac2aca32168dd53.tar.gz
rust-f64daff0c6e400819c997c888ac2aca32168dd53.zip
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.
-rw-r--r--compiler/rustc_typeck/src/check/check.rs14
1 files changed, 10 insertions, 4 deletions
diff --git a/compiler/rustc_typeck/src/check/check.rs b/compiler/rustc_typeck/src/check/check.rs
index ff103159566..a49c6bd2e80 100644
--- a/compiler/rustc_typeck/src/check/check.rs
+++ b/compiler/rustc_typeck/src/check/check.rs
@@ -993,10 +993,16 @@ fn check_impl_items_against_trait<'tcx>(
             }
 
             if let Some(required_items) = &must_implement_one_of {
-                let trait_item = tcx.associated_item(trait_item_id);
-
-                if is_implemented && required_items.contains(&trait_item.ident) {
-                    must_implement_one_of = None;
+                // true if this item is specifically implemented in this impl
+                let is_implemented_here = ancestors
+                    .leaf_def(tcx, trait_item_id)
+                    .map_or(false, |node_item| !node_item.defining_node.is_from_trait());
+
+                if is_implemented_here {
+                    let trait_item = tcx.associated_item(trait_item_id);
+                    if required_items.contains(&trait_item.ident) {
+                        must_implement_one_of = None;
+                    }
                 }
             }
         }