Skip to content

Commit 6005b0a

Browse files
committed
Move the Lrc outside the error type and name the fields
1 parent 6e5951c commit 6005b0a

File tree

12 files changed

+46
-33
lines changed

12 files changed

+46
-33
lines changed

src/librustc/ich/impls_ty.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -505,7 +505,8 @@ impl_stable_hash_for!(struct ty::Const<'tcx> {
505505

506506
impl_stable_hash_for!(struct ::middle::const_val::ConstEvalErr<'tcx> {
507507
span,
508-
data
508+
stacktrace,
509+
error
509510
});
510511

511512
impl_stable_hash_for!(struct ::middle::const_val::FrameInfo {

src/librustc/middle/const_val.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use syntax::ast;
2020

2121
use rustc_data_structures::sync::Lrc;
2222

23-
pub type EvalResult<'tcx> = Result<&'tcx ty::Const<'tcx>, ConstEvalErr<'tcx>>;
23+
pub type EvalResult<'tcx> = Result<&'tcx ty::Const<'tcx>, Lrc<ConstEvalErr<'tcx>>>;
2424

2525
#[derive(Copy, Clone, Debug, Hash, RustcEncodable, RustcDecodable, Eq, PartialEq, Ord, PartialOrd)]
2626
pub enum ConstVal<'tcx> {
@@ -31,7 +31,8 @@ pub enum ConstVal<'tcx> {
3131
#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
3232
pub struct ConstEvalErr<'tcx> {
3333
pub span: Span,
34-
pub data: Lrc<(::mir::interpret::EvalError<'tcx>, Vec<FrameInfo>)>,
34+
pub error: ::mir::interpret::EvalError<'tcx>,
35+
pub stacktrace: Vec<FrameInfo>,
3536
}
3637

3738
#[derive(Clone, Debug, RustcEncodable, RustcDecodable)]
@@ -81,7 +82,7 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> {
8182
message: &str,
8283
lint_root: Option<ast::NodeId>,
8384
) -> Option<DiagnosticBuilder<'tcx>> {
84-
match self.data.0.kind {
85+
match self.error.kind {
8586
::mir::interpret::EvalErrorKind::TypeckError |
8687
::mir::interpret::EvalErrorKind::TooGeneric |
8788
::mir::interpret::EvalErrorKind::CheckMatchError |
@@ -93,7 +94,7 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> {
9394
}
9495
trace!("reporting const eval failure at {:?}", self.span);
9596
let mut err = if let Some(lint_root) = lint_root {
96-
let node_id = self.data.1
97+
let node_id = self.stacktrace
9798
.iter()
9899
.rev()
99100
.filter_map(|frame| frame.lint_root)
@@ -108,8 +109,8 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> {
108109
} else {
109110
struct_error(tcx, message)
110111
};
111-
err.span_label(self.span, self.data.0.to_string());
112-
for FrameInfo { span, location, .. } in &self.data.1 {
112+
err.span_label(self.span, self.error.to_string());
113+
for FrameInfo { span, location, .. } in &self.stacktrace {
113114
err.span_label(*span, format!("inside call to `{}`", location));
114115
}
115116
Some(err)

src/librustc/mir/interpret/error.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use mir;
44
use middle::const_val::ConstEvalErr;
55
use ty::{FnSig, Ty, layout};
66
use ty::layout::{Size, Align};
7+
use rustc_data_structures::sync::Lrc;
78

89
use super::{
910
Pointer, Lock, AccessKind
@@ -155,7 +156,7 @@ pub enum EvalErrorKind<'tcx, O> {
155156
CheckMatchError,
156157
/// Cannot compute this constant because it depends on another one
157158
/// which already produced an error
158-
ReferencedConstant(ConstEvalErr<'tcx>),
159+
ReferencedConstant(Lrc<ConstEvalErr<'tcx>>),
159160
GeneratorResumedAfterReturn,
160161
GeneratorResumedAfterPanic,
161162
}

src/librustc/traits/fulfill.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -499,12 +499,12 @@ impl<'a, 'b, 'gcx, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'gcx,
499499
CodeSelectionError(ConstEvalFailure(err)))
500500
}
501501
} else {
502-
let err = EvalErrorKind::TooGeneric.into();
503502
ProcessResult::Error(
504503
CodeSelectionError(ConstEvalFailure(ConstEvalErr {
505504
span: obligation.cause.span,
506-
data: (err, vec![]).into(),
507-
}))
505+
error: EvalErrorKind::TooGeneric.into(),
506+
stacktrace: vec![],
507+
}.into()))
508508
)
509509
}
510510
},

src/librustc/traits/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -381,7 +381,7 @@ pub enum SelectionError<'tcx> {
381381
ty::PolyTraitRef<'tcx>,
382382
ty::error::TypeError<'tcx>),
383383
TraitNotObjectSafe(DefId),
384-
ConstEvalFailure(ConstEvalErr<'tcx>),
384+
ConstEvalFailure(Lrc<ConstEvalErr<'tcx>>),
385385
Overflow,
386386
}
387387

src/librustc/traits/structural_impls.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ impl<'a, 'tcx> Lift<'tcx> for traits::SelectionError<'a> {
172172
})
173173
}
174174
super::TraitNotObjectSafe(def_id) => Some(super::TraitNotObjectSafe(def_id)),
175-
super::ConstEvalFailure(ref err) => tcx.lift(err).map(super::ConstEvalFailure),
175+
super::ConstEvalFailure(ref err) => tcx.lift(&**err).map(|err| super::ConstEvalFailure(
176+
err.into(),
177+
)),
176178
super::Overflow => bug!(), // FIXME: ape ConstEvalFailure?
177179
}
178180
}

