port #[pattern_complexity_limit] to the new attribute parsing infrastructure
This commit is contained in:
parent
5dbe099dd3
commit
b82171de5f
5 changed files with 35 additions and 1 deletions
|
|
@ -147,3 +147,30 @@ impl<S: Stage> SingleAttributeParser<S> for TypeLengthLimitParser {
|
|||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct PatternComplexityLimitParser;
|
||||
|
||||
impl<S: Stage> SingleAttributeParser<S> for PatternComplexityLimitParser {
|
||||
const PATH: &[Symbol] = &[sym::pattern_complexity_limit];
|
||||
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
|
||||
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::Error;
|
||||
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "N");
|
||||
const TYPE: AttributeType = AttributeType::CrateLevel;
|
||||
|
||||
// FIXME: recursion limit is allowed on all targets and ignored,
|
||||
// even though it should only be valid on crates of course
|
||||
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(&[Allow(Target::Crate)]);
|
||||
|
||||
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
|
||||
let ArgParser::NameValue(nv) = args else {
|
||||
cx.expected_name_value(cx.attr_span, None);
|
||||
return None;
|
||||
};
|
||||
|
||||
Some(AttributeKind::PatternComplexityLimit {
|
||||
limit: cx.parse_limit_int(nv)?,
|
||||
attr_span: cx.attr_span,
|
||||
limit_span: nv.value_span,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,8 @@ use crate::attributes::codegen_attrs::{
|
|||
};
|
||||
use crate::attributes::confusables::ConfusablesParser;
|
||||
use crate::attributes::crate_level::{
|
||||
CrateNameParser, MoveSizeLimitParser, RecursionLimitParser, TypeLengthLimitParser,
|
||||
CrateNameParser, MoveSizeLimitParser, PatternComplexityLimitParser, RecursionLimitParser,
|
||||
TypeLengthLimitParser,
|
||||
};
|
||||
use crate::attributes::deprecation::DeprecationParser;
|
||||
use crate::attributes::dummy::DummyParser;
|
||||
|
|
@ -187,6 +188,7 @@ attribute_parsers!(
|
|||
Single<MustUseParser>,
|
||||
Single<OptimizeParser>,
|
||||
Single<PathAttributeParser>,
|
||||
Single<PatternComplexityLimitParser>,
|
||||
Single<ProcMacroDeriveParser>,
|
||||
Single<RecursionLimitParser>,
|
||||
Single<RustcBuiltinMacroParser>,
|
||||
|
|
|
|||
|
|
@ -599,6 +599,9 @@ pub enum AttributeKind {
|
|||
/// Represents `#[path]`
|
||||
Path(Symbol, Span),
|
||||
|
||||
/// Represents `#[pattern_complexity_limit]`
|
||||
PatternComplexityLimit { attr_span: Span, limit_span: Span, limit: usize },
|
||||
|
||||
/// Represents `#[pointee]`
|
||||
Pointee(Span),
|
||||
|
||||
|
|
|
|||
|
|
@ -71,6 +71,7 @@ impl AttributeKind {
|
|||
ParenSugar(..) => No,
|
||||
PassByValue(..) => Yes,
|
||||
Path(..) => No,
|
||||
PatternComplexityLimit { .. } => No,
|
||||
Pointee(..) => No,
|
||||
ProcMacro(..) => No,
|
||||
ProcMacroAttribute(..) => No,
|
||||
|
|
|
|||
|
|
@ -273,6 +273,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
|
|||
| AttributeKind::RecursionLimit { .. }
|
||||
| AttributeKind::MoveSizeLimit { .. }
|
||||
| AttributeKind::TypeLengthLimit { .. }
|
||||
| AttributeKind::PatternComplexityLimit { .. }
|
||||
) => { /* do nothing */ }
|
||||
Attribute::Unparsed(attr_item) => {
|
||||
style = Some(attr_item.style);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue