about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDeadbeef <ent3rm4n@gmail.com>2021-07-04 23:50:34 +0800
committerDeadbeef <ent3rm4n@gmail.com>2021-07-10 20:54:47 +0800
commit3660a4e97259a23b9a24c30aa097932ae6f0eb18 (patch)
treed740a6fdc515c949256ab1798ad06bb0f322b387
parent2db927d8d82260759e4aaa183dbebd0adbb00177 (diff)
downloadrust-3660a4e97259a23b9a24c30aa097932ae6f0eb18.tar.gz
rust-3660a4e97259a23b9a24c30aa097932ae6f0eb18.zip
Applied suggestions
-rw-r--r--compiler/rustc_feature/src/builtin_attrs.rs11
-rw-r--r--compiler/rustc_passes/src/check_const.rs17
2 files changed, 12 insertions, 16 deletions
diff --git a/compiler/rustc_feature/src/builtin_attrs.rs b/compiler/rustc_feature/src/builtin_attrs.rs
index dbdc14dced8..24a5a007ded 100644
--- a/compiler/rustc_feature/src/builtin_attrs.rs
+++ b/compiler/rustc_feature/src/builtin_attrs.rs
@@ -349,6 +349,12 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
     ),
 
     gated!(cmse_nonsecure_entry, AssumedUsed, template!(Word), experimental!(cmse_nonsecure_entry)),
+    // RFC 2632
+    gated!(
+        default_method_body_is_const, AssumedUsed, template!(Word), const_trait_impl,
+        "`default_method_body_is_const` is a temporary placeholder for declaring default bodies \
+        as `const`, which may be removed or renamed in the future."
+    ),
 
     // ==========================================================================
     // Internal attributes: Stability, deprecation, and unsafe:
@@ -470,11 +476,6 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
 
     rustc_attr!(rustc_promotable, AssumedUsed, template!(Word), IMPL_DETAIL),
     rustc_attr!(rustc_legacy_const_generics, AssumedUsed, template!(List: "N"), INTERNAL_UNSTABLE),
-    gated!(
-        default_method_body_is_const, AssumedUsed, template!(Word), const_trait_impl,
-        "the `#[default_method_body_is_const]` attribute marks a default method of a trait \
-        as const, so it does not need to be duplicated by a const impl."
-    ),
 
     // ==========================================================================
     // Internal attributes, Layout related:
diff --git a/compiler/rustc_passes/src/check_const.rs b/compiler/rustc_passes/src/check_const.rs
index eaeec19eb31..6ee54cfe37f 100644
--- a/compiler/rustc_passes/src/check_const.rs
+++ b/compiler/rustc_passes/src/check_const.rs
@@ -93,17 +93,12 @@ impl<'tcx> hir::itemlikevisit::ItemLikeVisitor<'tcx> for CheckConstTraitVisitor<
                             kind: ty::AssocKind::Fn, ident, defaultness, ..
                         } = self.tcx.associated_item(*did)
                         {
-                            match (
-                                self.tcx.has_attr(*did, sym::default_method_body_is_const),
-                                defaultness.has_value(),
-                            ) {
-                                (false, true) => {
-                                    to_implement.insert(ident);
-                                }
-                                // ignore functions that do not have default bodies
-                                // if those are unimplemented it will be catched by
-                                // typeck.
-                                _ => {}
+                            // we can ignore functions that do not have default bodies:
+                            // if those are unimplemented it will be catched by typeck.
+                            if defaultness.has_value()
+                                && !self.tcx.has_attr(*did, sym::default_method_body_is_const)
+                            {
+                                to_implement.insert(ident);
                             }
                         }
                     }