Skip to content

Commit 58fdac6

Browse files
committed
Simplify const error reporting
1 parent ba196bd commit 58fdac6

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/librustc/middle/const_val.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,14 +93,14 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> {
9393
message: &str)
9494
-> Option<DiagnosticBuilder<'tcx>>
9595
{
96-
self.struct_generic(tcx, message, None, true)
96+
self.struct_generic(tcx, message, None)
9797
}
9898

9999
pub fn report_as_error(&self,
100100
tcx: TyCtxtAt<'a, 'gcx, 'tcx>,
101101
message: &str
102102
) {
103-
let err = self.struct_generic(tcx, message, None, true);
103+
let err = self.struct_generic(tcx, message, None);
104104
if let Some(mut err) = err {
105105
err.emit();
106106
}
@@ -115,7 +115,6 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> {
115115
tcx,
116116
message,
117117
Some(lint_root),
118-
false,
119118
);
120119
if let Some(mut lint) = lint {
121120
lint.emit();
@@ -127,7 +126,6 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> {
127126
tcx: TyCtxtAt<'a, 'gcx, 'tcx>,
128127
message: &str,
129128
lint_root: Option<ast::NodeId>,
130-
as_err: bool,
131129
) -> Option<DiagnosticBuilder<'tcx>> {
132130
let (msg, frames): (_, &[_]) = match *self.kind {
133131
ErrKind::TypeckError | ErrKind::CheckMatchError => return None,
@@ -136,7 +134,7 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> {
136134
::mir::interpret::EvalErrorKind::TypeckError |
137135
::mir::interpret::EvalErrorKind::Layout(_) => return None,
138136
::mir::interpret::EvalErrorKind::ReferencedConstant(ref inner) => {
139-
inner.struct_generic(tcx, "referenced constant", lint_root, as_err)?.emit();
137+
inner.struct_generic(tcx, "referenced constant", lint_root)?.emit();
140138
(miri.to_string(), frames)
141139
},
142140
_ => (miri.to_string(), frames),
@@ -145,22 +143,21 @@ impl<'a, 'gcx, 'tcx> ConstEvalErr<'tcx> {
145143
_ => (self.description().into_oneline().to_string(), &[]),
146144
};
147145
trace!("reporting const eval failure at {:?}", self.span);
148-
let mut err = if as_err {
149-
struct_error(tcx, message)
150-
} else {
146+
let mut err = if let Some(lint_root) = lint_root {
151147
let node_id = frames
152148
.iter()
153149
.rev()
154150
.filter_map(|frame| frame.lint_root)
155151
.next()
156-
.or(lint_root)
157-
.expect("some part of a failing const eval must be local");
152+
.unwrap_or(lint_root);
158153
tcx.struct_span_lint_node(
159154
::rustc::lint::builtin::CONST_ERR,
160155
node_id,
161156
tcx.span,
162157
message,
163158
)
159+
} else {
160+
struct_error(tcx, message)
164161
};
165162
err.span_label(self.span, msg);
166163
for FrameInfo { span, location, .. } in frames {

0 commit comments

Comments
 (0)