Skip to content

Commit 3399405

Browse files
committed
port #[move_size_limit] to the new attribute parsing infrastructure
1 parent 762ccfb commit 3399405

File tree

5 files changed

+33
-1
lines changed

5 files changed

+33
-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
@@ -94,3 +94,29 @@ impl<S: Stage> SingleAttributeParser<S> for RecursionLimitParser {
9494
})
9595
}
9696
}
97+
98+
pub(crate) struct MoveSizeLimitParser;
99+
100+
impl<S: Stage> SingleAttributeParser<S> for MoveSizeLimitParser {
101+
const PATH: &[Symbol] = &[sym::move_size_limit];
102+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepOutermost;
103+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
104+
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "N");
105+
106+
// FIXME: recursion limit is allowed on all targets and ignored,
107+
// even though it should only be valid on crates of course
108+
const ALLOWED_TARGETS: AllowedTargets = AllowedTargets::AllowList(ALL_TARGETS);
109+
110+
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
111+
let ArgParser::NameValue(nv) = args else {
112+
cx.expected_name_value(cx.attr_span, None);
113+
return None;
114+
};
115+
116+
Some(AttributeKind::MoveSizeLimit {
117+
limit: cx.parse_limit_int(nv)?,
118+
attr_span: cx.attr_span,
119+
limit_span: nv.value_span,
120+
})
121+
}
122+
}

compiler/rustc_attr_parsing/src/context.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use crate::attributes::codegen_attrs::{
2424
UsedParser,
2525
};
2626
use crate::attributes::confusables::ConfusablesParser;
27-
use crate::attributes::crate_level::{CrateNameParser, RecursionLimitParser};
27+
use crate::attributes::crate_level::{CrateNameParser, MoveSizeLimitParser, RecursionLimitParser};
2828
use crate::attributes::deprecation::DeprecationParser;
2929
use crate::attributes::dummy::DummyParser;
3030
use crate::attributes::inline::{InlineParser, RustcForceInlineParser};
@@ -180,6 +180,7 @@ attribute_parsers!(
180180
Single<LinkOrdinalParser>,
181181
Single<LinkSectionParser>,
182182
Single<LinkageParser>,
183+
Single<MoveSizeLimitParser>,
183184
Single<MustUseParser>,
184185
Single<OptimizeParser>,
185186
Single<PathAttributeParser>,

compiler/rustc_hir/src/attrs/data_structures.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,9 @@ pub enum AttributeKind {
448448
/// Represents [`#[may_dangle]`](https://std-dev-guide.rust-lang.org/tricky/may-dangle.html).
449449
MayDangle(Span),
450450

451+
/// Represents `#[move_size_limit]`
452+
MoveSizeLimit { attr_span: Span, limit_span: Span, limit: usize },
453+
451454
/// Represents `#[must_use]`.
452455
MustUse {
453456
span: Span,

compiler/rustc_hir/src/attrs/encode_cross_crate.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ impl AttributeKind {
6060
MacroUse { .. } => No,
6161
Marker(..) => No,
6262
MayDangle(..) => No,
63+
MoveSizeLimit { .. } => No,
6364
MustUse { .. } => Yes,
6465
Naked(..) => No,
6566
NoImplicitPrelude(..) => No,

compiler/rustc_passes/src/check_attr.rs

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

0 commit comments

Comments
 (0)