avoid computing cur_span all the time
This commit is contained in:
parent
0ac6fd0405
commit
32b01c78d0
@ -317,7 +317,10 @@ pub fn const_eval_raw_provider<'tcx>(
|
||||
if is_static {
|
||||
// Ensure that if the above error was either `TooGeneric` or `Reported`
|
||||
// an error must be reported.
|
||||
let v = err.report_as_error(ecx.tcx_at(), "could not evaluate static initializer");
|
||||
let v = err.report_as_error(
|
||||
ecx.tcx.at(ecx.cur_span()),
|
||||
"could not evaluate static initializer",
|
||||
);
|
||||
|
||||
// If this is `Reveal:All`, then we need to make sure an error is reported but if
|
||||
// this is `Reveal::UserFacing`, then it's expected that we could get a
|
||||
@ -373,13 +376,16 @@ pub fn const_eval_raw_provider<'tcx>(
|
||||
// anything else (array lengths, enum initializers, constant patterns) are
|
||||
// reported as hard errors
|
||||
} else {
|
||||
err.report_as_error(ecx.tcx_at(), "evaluation of constant value failed")
|
||||
err.report_as_error(
|
||||
ecx.tcx.at(ecx.cur_span()),
|
||||
"evaluation of constant value failed",
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// use of broken constant from other crate
|
||||
err.report_as_error(ecx.tcx_at(), "could not evaluate constant")
|
||||
err.report_as_error(ecx.tcx.at(ecx.cur_span()), "could not evaluate constant")
|
||||
}
|
||||
})
|
||||
}
|
||||
|
@ -323,7 +323,9 @@ pub fn cur_span(&self) -> Span {
|
||||
|
||||
#[inline(always)]
|
||||
pub fn tcx_at(&self) -> TyCtxtAt<'tcx> {
|
||||
self.tcx.at(self.cur_span())
|
||||
// Computing the current span has a non-trivial cost, and for cycle errors
|
||||
// the "root span" is good enough.
|
||||
self.tcx.at(self.root_span)
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
@ -406,7 +408,7 @@ pub fn type_is_sized(&self, ty: Ty<'tcx>) -> bool {
|
||||
|
||||
#[inline]
|
||||
pub fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool {
|
||||
ty.is_freeze(self.tcx, self.param_env, self.cur_span())
|
||||
ty.is_freeze(self.tcx, self.param_env, self.root_span)
|
||||
}
|
||||
|
||||
pub fn load_mir(
|
||||
@ -889,7 +891,7 @@ pub fn const_eval_raw(
|
||||
// FIXME: We can hit delay_span_bug if this is an invalid const, interning finds
|
||||
// that problem, but we never run validation to show an error. Can we ensure
|
||||
// this does not happen?
|
||||
let val = self.tcx_at().const_eval_raw(param_env.and(gid))?;
|
||||
let val = self.tcx.at(self.cur_span()).const_eval_raw(param_env.and(gid))?;
|
||||
self.raw_const_to_mplace(val)
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user