Remove lit_to_mir_constant
query
This commit is contained in:
parent
aa3a1862ba
commit
4ca87073f6
@ -1092,10 +1092,6 @@
|
||||
desc { "converting literal to const" }
|
||||
}
|
||||
|
||||
query lit_to_mir_constant(key: LitToConstInput<'tcx>) -> Result<mir::ConstantKind<'tcx>, LitToConstError> {
|
||||
desc { "converting literal to mir constant" }
|
||||
}
|
||||
|
||||
query check_match(key: LocalDefId) -> Result<(), rustc_errors::ErrorGuaranteed> {
|
||||
desc { |tcx| "match-checking `{}`", tcx.def_path_str(key) }
|
||||
cache_on_disk_if { true }
|
||||
|
@ -106,7 +106,7 @@ pub fn as_constant_inner<'tcx>(
|
||||
}
|
||||
|
||||
#[instrument(skip(tcx, lit_input))]
|
||||
pub(crate) fn lit_to_mir_constant<'tcx>(
|
||||
fn lit_to_mir_constant<'tcx>(
|
||||
tcx: TyCtxt<'tcx>,
|
||||
lit_input: LitToConstInput<'tcx>,
|
||||
) -> Result<ConstantKind<'tcx>, LitToConstError> {
|
||||
|
@ -1,4 +1,3 @@
|
||||
pub(crate) use crate::build::expr::as_constant::lit_to_mir_constant;
|
||||
use crate::build::expr::as_place::PlaceBuilder;
|
||||
use crate::build::scope::DropKind;
|
||||
use rustc_apfloat::ieee::{Double, Single};
|
||||
|
@ -32,7 +32,6 @@
|
||||
pub fn provide(providers: &mut Providers) {
|
||||
providers.check_match = thir::pattern::check_match;
|
||||
providers.lit_to_const = thir::constant::lit_to_const;
|
||||
providers.lit_to_mir_constant = build::lit_to_mir_constant;
|
||||
providers.mir_built = build::mir_built;
|
||||
providers.thir_check_unsafety = check_unsafety::thir_check_unsafety;
|
||||
providers.thir_body = thir::cx::thir_body;
|
||||
|
@ -48,6 +48,11 @@ pub(crate) fn lit_to_const<'tcx>(
|
||||
(ast::LitKind::Byte(n), ty::Uint(ty::UintTy::U8)) => {
|
||||
ty::ValTree::from_scalar_int((*n).into())
|
||||
}
|
||||
(ast::LitKind::CStr(data, _), ty::Ref(_, inner_ty, _)) if matches!(inner_ty.kind(), ty::Adt(def, _) if Some(def.did()) == tcx.lang_items().c_str()) =>
|
||||
{
|
||||
let bytes = data as &[u8];
|
||||
ty::ValTree::from_raw_bytes(tcx, bytes)
|
||||
}
|
||||
(ast::LitKind::Int(n, _), ty::Uint(_)) | (ast::LitKind::Int(n, _), ty::Int(_)) => {
|
||||
let scalar_int =
|
||||
trunc(if neg { (*n as i128).overflowing_neg().0 as u128 } else { *n })?;
|
||||
|
@ -20,7 +20,7 @@
|
||||
use rustc_middle::mir::interpret::{
|
||||
ConstValue, ErrorHandled, GlobalId, LitToConstError, LitToConstInput, Scalar,
|
||||
};
|
||||
use rustc_middle::mir::{self, UserTypeProjection};
|
||||
use rustc_middle::mir::{self, ConstantKind, UserTypeProjection};
|
||||
use rustc_middle::mir::{BorrowKind, Mutability};
|
||||
use rustc_middle::thir::{Ascription, BindingMode, FieldPat, LocalVarId, Pat, PatKind, PatRange};
|
||||
use rustc_middle::ty::subst::{GenericArg, SubstsRef};
|
||||
@ -646,14 +646,10 @@ fn lower_lit(&mut self, expr: &'tcx hir::Expr<'tcx>) -> PatKind<'tcx> {
|
||||
|
||||
let lit_input =
|
||||
LitToConstInput { lit: &lit.node, ty: self.typeck_results.expr_ty(expr), neg };
|
||||
match self
|
||||
.tcx
|
||||
.at(expr.span)
|
||||
.lit_to_const(lit_input)
|
||||
.map(mir::ConstantKind::Ty)
|
||||
.or_else(|_| self.tcx.at(expr.span).lit_to_mir_constant(lit_input))
|
||||
{
|
||||
Ok(constant) => self.const_to_pat(constant, expr.hir_id, lit.span, None).kind,
|
||||
match self.tcx.at(expr.span).lit_to_const(lit_input) {
|
||||
Ok(constant) => {
|
||||
self.const_to_pat(ConstantKind::Ty(constant), expr.hir_id, lit.span, None).kind
|
||||
}
|
||||
Err(LitToConstError::Reported(_)) => PatKind::Wild,
|
||||
Err(LitToConstError::TypeError) => bug!("lower_lit: had type error"),
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user