src/librustc/ty/structural_impls.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ use ty::{self, Lift, Ty, TyCtxt};
1818
use ty::fold::{TypeFoldable, TypeFolder, TypeVisitor};
1919
use rustc_data_structures::accumulate_vec::AccumulateVec;
2020
use rustc_data_structures::indexed_vec::{IndexVec, Idx};
21-
use rustc_data_structures::sync::Lrc;
2221
use mir::interpret;
2322

2423
use std::rc::Rc;
@@ -462,10 +461,11 @@ impl<'a, 'tcx> Lift<'tcx> for ty::error::TypeError<'a> {
462461
impl<'a, 'tcx> Lift<'tcx> for ConstEvalErr<'a> {
463462
type Lifted = ConstEvalErr<'tcx>;
464463
fn lift_to_tcx<'b, 'gcx>(&self, tcx: TyCtxt<'b, 'gcx, 'tcx>) -> Option<Self::Lifted> {
465-
tcx.lift(&self.data.0).map(|data| {
464+
tcx.lift(&self.error).map(|error| {
466465
ConstEvalErr {
467466
span: self.span,
468-
data: Lrc::new((data, self.data.1.clone())),
467+
stacktrace: self.stacktrace.clone(),
468+
error,
469469
}
470470
})
471471
}
@@ -579,7 +579,7 @@ impl<'a, 'tcx, O: Lift<'tcx>> Lift<'tcx> for interpret::EvalErrorKind<'a, O> {
579579
TypeckError => TypeckError,
580580
TooGeneric => TooGeneric,
581581
CheckMatchError => CheckMatchError,
582-
ReferencedConstant(ref err) => ReferencedConstant(tcx.lift(err)?),
582+
ReferencedConstant(ref err) => ReferencedConstant(tcx.lift(&**err)?.into()),
583583
OverflowNeg => OverflowNeg,
584584
Overflow(op) => Overflow(op),
585585
DivisionByZero => DivisionByZero,

src/librustc_codegen_llvm/mir/constant.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ use rustc_mir::interpret::{read_target_uint, const_val_field};
1414
use rustc::hir::def_id::DefId;
1515
use rustc::mir;
1616
use rustc_data_structures::indexed_vec::Idx;
17+
use rustc_data_structures::sync::Lrc;
1718
use rustc::mir::interpret::{GlobalId, Pointer, Scalar, Allocation, ConstValue, AllocType};
1819
use rustc::ty::{self, Ty};
1920
use rustc::ty::layout::{self, HasDataLayout, LayoutOf, Size};
@@ -117,7 +118,7 @@ pub fn const_alloc_to_llvm(cx: &CodegenCx, alloc: &Allocation) -> ValueRef {
117118
pub fn codegen_static_initializer<'a, 'tcx>(
118119
cx: &CodegenCx<'a, 'tcx>,
119120
def_id: DefId)
120-
-> Result<ValueRef, ConstEvalErr<'tcx>>
121+
-> Result<ValueRef, Lrc<ConstEvalErr<'tcx>>>
121122
{
122123
let instance = ty::Instance::mono(cx.tcx, def_id);
123124
let cid = GlobalId {
@@ -139,7 +140,7 @@ impl<'a, 'tcx> FunctionCx<'a, 'tcx> {
139140
&mut self,
140141
bx: &Builder<'a, 'tcx>,
141142
constant: &'tcx ty::Const<'tcx>,
142-
) -> Result<ConstValue<'tcx>, ConstEvalErr<'tcx>> {
143+
) -> Result<ConstValue<'tcx>, Lrc<ConstEvalErr<'tcx>>> {
143144
match constant.val {
144145
ConstVal::Unevaluated(def_id, ref substs) => {
145146
let tcx = bx.tcx();
@@ -160,7 +161,7 @@ impl<'a, 'tcx> FunctionCx<'a, 'tcx> {
160161
&mut self,
161162
bx: &Builder<'a, 'tcx>,
162163
constant: &mir::Constant<'tcx>,
163-
) -> Result<ConstValue<'tcx>, ConstEvalErr<'tcx>> {
164+
) -> Result<ConstValue<'tcx>, Lrc<ConstEvalErr<'tcx>>> {
164165
match constant.literal {
165166
mir::Literal::Promoted { index } => {
166167
let param_env = ty::ParamEnv::reveal_all();
@@ -189,7 +190,7 @@ impl<'a, 'tcx> FunctionCx<'a, 'tcx> {
189190
ty::TyArray(_, n) => n.unwrap_usize(bx.tcx()),
190191
ref other => bug!("invalid simd shuffle type: {}", other),
191192
};
192-
let values: Result<Vec<ValueRef>, _> = (0..fields).map(|field| {
193+
let values: Result<Vec<ValueRef>, Lrc<_>> = (0..fields).map(|field| {
193194
let field = const_val_field(
194195
bx.tcx(),
195196
ty::ParamEnv::reveal_all(),

src/librustc_codegen_llvm/mir/operand.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ use rustc::mir::interpret::ConstValue;
1515
use rustc::ty;
1616
use rustc::ty::layout::{self, Align, LayoutOf, TyLayout};
1717
use rustc_data_structures::indexed_vec::Idx;
18+
use rustc_data_structures::sync::Lrc;
1819

1920
use base;
2021
use common::{self, CodegenCx, C_null, C_undef, C_usize};
@@ -97,7 +98,7 @@ impl<'a, 'tcx> OperandRef<'tcx> {
9798
pub fn from_const(bx: &Builder<'a, 'tcx>,
9899
val: ConstValue<'tcx>,
99100
ty: ty::Ty<'tcx>)
100-
-> Result<OperandRef<'tcx>, ConstEvalErr<'tcx>> {
101+
-> Result<OperandRef<'tcx>, Lrc<ConstEvalErr<'tcx>>> {
101102
let layout = bx.cx.layout_of(ty);
102103

103104
if layout.is_zst() {

src/librustc_mir/interpret/const_eval.rs

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ pub fn value_to_const_value<'tcx>(
104104
let (frames, span) = ecx.generate_stacktrace(None);
105105
let err = ConstEvalErr {
106106
span,
107-
data: (err, frames).into(),
107+
error: err,
108+
stacktrace: frames,
108109
};
109110
err.report_as_error(
110111
ecx.tcx,
@@ -466,9 +467,10 @@ pub fn const_val_field<'a, 'tcx>(
466467
result.map_err(|err| {
467468
let (trace, span) = ecx.generate_stacktrace(None);
468469
ConstEvalErr {
469-
data: (err, trace).into(),
470+
error: err,
471+
stacktrace: trace,
470472
span,
471-
}
473+
}.into()
472474
})
473475
}
474476

@@ -537,9 +539,10 @@ pub fn const_eval_provider<'a, 'tcx>(
537539
// Do match-check before building MIR
538540
if tcx.check_match(def_id).is_err() {
539541
return Err(ConstEvalErr {
540-
data: (EvalErrorKind::CheckMatchError.into(), Vec::new()).into(),
542+
error: EvalErrorKind::CheckMatchError.into(),
543+
stacktrace: vec![],
541544
span,
542-
});
545+
}.into());
543546
}
544547

545548
if let hir::BodyOwnerKind::Const = tcx.hir.body_owner_kind(id) {
@@ -549,9 +552,10 @@ pub fn const_eval_provider<'a, 'tcx>(
549552
// Do not continue into miri if typeck errors occurred; it will fail horribly
550553
if tables.tainted_by_errors {
551554
return Err(ConstEvalErr {
552-
data: (EvalErrorKind::TypeckError.into(), Vec::new()).into(),
555+
error: EvalErrorKind::CheckMatchError.into(),
556+
stacktrace: vec![],
553557
span,
554-
});
558+
}.into());
555559
}
556560
};
557561

@@ -564,13 +568,14 @@ pub fn const_eval_provider<'a, 'tcx>(
564568
}).map_err(|err| {
565569
let (trace, span) = ecx.generate_stacktrace(None);
566570
let err = ConstEvalErr {
567-
data: (err, trace).into(),
571+
error: err,
572+
stacktrace: trace,
568573
span,
569574
};
570575
if tcx.is_static(def_id).is_some() {
571576
err.report_as_error(ecx.tcx, "could not evaluate static initializer");
572577
}
573-
err
578+
err.into()
574579
})
575580
}
576581

src/librustc_mir/monomorphize/collector.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1210,7 +1210,7 @@ fn collect_neighbours<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
12101210
Ok(val) => collect_const(tcx, val, instance.substs, output),
12111211
Err(err) => {
12121212
use rustc::mir::interpret::EvalErrorKind;
1213-
if let EvalErrorKind::ReferencedConstant(_) = err.data.0.kind {
1213+
if let EvalErrorKind::ReferencedConstant(_) = err.error.kind {
12141214
err.report_as_error(
12151215
tcx.at(mir.promoted[i].span),
12161216
"erroneous constant used",

src/librustc_mir/transform/const_prop.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,8 @@ impl<'b, 'a, 'tcx:'b> ConstPropagator<'b, 'a, 'tcx> {
145145
let (frames, span) = self.ecx.generate_stacktrace(None);
146146
let err = ConstEvalErr {
147147
span,
148-
data: (err, frames).into(),
148+
error: err,
149+
stacktrace: frames,
149150
};
150151
err.report_as_lint(
151152
self.ecx.tcx,

0 commit comments

Comments
 (0)