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
44 changes: 13 additions & 31 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use rustc_middle::span_bug;
use rustc_middle::ty::TyCtxt;
use rustc_session::errors::report_lit_error;
use rustc_span::source_map::{Spanned, respan};
use rustc_span::{DUMMY_SP, DesugaringKind, Ident, Span, Symbol, sym};
use rustc_span::{ByteSymbol, DUMMY_SP, DesugaringKind, Ident, Span, Symbol, sym};
use thin_vec::{ThinVec, thin_vec};
use visit::{Visitor, walk_expr};

Expand Down 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 @@ -2097,30 +2097,18 @@ impl<'hir> LoweringContext<'_, 'hir> {
self.arena.alloc(self.expr(sp, hir::ExprKind::Tup(&[])))
}

fn expr_uint(&mut self, sp: Span, ty: ast::UintTy, value: u128) -> hir::Expr<'hir> {
pub(super) fn expr_str(&mut self, sp: Span, value: Symbol) -> hir::Expr<'hir> {
let lit = hir::Lit {
span: self.lower_span(sp),
node: ast::LitKind::Int(value.into(), ast::LitIntType::Unsigned(ty)),
node: ast::LitKind::Str(value, ast::StrStyle::Cooked),
};
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> {
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> {
pub(super) fn expr_byte_str(&mut self, sp: Span, value: ByteSymbol) -> hir::Expr<'hir> {
let lit = hir::Lit {
span: self.lower_span(sp),
node: ast::LitKind::Str(value, ast::StrStyle::Cooked),
node: ast::LitKind::ByteStr(value, ast::StrStyle::Cooked),
};
self.expr(sp, hir::ExprKind::Lit(lit))
}
Expand Down Expand Up @@ -2256,9 +2244,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 Expand Up @@ -2296,15 +2287,6 @@ impl<'hir> LoweringContext<'_, 'hir> {
self.arena.alloc(self.expr_block(b))
}

pub(super) fn expr_array_ref(
&mut self,
span: Span,
elements: &'hir [hir::Expr<'hir>],
) -> hir::Expr<'hir> {
let array = self.arena.alloc(self.expr(span, hir::ExprKind::Array(elements)));
self.expr_ref(span, array)
}

pub(super) fn expr_ref(&mut self, span: Span, expr: &'hir hir::Expr<'hir>) -> hir::Expr<'hir> {
self.expr(span, hir::ExprKind::AddrOf(hir::BorrowKind::Ref, hir::Mutability::Not, expr))
}
Expand Down
Loading
Loading