Skip to content

Commit 9c1b104

Browse files
committed
port #[pattern_complexity_limit] to the new attribute parsing infrastructure
1 parent 55ba739 commit 9c1b104

File tree

5 files changed

+34
-1
lines changed

5 files changed

+34
-1
lines changed

compiler/rustc_attr_parsing/src/attributes/crate_level.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,3 +144,29 @@ impl<S: Stage> SingleAttributeParser<S> for TypeLengthLimitParser {
144144
})
145145
}
146146
}
147+
148+
pub(crate) struct PatternComplexityLimitParser;
149+
150+
impl<S: Stage> SingleAttributeParser<S> for PatternComplexityLimitParser {
151+
const PATH: &[Symbol] = &[sym::pattern_complexity_limit];
152+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
153+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
154+
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "N");
155+
156+
// FIXME: recursion limit is allowed on all targets and ignored,
157+
// even though it should only be valid on crates of course
158+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS);
159+
160+
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
161+
let ArgParser::NameValue(nv) = args else {
162+
cx.expected_name_value(cx.attr_span, None);
163+
return None;
164+
};
165+
166+
Some(AttributeKind::PatternComplexityLimit {
167+
limit: cx.parse_limit_int(nv)?,
168+
attr_span: cx.attr_span,
169+
limit_span: nv.value_span,
170+
})
171+
}
172+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ use crate::attributes::codegen_attrs::{
2525
};
2626
use crate::attributes::confusables::ConfusablesParser;
2727
use crate::attributes::crate_level::{
28-
CrateNameParser, MoveSizeLimitParser, RecursionLimitParser, TypeLengthLimitParser,
28+
CrateNameParser, MoveSizeLimitParser, PatternComplexityLimitParser, RecursionLimitParser,
29+
TypeLengthLimitParser,
2930
};
3031
use crate::attributes::deprecation::DeprecationParser;
3132
use crate::attributes::dummy::DummyParser;
@@ -184,6 +185,7 @@ attribute_parsers!(
184185
Single<MustUseParser>,
185186
Single<OptimizeParser>,
186187
Single<PathAttributeParser>,
188+
Single<PatternComplexityLimitParser>,
187189
Single<ProcMacroDeriveParser>,
188190
Single<RecursionLimitParser>,
189191
Single<RustcBuiltinMacroParser>,

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,9 @@ pub enum AttributeKind {
482482
/// Represents `#[path]`
483483
Path(Symbol, Span),
484484

485+
/// Represents `#[pattern_complexity_limit]`
486+
PatternComplexityLimit { attr_span: Span, limit_span: Span, limit: usize },
487+
485488
/// Represents `#[pointee]`
486489
Pointee(Span),
487490

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ impl AttributeKind {
7070
ParenSugar(..) => No,
7171
PassByValue(..) => Yes,
7272
Path(..) => No,
73+
PatternComplexityLimit { .. } => No,
7374
Pointee(..) => No,
7475
ProcMacro(..) => No,
7576
ProcMacroAttribute(..) => No,

compiler/rustc_passes/src/check_attr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
255255
| AttributeKind::RecursionLimit { .. }
256256
| AttributeKind::MoveSizeLimit { .. }
257257
| AttributeKind::TypeLengthLimit { .. }
258+
| AttributeKind::PatternComplexityLimit { .. }
258259
) => { /* do nothing */ }
259260
Attribute::Unparsed(attr_item) => {
260261
style = Some(attr_item.style);

0 commit comments

Comments
 (0)