Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 03e63d3

Browse files
committedJun 20, 2025·
Auto merge of #142762 - tgross35:rollup-wi1rum8, r=tgross35
Rollup of 8 pull requests Successful merges: - #138291 (rewrite `optimize` attribute to use new attribute parsing infrastructure) - #140920 (Extract some shared code from codegen backend target feature handling) - #141990 (Implement send_signal for unix child processes) - #142597 (error on calls to ABIs that cannot be called) - #142668 (vec_deque/fmt/vec tests: remove static mut) - #142687 (Reduce uses of `hir_crate`.) - #142699 (Update books) - #142714 (add comment to `src/bootstrap/build.rs`) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 5b74275 + 8e4d77f commit 03e63d3

File tree

96 files changed

+2211
-1277
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

96 files changed

+2211
-1277
lines changed
 

‎compiler/rustc_attr_data_structures/src/attributes.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ pub enum InstructionSetAttr {
3838
ArmT32,
3939
}
4040

41-
#[derive(Clone, Encodable, Decodable, Debug, PartialEq, Eq, HashStable_Generic, Default)]
41+
#[derive(Copy, Clone, Debug, PartialEq, Eq, Default, PrintAttribute)]
42+
#[derive(Encodable, Decodable, HashStable_Generic)]
4243
pub enum OptimizeAttr {
4344
/// No `#[optimize(..)]` attribute
4445
#[default]
@@ -229,7 +230,8 @@ pub enum AttributeKind {
229230

230231
/// Represents `#[rustc_macro_transparency]`.
231232
MacroTransparency(Transparency),
232-
233+
/// Represents `#[optimize(size|speed)]`
234+
Optimize(OptimizeAttr, Span),
233235
/// Represents [`#[repr]`](https://doc.rust-lang.org/stable/reference/type-layout.html#representations).
234236
Repr(ThinVec<(ReprAttr, Span)>),
235237

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
use rustc_attr_data_structures::{AttributeKind, OptimizeAttr};
2+
use rustc_feature::{AttributeTemplate, template};
3+
use rustc_span::sym;
4+
5+
use super::{AttributeOrder, OnDuplicate, SingleAttributeParser};
6+
use crate::context::{AcceptContext, Stage};
7+
use crate::parser::ArgParser;
8+
9+
pub(crate) struct OptimizeParser;
10+
11+
impl<S: Stage> SingleAttributeParser<S> for OptimizeParser {
12+
const PATH: &[rustc_span::Symbol] = &[sym::optimize];
13+
const ATTRIBUTE_ORDER: AttributeOrder = AttributeOrder::KeepLast;
14+
const ON_DUPLICATE: OnDuplicate<S> = OnDuplicate::WarnButFutureError;
15+
const TEMPLATE: AttributeTemplate = template!(List: "size|speed|none");
16+
17+
fn convert(cx: &mut AcceptContext<'_, '_, S>, args: &ArgParser<'_>) -> Option<AttributeKind> {
18+
let Some(list) = args.list() else {
19+
cx.expected_list(cx.attr_span);
20+
return None;
21+
};
22+
23+
let Some(single) = list.single() else {
24+
cx.expected_single_argument(list.span);
25+
return None;
26+
};
27+
28+
let res = match single.meta_item().and_then(|i| i.path().word().map(|i| i.name)) {
29+
Some(sym::size) => OptimizeAttr::Size,
30+
Some(sym::speed) => OptimizeAttr::Speed,
31+
Some(sym::none) => OptimizeAttr::DoNotOptimize,
32+
_ => {
33+
cx.expected_specific_argument(single.span(), vec!["size", "speed", "none"]);
34+
OptimizeAttr::Default
35+
}
36+
};
37+
38+
Some(AttributeKind::Optimize(res, cx.attr_span))
39+
}
40+
}

0 commit comments

Comments
 (0)
Please sign in to comment.