Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace #[allow_internal_unstable] with #[rustc_allow_const_fn_unstable] for const fns #78208

Merged
merged 7 commits into from
Oct 25, 2020
22 changes: 22 additions & 0 deletions compiler/rustc_passes/src/check_attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
oli-obk marked this conversation as resolved.
Show resolved Hide resolved
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> {
Expand Down