Skip to content

Commit 55ba739

Browse files
committed
port #[type_length_limit] to the new attribute parsing infrastructure
1 parent 0309487 commit 55ba739

File tree

5 files changed

+35
-1
lines changed

5 files changed

+35
-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
@@ -118,3 +118,29 @@ impl<S: Stage> SingleAttributeParser<S> for MoveSizeLimitParser {
118118
})
119119
}
120120
}
121+
122+
pub(crate) struct TypeLengthLimitParser;
123+
124+
impl<S: Stage> SingleAttributeParser<S> for TypeLengthLimitParser {
125+
const PATH: &[Symbol] = &[sym::type_length_limit];
126+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
127+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
128+
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "N");
129+
130+
// FIXME: recursion limit is allowed on all targets and ignored,
131+
// even though it should only be valid on crates of course
132+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS);
133+
134+
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
135+
let ArgParser::NameValue(nv) = args else {
136+
cx.expected_name_value(cx.attr_span, None);
137+
return None;
138+
};
139+
140+
Some(AttributeKind::TypeLengthLimit {
141+
limit: cx.parse_limit_int(nv)?,
142+
attr_span: cx.attr_span,
143+
limit_span: nv.value_span,
144+
})
145+
}
146+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ use crate::attributes::codegen_attrs::{
2424
UsedParser,
2525
};
2626
use crate::attributes::confusables::ConfusablesParser;
27-
use crate::attributes::crate_level::{CrateNameParser, MoveSizeLimitParser, RecursionLimitParser};
27+
use crate::attributes::crate_level::{
28+
CrateNameParser, MoveSizeLimitParser, RecursionLimitParser, TypeLengthLimitParser,
29+
};
2830
use crate::attributes::deprecation::DeprecationParser;
2931
use crate::attributes::dummy::DummyParser;
3032
use crate::attributes::inline::{InlineParser, RustcForceInlineParser};
@@ -193,6 +195,7 @@ attribute_parsers!(
193195
Single<ShouldPanicParser>,
194196
Single<SkipDuringMethodDispatchParser>,
195197
Single<TransparencyParser>,
198+
Single<TypeLengthLimitParser>,
196199
Single<WithoutArgs<AllowIncoherentImplParser>>,
197200
Single<WithoutArgs<AllowInternalUnsafeParser>>,
198201
Single<WithoutArgs<AsPtrParser>>,

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -550,6 +550,9 @@ pub enum AttributeKind {
550550
/// Represents `#[type_const]`.
551551
TypeConst(Span),
552552

553+
/// Represents `#[type_length_limit]`
554+
TypeLengthLimit { attr_span: Span, limit_span: Span, limit: usize },
555+
553556
/// Represents `#[rustc_unsafe_specialization_marker]`.
554557
UnsafeSpecializationMarker(Span),
555558

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ impl AttributeKind {
9090
TargetFeature { .. } => No,
9191
TrackCaller(..) => Yes,
9292
TypeConst(..) => Yes,
93+
TypeLengthLimit { .. } => Yes,
9394
UnsafeSpecializationMarker(..) => No,
9495
UnstableFeatureBound(..) => No,
9596
Used { .. } => No,

compiler/rustc_passes/src/check_attr.rs

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

0 commit comments

Comments
 (0)