Skip to content

Commit 3e3ad66

Browse files
committed
Implement check_attr
1 parent 76c210f commit 3e3ad66

File tree

3 files changed

+57
-2
lines changed

3 files changed

+57
-2
lines changed

compiler/rustc_passes/messages.ftl

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -594,6 +594,10 @@ passes_rustc_allow_const_fn_unstable =
594594
attribute should be applied to `const fn`
595595
.label = not a `const fn`
596596
597+
passes_rustc_unstable_feature_bound =
598+
attribute should be applied to `impl` or free function outside of any `impl` or trait
599+
.label = not an `impl` or free function
600+
597601
passes_rustc_const_stable_indirect_pairing =
598602
`const_stable_indirect` attribute does not make sense on `rustc_const_stable` function, its behavior is already implied
599603
passes_rustc_dirty_clean =

compiler/rustc_passes/src/check_attr.rs

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,8 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
142142
}
143143
Attribute::Parsed(AttributeKind::Repr(_)) => { /* handled below this loop and elsewhere */
144144
}
145-
Attribute::Parsed(AttributeKind::AllowUnstableFeature(_)) => {
146-
// FIXME: handle this later.
145+
Attribute::Parsed(AttributeKind::AllowUnstableFeature(syms)) => {
146+
self.check_unstable_feature_bound(syms.first().unwrap().1, span, target)
147147
}
148148
Attribute::Parsed(
149149
AttributeKind::BodyStability { .. }
@@ -2277,6 +2277,47 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
22772277
}
22782278
}
22792279

2280+
fn check_unstable_feature_bound(&self, attr_span: Span, span: Span, target: Target) {
2281+
match target {
2282+
Target::Fn | Target::Impl => {}
2283+
Target::ExternCrate |
2284+
Target::Use |
2285+
Target::Static |
2286+
Target::Const |
2287+
Target::Closure |
2288+
Target::Mod |
2289+
Target::ForeignMod |
2290+
Target::GlobalAsm |
2291+
Target::TyAlias |
2292+
Target::Enum |
2293+
Target::Variant |
2294+
Target::Struct |
2295+
Target::Field |
2296+
Target::Union |
2297+
Target::Trait |
2298+
Target::TraitAlias |
2299+
Target::Expression |
2300+
Target::Statement |
2301+
Target::Arm |
2302+
Target::AssocConst |
2303+
Target::Method(_) |
2304+
Target::AssocTy |
2305+
Target::ForeignFn |
2306+
Target::ForeignStatic |
2307+
Target::ForeignTy |
2308+
Target::GenericParam(_) |
2309+
Target::MacroDef |
2310+
Target::Param |
2311+
Target::PatField |
2312+
Target::ExprField |
2313+
Target::WherePredicate => {
2314+
self.tcx
2315+
.dcx()
2316+
.emit_err(errors::RustcUnstableFeatureBound{ attr_span, span });
2317+
}
2318+
}
2319+
}
2320+
22802321
fn check_rustc_std_internal_symbol(&self, attr: &Attribute, span: Span, target: Target) {
22812322
match target {
22822323
Target::Fn | Target::Static | Target::ForeignFn | Target::ForeignStatic => {}

compiler/rustc_passes/src/errors.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,16 @@ pub(crate) struct RustcAllowConstFnUnstable {
662662
pub span: Span,
663663
}
664664

665+
#[derive(Diagnostic)]
666+
#[diag(passes_rustc_unstable_feature_bound)]
667+
pub(crate) struct RustcUnstableFeatureBound {
668+
#[primary_span]
669+
pub attr_span: Span,
670+
#[label]
671+
pub span: Span,
672+
}
673+
674+
665675
#[derive(Diagnostic)]
666676
#[diag(passes_rustc_std_internal_symbol)]
667677
pub(crate) struct RustcStdInternalSymbol {

0 commit comments

Comments
 (0)