mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-17 22:46:50 +00:00
use precise spans for recursive const evaluation
This commit is contained in:
parent
9ab4f876a1
commit
467e0f4446
@ -926,7 +926,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
self.param_env
|
||||
};
|
||||
let param_env = param_env.with_const();
|
||||
let val = self.tcx.eval_to_allocation_raw(param_env.and(gid))?;
|
||||
// Use a precise span for better cycle errors.
|
||||
let val = self.tcx.at(self.cur_span()).eval_to_allocation_raw(param_env.and(gid))?;
|
||||
self.raw_const_to_mplace(val)
|
||||
}
|
||||
|
||||
|
@ -504,7 +504,8 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
throw_unsup!(ReadExternStatic(def_id));
|
||||
}
|
||||
|
||||
(self.tcx.eval_static_initializer(def_id)?, Some(def_id))
|
||||
// Use a precise span for better cycle errors.
|
||||
(self.tcx.at(self.cur_span()).eval_static_initializer(def_id)?, Some(def_id))
|
||||
}
|
||||
};
|
||||
M::before_access_global(*self.tcx, &self.machine, id, alloc, def_id, is_write)?;
|
||||
|
@ -55,7 +55,6 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
|
||||
};
|
||||
let basic_block = &self.body().basic_blocks()[loc.block];
|
||||
|
||||
|
||||
if let Some(stmt) = basic_block.statements.get(loc.statement_index) {
|
||||
let old_frames = self.frame_idx();
|
||||
self.statement(stmt)?;
|
||||
|
@ -3,9 +3,9 @@ use super::{ErrorHandled, EvalToConstValueResult, GlobalId};
|
||||
use crate::mir;
|
||||
use crate::ty::fold::TypeFoldable;
|
||||
use crate::ty::subst::InternalSubsts;
|
||||
use crate::ty::{self, TyCtxt};
|
||||
use crate::ty::{self, query::TyCtxtAt, TyCtxt};
|
||||
use rustc_hir::def_id::DefId;
|
||||
use rustc_span::Span;
|
||||
use rustc_span::{Span, DUMMY_SP};
|
||||
|
||||
impl<'tcx> TyCtxt<'tcx> {
|
||||
/// Evaluates a constant without providing any substitutions. This is useful to evaluate consts
|
||||
@ -86,6 +86,17 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
}
|
||||
}
|
||||
|
||||
/// Evaluate a static's initializer, returning the allocation of the initializer's memory.
|
||||
#[inline(always)]
|
||||
pub fn eval_static_initializer(
|
||||
self,
|
||||
def_id: DefId,
|
||||
) -> Result<mir::ConstAllocation<'tcx>, ErrorHandled> {
|
||||
self.at(DUMMY_SP).eval_static_initializer(def_id)
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TyCtxtAt<'tcx> {
|
||||
/// Evaluate a static's initializer, returning the allocation of the initializer's memory.
|
||||
pub fn eval_static_initializer(
|
||||
self,
|
||||
@ -93,7 +104,7 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
) -> Result<mir::ConstAllocation<'tcx>, ErrorHandled> {
|
||||
trace!("eval_static_initializer: Need to compute {:?}", def_id);
|
||||
assert!(self.is_static(def_id));
|
||||
let instance = ty::Instance::mono(self, def_id);
|
||||
let instance = ty::Instance::mono(*self, def_id);
|
||||
let gid = GlobalId { instance, promoted: None };
|
||||
self.eval_to_allocation(gid, ty::ParamEnv::reveal_all())
|
||||
}
|
||||
@ -109,7 +120,9 @@ impl<'tcx> TyCtxt<'tcx> {
|
||||
let raw_const = self.eval_to_allocation_raw(param_env.and(gid))?;
|
||||
Ok(self.global_alloc(raw_const.alloc_id).unwrap_memory())
|
||||
}
|
||||
}
|
||||
|
||||
impl<'tcx> TyCtxt<'tcx> {
|
||||
/// Destructure a type-level constant ADT or array into its variant index and its field values.
|
||||
/// Panics if the destructuring fails, use `try_destructure_const` for fallible version.
|
||||
pub fn destructure_const(
|
||||
|
@ -5,10 +5,10 @@ LL | static FOO: () = FOO;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: ...which requires const-evaluating + checking `FOO`...
|
||||
--> $DIR/recursive-zst-static.rs:10:1
|
||||
--> $DIR/recursive-zst-static.rs:10:18
|
||||
|
|
||||
LL | static FOO: () = FOO;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^
|
||||
= note: ...which again requires const-evaluating + checking `FOO`, completing the cycle
|
||||
= note: cycle used when running analysis passes on this crate
|
||||
|
||||
|
@ -5,10 +5,10 @@ LL | static FOO: () = FOO;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: ...which requires const-evaluating + checking `FOO`...
|
||||
--> $DIR/recursive-zst-static.rs:10:1
|
||||
--> $DIR/recursive-zst-static.rs:10:18
|
||||
|
|
||||
LL | static FOO: () = FOO;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^
|
||||
= note: ...which again requires const-evaluating + checking `FOO`, completing the cycle
|
||||
= note: cycle used when running analysis passes on this crate
|
||||
|
||||
|
@ -11,10 +11,10 @@ LL | pub static mut C: u32 = unsafe { C = 1; 0 };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: ...which requires const-evaluating + checking `C`...
|
||||
--> $DIR/write-to-static-mut-in-static.rs:5:1
|
||||
--> $DIR/write-to-static-mut-in-static.rs:5:34
|
||||
|
|
||||
LL | pub static mut C: u32 = unsafe { C = 1; 0 };
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^^^
|
||||
= note: ...which again requires const-evaluating + checking `C`, completing the cycle
|
||||
= note: cycle used when running analysis passes on this crate
|
||||
|
||||
|
@ -5,10 +5,10 @@ LL | pub static FOO: u32 = FOO;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
|
||||
note: ...which requires const-evaluating + checking `FOO`...
|
||||
--> $DIR/recursive-static-definition.rs:1:1
|
||||
--> $DIR/recursive-static-definition.rs:1:23
|
||||
|
|
||||
LL | pub static FOO: u32 = FOO;
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
| ^^^
|
||||
= note: ...which again requires const-evaluating + checking `FOO`, completing the cycle
|
||||
= note: cycle used when running analysis passes on this crate
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user