dont use a query for lit_to_constant

This commit is contained in:
b-naber 2022-03-23 19:41:35 +01:00
parent 1b5fbe2076
commit 19041d995d
5 changed files with 9 additions and 18 deletions

View File

@ -962,10 +962,6 @@ rustc_queries! {
desc { "converting literal to const" }
}
query lit_to_constant(key: LitToConstInput<'tcx>) -> Result<mir::ConstantKind<'tcx>, LitToConstError> {
desc { "converting literal to mir constant"}
}
query check_match(key: DefId) {
desc { |tcx| "match-checking `{}`", tcx.def_path_str(key) }
cache_on_disk_if { key.is_local() }

View File

@ -31,17 +31,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
this.as_constant(&this.thir[value])
}
ExprKind::Literal { lit, neg } => {
let literal = match tcx.at(expr.span).lit_to_constant(LitToConstInput {
lit: &lit.node,
ty,
neg,
}) {
Ok(c) => c,
Err(LitToConstError::Reported) => ConstantKind::Ty(tcx.const_error(ty)),
Err(LitToConstError::TypeError) => {
bug!("encountered type error in `lit_to_constant")
}
};
let literal =
match lit_to_constant(tcx, LitToConstInput { lit: &lit.node, ty, neg }) {
Ok(c) => c,
Err(LitToConstError::Reported) => ConstantKind::Ty(tcx.const_error(ty)),
Err(LitToConstError::TypeError) => {
bug!("encountered type error in `lit_to_constant")
}
};
Constant { span, user_ty: None, literal: literal.into() }
}

View File

@ -1078,5 +1078,4 @@ mod matches;
mod misc;
mod scope;
crate use expr::as_constant;
pub(crate) use expr::category::Category as ExprCategory;

View File

@ -27,7 +27,6 @@ use rustc_middle::ty::query::Providers;
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_constant = build::as_constant::lit_to_constant;
providers.mir_built = build::mir_built;
providers.thir_check_unsafety = check_unsafety::thir_check_unsafety;
providers.thir_check_unsafety_for_const_arg = check_unsafety::thir_check_unsafety_for_const_arg;

View File

@ -442,7 +442,7 @@ impl<'a, 'tcx> AbstractConstBuilder<'a, 'tcx> {
self.tcx.const_error(node.ty)
}
Err(LitToConstError::TypeError) => {
bug!("encountered type error in lit_to_constant")
bug!("encountered type error in lit_to_const")
}
};