diff options
| author | Florian Warzecha <liketechnik@disroot.org> | 2020-10-22 00:02:26 +0200 |
|---|---|---|
| committer | Florian Warzecha <liketechnik@disroot.org> | 2020-10-22 00:02:26 +0200 |
| commit | 3a63bf02998f7b5e040a4b87e049d03ddd144f74 (patch) | |
| tree | b240a2332a42c0ead1ca5fa9e2731835f645bef5 | |
| parent | 7258740509877ff97c32c52cea7ac236ba80c51a (diff) | |
| download | rust-3a63bf02998f7b5e040a4b87e049d03ddd144f74.tar.gz rust-3a63bf02998f7b5e040a4b87e049d03ddd144f74.zip | |
validate rustc_allow_const_fn_unstable targets
Adds a check to make sure `#[rustc_allow_const_fn_unstable]` can be applied only to functions.
| -rw-r--r-- | compiler/rustc_passes/src/check_attr.rs | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 95e6cc3b863..d6936ae942c 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -87,6 +87,8 @@ impl CheckAttrVisitor<'tcx> { self.check_rustc_args_required_const(&attr, span, target, item) } 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) } else { // lint-only checks if self.tcx.sess.check_name(attr, sym::cold) { @@ -791,6 +793,26 @@ impl CheckAttrVisitor<'tcx> { .emit(); false } + + /// Outputs an error for `#[allow_internal_unstable]` which can only be applied to macros. + /// (Allows proc_macro functions) + fn check_rustc_allow_const_fn_unstable( + &self, + 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; + } + self.tcx + .sess + .struct_span_err(attr.span, "attribute should be applied to `const fn`") + .span_label(*span, "not a `const fn`") + .emit(); + false + } } impl Visitor<'tcx> for CheckAttrVisitor<'tcx> { |
