improve the docs of ConstantId

This commit is contained in:
Oliver Schneider
2016-06-08 12:35:15 +02:00
parent 240f0c0dd6
commit 2178961262
2 changed files with 11 additions and 4 deletions
+10 -3
View File
@@ -129,8 +129,14 @@ enum TerminatorTarget {
}
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
/// Uniquely identifies a specific constant or static
struct ConstantId<'tcx> {
/// the def id of the constant/static or in case of promoteds, the def id of the function they belong to
def_id: DefId,
/// In case of statics and constants this is `Substs::empty()`, so only promoteds and associated
/// constants actually have something useful here. We could special case statics and constants,
/// but that would only require more branching when working with constants, and not bring any
/// real benefits.
substs: &'tcx Substs<'tcx>,
kind: ConstantKind,
}
@@ -138,7 +144,8 @@ struct ConstantId<'tcx> {
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
enum ConstantKind {
Promoted(usize),
Static,
/// Statics, constants and associated constants
Global,
}
impl<'a, 'tcx> GlobalEvalContext<'a, 'tcx> {
@@ -1199,7 +1206,7 @@ fn eval_operand(&mut self, op: &mir::Operand<'tcx>) -> EvalResult<Pointer> {
let cid = ConstantId {
def_id: def_id,
substs: substs,
kind: ConstantKind::Static,
kind: ConstantKind::Global,
};
Ok(*self.statics.get(&cid).expect("static should have been cached (rvalue)"))
}
@@ -1231,7 +1238,7 @@ fn eval_lvalue(&mut self, lvalue: &mir::Lvalue<'tcx>) -> EvalResult<Lvalue> {
let cid = ConstantId {
def_id: def_id,
substs: substs,
kind: ConstantKind::Static,
kind: ConstantKind::Global,
};
*self.gecx.statics.get(&cid).expect("static should have been cached (lvalue)")
},
+1 -1
View File
@@ -145,7 +145,7 @@ fn static_item(&mut self, def_id: DefId, substs: &'tcx subst::Substs<'tcx>, span
let cid = ConstantId {
def_id: def_id,
substs: substs,
kind: ConstantKind::Static,
kind: ConstantKind::Global,
};
if self.gecx.statics.contains_key(&cid) {
return;