Skip to content

Commit

Permalink
Refactor fmt::Arguments to just two pointers in size.
Browse files Browse the repository at this point in the history
  • Loading branch information
m-ou-se committed Feb 19, 2025
1 parent e02ed64 commit 25ccdae
Show file tree
Hide file tree
Showing 10 changed files with 697 additions and 392 deletions.
7 changes: 7 additions & 0 deletions compiler/rustc_ast/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,13 @@ impl FormatArgumentKind {
&Self::Captured(id) => Some(id),
}
}

pub fn is_captured(&self) -> bool {
match self {
Self::Captured(_) => true,
_ => false,
}
}
}

#[derive(Clone, Encodable, Decodable, Debug, PartialEq, Eq)]
Expand Down
3 changes: 3 additions & 0 deletions compiler/rustc_ast_lowering/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ ast_lowering_template_modifier = template modifier
ast_lowering_this_not_async = this is not `async`
ast_lowering_too_many_format_arguments =
too many arguments used in format string
ast_lowering_underscore_array_length_unstable =
using `_` for array lengths is unstable
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_ast_lowering/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -467,3 +467,10 @@ pub(crate) struct UseConstGenericArg {
#[suggestion_part(code = "{other_args}")]
pub call_args: Span,
}

#[derive(Diagnostic)]
#[diag(ast_lowering_too_many_format_arguments)]
pub(crate) struct TooManyFormatArguments {
#[primary_span]
pub span: Span,
}
26 changes: 21 additions & 5 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2129,12 +2129,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
self.arena.alloc(self.expr(sp, hir::ExprKind::Tup(&[])))
}

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

pub(super) fn expr_u16(&mut self, sp: Span, value: u16) -> hir::Expr<'hir> {
pub(super) fn expr_usize(&mut self, sp: Span, value: u16) -> hir::Expr<'hir> {
let lit = self.arena.alloc(hir::Lit {
span: sp,
node: ast::LitKind::Int(
u128::from(value).into(),
ast::LitIntType::Unsigned(ast::UintTy::U16),
ast::LitIntType::Unsigned(ast::UintTy::Usize),
),
});
self.expr(sp, hir::ExprKind::Lit(lit))
Expand Down Expand Up @@ -2287,6 +2287,22 @@ impl<'hir> LoweringContext<'_, 'hir> {
self.expr(b.span, hir::ExprKind::Block(b, None))
}

pub(super) fn expr_unsafe_block(
&mut self,
span: Span,
expr: &'hir hir::Expr<'hir>,
) -> hir::Expr<'hir> {
let hir_id = self.next_id();
self.expr_block(self.arena.alloc(hir::Block {
stmts: &[],
expr: Some(expr),
hir_id,
rules: hir::BlockCheckMode::UnsafeBlock(hir::UnsafeSource::CompilerGenerated),
span,
targeted_by_break: false,
}))
}

pub(super) fn expr_array_ref(
&mut self,
span: Span,
Expand Down
Loading

0 comments on commit 25ccdae

Please sign in to comment.