validate rustc_allow_const_fn_unstable targets
Adds a check to make sure `#[rustc_allow_const_fn_unstable]` can be applied only to functions.
This commit is contained in:
parent
7258740509
commit
3a63bf0299
1 changed files with 22 additions and 0 deletions
|
@ -87,6 +87,8 @@ impl CheckAttrVisitor<'tcx> {
|
||||||
self.check_rustc_args_required_const(&attr, span, target, item)
|
self.check_rustc_args_required_const(&attr, span, target, item)
|
||||||
} else if self.tcx.sess.check_name(attr, sym::allow_internal_unstable) {
|
} else if self.tcx.sess.check_name(attr, sym::allow_internal_unstable) {
|
||||||
self.check_allow_internal_unstable(&attr, span, target, &attrs)
|
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 {
|
} else {
|
||||||
// lint-only checks
|
// lint-only checks
|
||||||
if self.tcx.sess.check_name(attr, sym::cold) {
|
if self.tcx.sess.check_name(attr, sym::cold) {
|
||||||
|
@ -791,6 +793,26 @@ impl CheckAttrVisitor<'tcx> {
|
||||||
.emit();
|
.emit();
|
||||||
false
|
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> {
|
impl Visitor<'tcx> for CheckAttrVisitor<'tcx> {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue