Skip to content

Commit 86a686c

Browse files
authored
Auto merge of #36335 - mcarton:compiletest, r=GuillaumeGomez
Fix ICE test in compiletest fail-tests While working on Clippy which uses *compiletest*, I noticed that as long as all expected error are found, *compile-fail* tests will be marked *ok* even if there is an ICE. One function seems to have not been updated with JSON errors because ICEs are now reported like this: ```json {"message":"../src/librustc/ty/context.rs:161: Attempted to intern `_` which contains inference types/regions in the global type context","code":null,"level":"error: internal compiler error","spans":[],"children":[],"rendered":null} ``` I don't think I can add a test for that. I guess: r? @nikomatsakis
2 parents f2c53ea + bfa3433 commit 86a686c

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

src/librustc_const_eval/eval.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -868,7 +868,7 @@ pub fn eval_const_expr_partial<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
868868
debug!("const call({:?})", call_args);
869869
eval_const_expr_partial(tcx, &result, ty_hint, Some(&call_args))?
870870
},
871-
hir::ExprLit(ref lit) => match lit_to_const(&lit.node, tcx, ety, lit.span) {
871+
hir::ExprLit(ref lit) => match lit_to_const(&lit.node, tcx, ety) {
872872
Ok(val) => val,
873873
Err(err) => signal!(e, err),
874874
},
@@ -1210,8 +1210,7 @@ fn cast_const<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, val: ConstVal, ty: ty::Ty)
12101210

12111211
fn lit_to_const<'a, 'tcx>(lit: &ast::LitKind,
12121212
tcx: TyCtxt<'a, 'tcx, 'tcx>,
1213-
ty_hint: Option<Ty<'tcx>>,
1214-
span: Span)
1213+
ty_hint: Option<Ty<'tcx>>)
12151214
-> Result<ConstVal, ErrKind> {
12161215
use syntax::ast::*;
12171216
use syntax::ast::LitIntType::*;
@@ -1245,21 +1244,22 @@ fn lit_to_const<'a, 'tcx>(lit: &ast::LitKind,
12451244
},
12461245

12471246
LitKind::Float(ref n, fty) => {
1248-
Ok(Float(parse_float(n, Some(fty), span)))
1247+
parse_float(n, Some(fty)).map(Float)
12491248
}
12501249
LitKind::FloatUnsuffixed(ref n) => {
12511250
let fty_hint = match ty_hint.map(|t| &t.sty) {
12521251
Some(&ty::TyFloat(fty)) => Some(fty),
12531252
_ => None
12541253
};
1255-
Ok(Float(parse_float(n, fty_hint, span)))
1254+
parse_float(n, fty_hint).map(Float)
12561255
}
12571256
LitKind::Bool(b) => Ok(Bool(b)),
12581257
LitKind::Char(c) => Ok(Char(c)),
12591258
}
12601259
}
12611260

1262-
fn parse_float(num: &str, fty_hint: Option<ast::FloatTy>, span: Span) -> ConstFloat {
1261+
fn parse_float(num: &str, fty_hint: Option<ast::FloatTy>)
1262+
-> Result<ConstFloat, ErrKind> {
12631263
let val = match fty_hint {
12641264
Some(ast::FloatTy::F32) => num.parse::<f32>().map(F32),
12651265
Some(ast::FloatTy::F64) => num.parse::<f64>().map(F64),
@@ -1271,9 +1271,9 @@ fn parse_float(num: &str, fty_hint: Option<ast::FloatTy>, span: Span) -> ConstFl
12711271
})
12721272
}
12731273
};
1274-
val.unwrap_or_else(|_| {
1274+
val.map_err(|_| {
12751275
// FIXME(#31407) this is only necessary because float parsing is buggy
1276-
span_bug!(span, "could not evaluate float literal (see issue #31407)");
1276+
UnimplementedConstVal("could not evaluate float literal (see issue #31407)")
12771277
})
12781278
}
12791279

src/test/compile-fail/issue-31109.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,7 @@
1111
fn main() {
1212
// FIXME(#31407) this error should go away, but in the meantime we test that it
1313
// is accompanied by a somewhat useful error message.
14-
let _: f64 = 1234567890123456789012345678901234567890e-340; //~ ERROR could not evaluate float
14+
let _: f64 = 1234567890123456789012345678901234567890e-340;
15+
//~^ ERROR constant evaluation error
16+
//~| unimplemented constant expression: could not evaluate float literal
1517
}

src/tools/compiletest/src/runtest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -978,7 +978,7 @@ actual:\n\
978978

979979
fn check_no_compiler_crash(&self, proc_res: &ProcRes) {
980980
for line in proc_res.stderr.lines() {
981-
if line.starts_with("error: internal compiler error:") {
981+
if line.contains("error: internal compiler error") {
982982
self.fatal_proc_rec("compiler encountered internal error", proc_res);
983983
}
984984
}

0 commit comments

Comments
 (0)