about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFlorian Warzecha <liketechnik@disroot.org>2020-10-23 17:54:48 +0200
committerFlorian Warzecha <liketechnik@disroot.org>2020-10-23 17:54:48 +0200
commitac2c599f23d6c8b5d3413febde4c6febff68062e (patch)
tree1427f2565aaee12ec3031602e51e33af1faa96f5
parent13b481b247fe472ccf75b4fb13f3a46ac8f9ecaf (diff)
downloadrust-ac2c599f23d6c8b5d3413febde4c6febff68062e.tar.gz
rust-ac2c599f23d6c8b5d3413febde4c6febff68062e.zip
fix validation for rustc_allow_const_fn_unstable targets
The validation was introduced in 3a63bf02998f7b5e040a4b87e049d03ddd144f74
without strict validation of functions, e. g. all function types were
allowed.
Now the validation only allows `const fn`s.
-rw-r--r--compiler/rustc_passes/src/check_attr.rs8
1 files changed, 5 insertions, 3 deletions
diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs
index d6936ae942c..920c69cb619 100644
--- a/compiler/rustc_passes/src/check_attr.rs
+++ b/compiler/rustc_passes/src/check_attr.rs
@@ -88,7 +88,7 @@ impl CheckAttrVisitor<'tcx> {
             } else if self.tcx.sess.check_name(attr, sym::allow_internal_unstable) {
                 self.check_allow_internal_unstable(&attr, span, target, &attrs)
             } else if self.tcx.sess.check_name(attr, sym::rustc_allow_const_fn_unstable) {
-                self.check_rustc_allow_const_fn_unstable(&attr, span, target)
+                self.check_rustc_allow_const_fn_unstable(hir_id, &attr, span, target)
             } else {
                 // lint-only checks
                 if self.tcx.sess.check_name(attr, sym::cold) {
@@ -798,13 +798,15 @@ impl CheckAttrVisitor<'tcx> {
     /// (Allows proc_macro functions)
     fn check_rustc_allow_const_fn_unstable(
         &self,
+        hir_id: HirId,
         attr: &Attribute,
         span: &Span,
         target: Target,
     ) -> bool {
         if let Target::Fn | Target::Method(_) = target {
-            // FIXME Check that this isn't just a function, but a const fn
-            return true;
+            if self.tcx.is_const_fn_raw(self.tcx.hir().local_def_id(hir_id)) {
+                return true;
+            }
         }
         self.tcx
             .sess