Skip to content

Commit 48f366f

Browse files
committed
Replace and_then map_err and_then chain with a match
1 parent b1bd34d commit 48f366f

File tree

1 file changed

+16
-15
lines changed

1 file changed

+16
-15
lines changed

compiler/rustc_mir/src/const_eval/eval_queries.rs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,8 @@ pub fn const_eval_raw_provider<'tcx>(
294294
);
295295

296296
let res = ecx.load_mir(cid.instance.def, cid.promoted);
297-
res.and_then(|body| eval_body_using_ecx(&mut ecx, cid, &body))
298-
.map_err(|error| {
297+
match res.and_then(|body| eval_body_using_ecx(&mut ecx, cid, &body)) {
298+
Err(error) => {
299299
let err = ConstEvalErr::new(&ecx, error, None);
300300
// errors in statics are always emitted as fatal errors
301301
if is_static {
@@ -317,7 +317,7 @@ pub fn const_eval_raw_provider<'tcx>(
317317
);
318318
}
319319

320-
v
320+
Err(v)
321321
} else if let Some(def) = def.as_local() {
322322
// constant defined in this crate, we can figure out a lint level!
323323
match tcx.def_kind(def.did.to_def_id()) {
@@ -331,12 +331,12 @@ pub fn const_eval_raw_provider<'tcx>(
331331
// compatibility hazard
332332
DefKind::Const | DefKind::AssocConst => {
333333
let hir_id = tcx.hir().local_def_id_to_hir_id(def.did);
334-
err.report_as_lint(
334+
Err(err.report_as_lint(
335335
tcx.at(tcx.def_span(def.did)),
336336
"any use of this value will cause an error",
337337
hir_id,
338338
Some(err.span),
339-
)
339+
))
340340
}
341341
// promoting runtime code is only allowed to error if it references broken
342342
// constants any other kind of error will be reported to the user as a
@@ -345,34 +345,34 @@ pub fn const_eval_raw_provider<'tcx>(
345345
if let Some(p) = cid.promoted {
346346
let span = tcx.promoted_mir_of_opt_const_arg(def.to_global())[p].span;
347347
if let err_inval!(ReferencedConstant) = err.error {
348-
err.report_as_error(
348+
Err(err.report_as_error(
349349
tcx.at(span),
350350
"evaluation of constant expression failed",
351-
)
351+
))
352352
} else {
353-
err.report_as_lint(
353+
Err(err.report_as_lint(
354354
tcx.at(span),
355355
"reaching this expression at runtime will panic or abort",
356356
tcx.hir().local_def_id_to_hir_id(def.did),
357357
Some(err.span),
358-
)
358+
))
359359
}
360360
// anything else (array lengths, enum initializers, constant patterns) are
361361
// reported as hard errors
362362
} else {
363-
err.report_as_error(
363+
Err(err.report_as_error(
364364
ecx.tcx.at(ecx.cur_span()),
365365
"evaluation of constant value failed",
366-
)
366+
))
367367
}
368368
}
369369
}
370370
} else {
371371
// use of broken constant from other crate
372-
err.report_as_error(ecx.tcx.at(ecx.cur_span()), "could not evaluate constant")
372+
Err(err.report_as_error(ecx.tcx.at(ecx.cur_span()), "could not evaluate constant"))
373373
}
374-
})
375-
.and_then(|mplace| {
374+
}
375+
Ok(mplace) => {
376376
// Since evaluation had no errors, valiate the resulting constant:
377377
let validation = try {
378378
// FIXME do not validate promoteds until a decision on
@@ -404,5 +404,6 @@ pub fn const_eval_raw_provider<'tcx>(
404404
// Convert to raw constant
405405
Ok(RawConst { alloc_id: mplace.ptr.assert_ptr().alloc_id, ty: mplace.layout.ty })
406406
}
407-
})
407+
}
408+
}
408409
}

0 commit comments

Comments
 (0)