1
Fork 0

Share implementation of expr_u{16,32,size}.

This commit is contained in:
Mara Bos 2025-03-10 13:57:23 +01:00
parent 2647cf17e7
commit 2ce0205735

View file

@ -2130,37 +2130,24 @@ impl<'hir> LoweringContext<'_, 'hir> {
self.arena.alloc(self.expr(sp, hir::ExprKind::Tup(&[]))) self.arena.alloc(self.expr(sp, hir::ExprKind::Tup(&[])))
} }
pub(super) fn expr_usize(&mut self, sp: Span, value: usize) -> hir::Expr<'hir> { fn expr_uint(&mut self, sp: Span, ty: ast::UintTy, value: u128) -> hir::Expr<'hir> {
let lit = self.arena.alloc(hir::Lit { let lit = self.arena.alloc(hir::Lit {
span: sp, span: sp,
node: ast::LitKind::Int( node: ast::LitKind::Int(value.into(), ast::LitIntType::Unsigned(ty)),
(value as u128).into(),
ast::LitIntType::Unsigned(ast::UintTy::Usize),
),
}); });
self.expr(sp, hir::ExprKind::Lit(lit)) self.expr(sp, hir::ExprKind::Lit(lit))
} }
pub(super) fn expr_usize(&mut self, sp: Span, value: usize) -> 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> { pub(super) fn expr_u32(&mut self, sp: Span, value: u32) -> hir::Expr<'hir> {
let lit = self.arena.alloc(hir::Lit { self.expr_uint(sp, ast::UintTy::U32, value as u128)
span: sp,
node: ast::LitKind::Int(
u128::from(value).into(),
ast::LitIntType::Unsigned(ast::UintTy::U32),
),
});
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_u16(&mut self, sp: Span, value: u16) -> hir::Expr<'hir> {
let lit = self.arena.alloc(hir::Lit { self.expr_uint(sp, ast::UintTy::U16, value as u128)
span: sp,
node: ast::LitKind::Int(
u128::from(value).into(),
ast::LitIntType::Unsigned(ast::UintTy::U16),
),
});
self.expr(sp, hir::ExprKind::Lit(lit))
} }
pub(super) fn expr_char(&mut self, sp: Span, value: char) -> hir::Expr<'hir> { pub(super) fn expr_char(&mut self, sp: Span, value: char) -> hir::Expr<'hir> {