Skip to content

Commit fbb43aa

Browse files
Auto merge of #148529 - m-ou-se:new-fmt-args, r=<try>
Experiment: New fmt::Arguments implementation
2 parents c90bcb9 + efeeca4 commit fbb43aa

Some content is hidden

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

49 files changed

+842
-855
lines changed

compiler/rustc_ast_lowering/messages.ftl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ ast_lowering_template_modifier = template modifier
169169
170170
ast_lowering_this_not_async = this is not `async`
171171
172+
ast_lowering_too_many_format_arguments =
173+
too many arguments used in format string
174+
172175
ast_lowering_underscore_expr_lhs_assign =
173176
in expressions, `_` can only be used on the left-hand side of an assignment
174177
.label = `_` not allowed here

compiler/rustc_ast_lowering/src/errors.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -475,3 +475,10 @@ pub(crate) struct UnionWithDefault {
475475
#[primary_span]
476476
pub span: Span,
477477
}
478+
479+
#[derive(Diagnostic)]
480+
#[diag(ast_lowering_too_many_format_arguments)]
481+
pub(crate) struct TooManyFormatArguments {
482+
#[primary_span]
483+
pub span: Span,
484+
}

compiler/rustc_ast_lowering/src/expr.rs

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -924,7 +924,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
924924
arena_vec![self; new_unchecked, get_context],
925925
),
926926
};
927-
self.arena.alloc(self.expr_unsafe(call))
927+
self.arena.alloc(self.expr_unsafe(span, call))
928928
};
929929

930930
// `::std::task::Poll::Ready(result) => break result`
@@ -1826,7 +1826,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
18261826
arena_vec![self; iter],
18271827
));
18281828
// `unsafe { ... }`
1829-
let iter = self.arena.alloc(self.expr_unsafe(iter));
1829+
let iter = self.arena.alloc(self.expr_unsafe(head_span, iter));
18301830
let kind = self.make_lowered_await(head_span, iter, FutureKind::AsyncIterator);
18311831
self.arena.alloc(hir::Expr { hir_id: self.next_id(), kind, span: head_span })
18321832
}
@@ -1881,7 +1881,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
18811881
arena_vec![self; iter],
18821882
));
18831883
// `unsafe { ... }`
1884-
let iter = self.arena.alloc(self.expr_unsafe(iter));
1884+
let iter = self.arena.alloc(self.expr_unsafe(head_span, iter));
18851885
let inner_match_expr = self.arena.alloc(self.expr_match(
18861886
for_span,
18871887
iter,
@@ -2105,18 +2105,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
21052105
self.expr(sp, hir::ExprKind::Lit(lit))
21062106
}
21072107

2108-
pub(super) fn expr_usize(&mut self, sp: Span, value: usize) -> hir::Expr<'hir> {
2108+
pub(super) fn expr_usize(&mut self, sp: Span, value: u64) -> hir::Expr<'hir> {
21092109
self.expr_uint(sp, ast::UintTy::Usize, value as u128)
21102110
}
21112111

2112-
pub(super) fn expr_u32(&mut self, sp: Span, value: u32) -> hir::Expr<'hir> {
2113-
self.expr_uint(sp, ast::UintTy::U32, value as u128)
2114-
}
2115-
2116-
pub(super) fn expr_u16(&mut self, sp: Span, value: u16) -> hir::Expr<'hir> {
2117-
self.expr_uint(sp, ast::UintTy::U16, value as u128)
2118-
}
2119-
21202112
pub(super) fn expr_str(&mut self, sp: Span, value: Symbol) -> hir::Expr<'hir> {
21212113
let lit = hir::Lit {
21222114
span: self.lower_span(sp),
@@ -2256,9 +2248,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
22562248
self.expr(span, expr_path)
22572249
}
22582250

2259-
fn expr_unsafe(&mut self, expr: &'hir hir::Expr<'hir>) -> hir::Expr<'hir> {
2251+
pub(super) fn expr_unsafe(
2252+
&mut self,
2253+
span: Span,
2254+
expr: &'hir hir::Expr<'hir>,
2255+
) -> hir::Expr<'hir> {
22602256
let hir_id = self.next_id();
2261-
let span = expr.span;
22622257
self.expr(
22632258
span,
22642259
hir::ExprKind::Block(
@@ -2275,6 +2270,15 @@ impl<'hir> LoweringContext<'_, 'hir> {
22752270
)
22762271
}
22772272

2273+
pub(super) fn expr_const(&mut self, span: Span, expr: hir::Expr<'hir>) -> hir::Expr<'hir> {
2274+
let node_id = self.next_node_id();
2275+
let def_id =
2276+
self.create_def(node_id, None, DefKind::InlineConst, DefPathData::LateAnonConst, span);
2277+
let hir_id = self.lower_node_id(node_id);
2278+
let body = self.record_body(&[], expr);
2279+
self.expr(span, hir::ExprKind::ConstBlock(hir::ConstBlock { hir_id, def_id, body }))
2280+
}
2281+
22782282
fn expr_block_empty(&mut self, span: Span) -> &'hir hir::Expr<'hir> {
22792283
let blk = self.block_all(span, &[], None);
22802284
let expr = self.expr_block(blk);

0 commit comments

Comments
 (0)