Skip to content

Commit 1597a18

Browse files
committed
port #[move_size_limit] to the new attribute parsing infrastructure
1 parent c601e02 commit 1597a18

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::Error;
104+
const TEMPLATE: AttributeTemplate = template!(NameValueStr: "N");
105+
106+
// FIXME: move size 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(&[Allow(Target::Crate)]);
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};
@@ -181,6 +181,7 @@ attribute_parsers!(
181181
Single<LinkOrdinalParser>,
182182
Single<LinkSectionParser>,
183183
Single<LinkageParser>,
184+
Single<MoveSizeLimitParser>,
184185
Single<MustUseParser>,
185186
Single<OptimizeParser>,
186187
Single<PathAttributeParser>,

compiler/rustc_hir/src/attrs/data_structures.rs

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

568+
/// Represents `#[move_size_limit]`
569+
MoveSizeLimit { attr_span: Span, limit_span: Span, limit: usize },
570+
568571
/// Represents `#[must_use]`.
569572
MustUse {
570573
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
@@ -61,6 +61,7 @@ impl AttributeKind {
6161
MacroUse { .. } => No,
6262
Marker(..) => No,
6363
MayDangle(..) => No,
64+
MoveSizeLimit { .. } => No,
6465
MustUse { .. } => Yes,
6566
Naked(..) => No,
6667
NoImplicitPrelude(..) => No,

compiler/rustc_passes/src/check_attr.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,7 @@ impl<'tcx> CheckAttrVisitor<'tcx> {
271271
| AttributeKind::MustUse { .. }
272272
| AttributeKind::CrateName { .. }
273273
| AttributeKind::RecursionLimit { .. }
274+
| AttributeKind::MoveSizeLimit { .. }
274275
) => { /* do nothing */ }
275276
Attribute::Unparsed(attr_item) => {
276277
style = Some(attr_item.style);

0 commit comments

Comments
 (0)