Add DiagCtxt::delayed_bug
.
We have `span_delayed_bug` and often pass it a `DUMMY_SP`. This commit adds `delayed_bug`, which matches pairs like `err`/`span_err` and `warn`/`span_warn`.
This commit is contained in:
parent
3c4f1d85af
commit
2ea7a37e11
27 changed files with 103 additions and 146 deletions
|
@ -9,7 +9,6 @@ use rustc_middle::thir::*;
|
|||
use rustc_middle::ty::{
|
||||
self, CanonicalUserType, CanonicalUserTypeAnnotation, TyCtxt, UserTypeAnnotationIndex,
|
||||
};
|
||||
use rustc_span::DUMMY_SP;
|
||||
use rustc_target::abi::Size;
|
||||
|
||||
impl<'a, 'tcx> Builder<'a, 'tcx> {
|
||||
|
@ -111,15 +110,15 @@ fn lit_to_mir_constant<'tcx>(
|
|||
let LitToConstInput { lit, ty, neg } = lit_input;
|
||||
let trunc = |n| {
|
||||
let param_ty = ty::ParamEnv::reveal_all().and(ty);
|
||||
let width = tcx
|
||||
.layout_of(param_ty)
|
||||
.map_err(|_| {
|
||||
LitToConstError::Reported(tcx.dcx().span_delayed_bug(
|
||||
DUMMY_SP,
|
||||
format!("couldn't compute width of literal: {:?}", lit_input.lit),
|
||||
))
|
||||
})?
|
||||
.size;
|
||||
let width =
|
||||
tcx.layout_of(param_ty)
|
||||
.map_err(|_| {
|
||||
LitToConstError::Reported(tcx.dcx().delayed_bug(format!(
|
||||
"couldn't compute width of literal: {:?}",
|
||||
lit_input.lit
|
||||
)))
|
||||
})?
|
||||
.size;
|
||||
trace!("trunc {} with size {} and shift {}", n, width.bits(), 128 - width.bits());
|
||||
let result = width.truncate(n);
|
||||
trace!("trunc result: {}", result);
|
||||
|
@ -158,16 +157,16 @@ fn lit_to_mir_constant<'tcx>(
|
|||
}
|
||||
(ast::LitKind::Float(n, _), ty::Float(fty)) => parse_float_into_constval(*n, *fty, neg)
|
||||
.ok_or_else(|| {
|
||||
LitToConstError::Reported(tcx.dcx().span_delayed_bug(
|
||||
DUMMY_SP,
|
||||
format!("couldn't parse float literal: {:?}", lit_input.lit),
|
||||
))
|
||||
LitToConstError::Reported(
|
||||
tcx.dcx()
|
||||
.delayed_bug(format!("couldn't parse float literal: {:?}", lit_input.lit)),
|
||||
)
|
||||
})?,
|
||||
(ast::LitKind::Bool(b), ty::Bool) => ConstValue::Scalar(Scalar::from_bool(*b)),
|
||||
(ast::LitKind::Char(c), ty::Char) => ConstValue::Scalar(Scalar::from_char(*c)),
|
||||
(ast::LitKind::Err, _) => {
|
||||
return Err(LitToConstError::Reported(
|
||||
tcx.dcx().span_delayed_bug(DUMMY_SP, "encountered LitKind::Err during mir build"),
|
||||
tcx.dcx().delayed_bug("encountered LitKind::Err during mir build"),
|
||||
));
|
||||
}
|
||||
_ => return Err(LitToConstError::TypeError),
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
use rustc_ast as ast;
|
||||
use rustc_middle::mir::interpret::{LitToConstError, LitToConstInput};
|
||||
use rustc_middle::ty::{self, ParamEnv, ScalarInt, TyCtxt};
|
||||
use rustc_span::DUMMY_SP;
|
||||
|
||||
use crate::build::parse_float_into_scalar;
|
||||
|
||||
|
@ -13,15 +12,15 @@ pub(crate) fn lit_to_const<'tcx>(
|
|||
|
||||
let trunc = |n| {
|
||||
let param_ty = ParamEnv::reveal_all().and(ty);
|
||||
let width = tcx
|
||||
.layout_of(param_ty)
|
||||
.map_err(|_| {
|
||||
LitToConstError::Reported(tcx.dcx().span_delayed_bug(
|
||||
DUMMY_SP,
|
||||
format!("couldn't compute width of literal: {:?}", lit_input.lit),
|
||||
))
|
||||
})?
|
||||
.size;
|
||||
let width =
|
||||
tcx.layout_of(param_ty)
|
||||
.map_err(|_| {
|
||||
LitToConstError::Reported(tcx.dcx().delayed_bug(format!(
|
||||
"couldn't compute width of literal: {:?}",
|
||||
lit_input.lit
|
||||
)))
|
||||
})?
|
||||
.size;
|
||||
trace!("trunc {} with size {} and shift {}", n, width.bits(), 128 - width.bits());
|
||||
let result = width.truncate(n);
|
||||
trace!("trunc result: {}", result);
|
||||
|
@ -60,20 +59,21 @@ pub(crate) fn lit_to_const<'tcx>(
|
|||
}
|
||||
(ast::LitKind::Bool(b), ty::Bool) => ty::ValTree::from_scalar_int((*b).into()),
|
||||
(ast::LitKind::Float(n, _), ty::Float(fty)) => {
|
||||
let bits = parse_float_into_scalar(*n, *fty, neg)
|
||||
.ok_or_else(|| {
|
||||
LitToConstError::Reported(tcx.dcx().span_delayed_bug(
|
||||
DUMMY_SP,
|
||||
format!("couldn't parse float literal: {:?}", lit_input.lit),
|
||||
))
|
||||
})?
|
||||
.assert_int();
|
||||
let bits =
|
||||
parse_float_into_scalar(*n, *fty, neg)
|
||||
.ok_or_else(|| {
|
||||
LitToConstError::Reported(tcx.dcx().delayed_bug(format!(
|
||||
"couldn't parse float literal: {:?}",
|
||||
lit_input.lit
|
||||
)))
|
||||
})?
|
||||
.assert_int();
|
||||
ty::ValTree::from_scalar_int(bits)
|
||||
}
|
||||
(ast::LitKind::Char(c), ty::Char) => ty::ValTree::from_scalar_int((*c).into()),
|
||||
(ast::LitKind::Err, _) => {
|
||||
return Err(LitToConstError::Reported(
|
||||
tcx.dcx().span_delayed_bug(DUMMY_SP, "encountered LitKind::Err during mir build"),
|
||||
tcx.dcx().delayed_bug("encountered LitKind::Err during mir build"),
|
||||
));
|
||||
}
|
||||
_ => return Err(LitToConstError::TypeError),
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue