Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions compiler/rustc_ast_lowering/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,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_expr_lhs_assign =
in expressions, `_` can only be used on the left-hand side of an assignment
.label = `_` not allowed here
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 @@ -475,3 +475,10 @@ pub(crate) struct UnionWithDefault {
#[primary_span]
pub span: Span,
}

#[derive(Diagnostic)]
#[diag(ast_lowering_too_many_format_arguments)]
pub(crate) struct TooManyFormatArguments {
#[primary_span]
pub span: Span,
}
23 changes: 9 additions & 14 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -924,7 +924,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
arena_vec![self; new_unchecked, get_context],
),
};
self.arena.alloc(self.expr_unsafe(call))
self.arena.alloc(self.expr_unsafe(span, call))
};

// `::std::task::Poll::Ready(result) => break result`
Expand Down Expand Up @@ -1826,7 +1826,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
arena_vec![self; iter],
));
// `unsafe { ... }`
let iter = self.arena.alloc(self.expr_unsafe(iter));
let iter = self.arena.alloc(self.expr_unsafe(head_span, iter));
let kind = self.make_lowered_await(head_span, iter, FutureKind::AsyncIterator);
self.arena.alloc(hir::Expr { hir_id: self.next_id(), kind, span: head_span })
}
Expand Down Expand Up @@ -1881,7 +1881,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
arena_vec![self; iter],
));
// `unsafe { ... }`
let iter = self.arena.alloc(self.expr_unsafe(iter));
let iter = self.arena.alloc(self.expr_unsafe(head_span, iter));
let inner_match_expr = self.arena.alloc(self.expr_match(
for_span,
iter,
Expand Down Expand Up @@ -2105,18 +2105,10 @@ impl<'hir> LoweringContext<'_, 'hir> {
self.expr(sp, hir::ExprKind::Lit(lit))
}

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

pub(super) fn expr_u32(&mut self, sp: Span, value: u32) -> hir::Expr<'hir> {
self.expr_uint(sp, ast::UintTy::U32, value as u128)
}

pub(super) fn expr_u16(&mut self, sp: Span, value: u16) -> hir::Expr<'hir> {
self.expr_uint(sp, ast::UintTy::U16, value as u128)
}

pub(super) fn expr_str(&mut self, sp: Span, value: Symbol) -> hir::Expr<'hir> {
let lit = hir::Lit {
span: self.lower_span(sp),
Expand Down Expand Up @@ -2256,9 +2248,12 @@ impl<'hir> LoweringContext<'_, 'hir> {
self.expr(span, expr_path)
}

fn expr_unsafe(&mut self, expr: &'hir hir::Expr<'hir>) -> hir::Expr<'hir> {
pub(super) fn expr_unsafe(
&mut self,
span: Span,
expr: &'hir hir::Expr<'hir>,
) -> hir::Expr<'hir> {
let hir_id = self.next_id();
let span = expr.span;
self.expr(
span,
hir::ExprKind::Block(
Expand Down
Loading
Loading