Skip to content

Commit 2ce0205

Browse files
committed
Share implementation of expr_u{16,32,size}.
1 parent 2647cf1 commit 2ce0205

File tree

1 file changed

+8
-21
lines changed
  • compiler/rustc_ast_lowering/src

1 file changed

+8
-21
lines changed

compiler/rustc_ast_lowering/src/expr.rs

+8-21
Original file line numberDiff line numberDiff line change
@@ -2130,37 +2130,24 @@ impl<'hir> LoweringContext<'_, 'hir> {
21302130
self.arena.alloc(self.expr(sp, hir::ExprKind::Tup(&[])))
21312131
}
21322132

2133-
pub(super) fn expr_usize(&mut self, sp: Span, value: usize) -> hir::Expr<'hir> {
2133+
fn expr_uint(&mut self, sp: Span, ty: ast::UintTy, value: u128) -> hir::Expr<'hir> {
21342134
let lit = self.arena.alloc(hir::Lit {
21352135
span: sp,
2136-
node: ast::LitKind::Int(
2137-
(value as u128).into(),
2138-
ast::LitIntType::Unsigned(ast::UintTy::Usize),
2139-
),
2136+
node: ast::LitKind::Int(value.into(), ast::LitIntType::Unsigned(ty)),
21402137
});
21412138
self.expr(sp, hir::ExprKind::Lit(lit))
21422139
}
21432140

2141+
pub(super) fn expr_usize(&mut self, sp: Span, value: usize) -> hir::Expr<'hir> {
2142+
self.expr_uint(sp, ast::UintTy::Usize, value as u128)
2143+
}
2144+
21442145
pub(super) fn expr_u32(&mut self, sp: Span, value: u32) -> hir::Expr<'hir> {
2145-
let lit = self.arena.alloc(hir::Lit {
2146-
span: sp,
2147-
node: ast::LitKind::Int(
2148-
u128::from(value).into(),
2149-
ast::LitIntType::Unsigned(ast::UintTy::U32),
2150-
),
2151-
});
2152-
self.expr(sp, hir::ExprKind::Lit(lit))
2146+
self.expr_uint(sp, ast::UintTy::U32, value as u128)
21532147
}
21542148

21552149
pub(super) fn expr_u16(&mut self, sp: Span, value: u16) -> hir::Expr<'hir> {
2156-
let lit = self.arena.alloc(hir::Lit {
2157-
span: sp,
2158-
node: ast::LitKind::Int(
2159-
u128::from(value).into(),
2160-
ast::LitIntType::Unsigned(ast::UintTy::U16),
2161-
),
2162-
});
2163-
self.expr(sp, hir::ExprKind::Lit(lit))
2150+
self.expr_uint(sp, ast::UintTy::U16, value as u128)
21642151
}
21652152

21662153
pub(super) fn expr_char(&mut self, sp: Span, value: char) -> hir::Expr<'hir> {

0 commit comments

Comments
 (0)