Skip to content

Commit 50bd08b

Browse files
committed
Refactor fmt::Arguments to just two pointers in size.
1 parent e02ed64 commit 50bd08b

File tree

10 files changed

+696
-392
lines changed

10 files changed

+696
-392
lines changed

compiler/rustc_ast/src/format.rs

+7
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,13 @@ impl FormatArgumentKind {
160160
&Self::Captured(id) => Some(id),
161161
}
162162
}
163+
164+
pub fn is_captured(&self) -> bool {
165+
match self {
166+
Self::Captured(_) => true,
167+
_ => false,
168+
}
169+
}
163170
}
164171

165172
#[derive(Clone, Encodable, Decodable, Debug, PartialEq, Eq)]

compiler/rustc_ast_lowering/messages.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ ast_lowering_template_modifier = template modifier
175175
176176
ast_lowering_this_not_async = this is not `async`
177177
178+
ast_lowering_too_many_format_arguments =
179+
too many arguments used in format string
180+
178181
ast_lowering_underscore_array_length_unstable =
179182
using `_` for array lengths is unstable
180183

compiler/rustc_ast_lowering/src/errors.rs

+7
Original file line numberDiff line numberDiff line change
@@ -467,3 +467,10 @@ pub(crate) struct UseConstGenericArg {
467467
#[suggestion_part(code = "{other_args}")]
468468
pub call_args: Span,
469469
}
470+
471+
#[derive(Diagnostic)]
472+
#[diag(ast_lowering_too_many_format_arguments)]
473+
pub(crate) struct TooManyFormatArguments {
474+
#[primary_span]
475+
pub span: Span,
476+
}

compiler/rustc_ast_lowering/src/expr.rs

+21-5
Original file line numberDiff line numberDiff line change
@@ -2129,12 +2129,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
21292129
self.arena.alloc(self.expr(sp, hir::ExprKind::Tup(&[])))
21302130
}
21312131

2132-
pub(super) fn expr_usize(&mut self, sp: Span, value: usize) -> hir::Expr<'hir> {
2132+
pub(super) fn expr_u64(&mut self, sp: Span, value: u64) -> hir::Expr<'hir> {
21332133
let lit = self.arena.alloc(hir::Lit {
21342134
span: sp,
21352135
node: ast::LitKind::Int(
2136-
(value as u128).into(),
2137-
ast::LitIntType::Unsigned(ast::UintTy::Usize),
2136+
u128::from(value).into(),
2137+
ast::LitIntType::Unsigned(ast::UintTy::U64),
21382138
),
21392139
});
21402140
self.expr(sp, hir::ExprKind::Lit(lit))
@@ -2151,12 +2151,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
21512151
self.expr(sp, hir::ExprKind::Lit(lit))
21522152
}
21532153

2154-
pub(super) fn expr_u16(&mut self, sp: Span, value: u16) -> hir::Expr<'hir> {
2154+
pub(super) fn expr_usize(&mut self, sp: Span, value: u16) -> hir::Expr<'hir> {
21552155
let lit = self.arena.alloc(hir::Lit {
21562156
span: sp,
21572157
node: ast::LitKind::Int(
21582158
u128::from(value).into(),
2159-
ast::LitIntType::Unsigned(ast::UintTy::U16),
2159+
ast::LitIntType::Unsigned(ast::UintTy::Usize),
21602160
),
21612161
});
21622162
self.expr(sp, hir::ExprKind::Lit(lit))
@@ -2287,6 +2287,22 @@ impl<'hir> LoweringContext<'_, 'hir> {
22872287
self.expr(b.span, hir::ExprKind::Block(b, None))
22882288
}
22892289

2290+
pub(super) fn expr_unsafe_block(
2291+
&mut self,
2292+
span: Span,
2293+
expr: &'hir hir::Expr<'hir>,
2294+
) -> hir::Expr<'hir> {
2295+
let hir_id = self.next_id();
2296+
self.expr_block(self.arena.alloc(hir::Block {
2297+
stmts: &[],
2298+
expr: Some(expr),
2299+
hir_id,
2300+
rules: hir::BlockCheckMode::UnsafeBlock(hir::UnsafeSource::CompilerGenerated),
2301+
span,
2302+
targeted_by_break: false,
2303+
}))
2304+
}
2305+
22902306
pub(super) fn expr_array_ref(
22912307
&mut self,
22922308
span: Span,

0 commit comments

Comments
 (0)