Skip to content

Commit

Permalink
Rollup merge of #102486 - pierwill:middle-const-eval-err, r=compiler-…
Browse files Browse the repository at this point in the history
…errors

Add diagnostic struct for const eval error in `rustc_middle`

Part of #100717.

r? `@ghost`
  • Loading branch information
matthiaskrgr authored Oct 3, 2022
2 parents 1dfd3ab + b9c0467 commit a3abc61
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
3 changes: 3 additions & 0 deletions compiler/rustc_error_messages/locales/en-US/middle.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,6 @@ middle_previous_use_here =
middle_limit_invalid =
`limit` must be a non-negative integer
.label = {$error_str}
middle_const_eval_non_int =
constant evaluation of enum discriminant resulted in non-integer
7 changes: 7 additions & 0 deletions compiler/rustc_middle/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,10 @@ pub struct LimitInvalid<'a> {
pub value_span: Span,
pub error_str: &'a str,
}

#[derive(Diagnostic)]
#[diag(middle::const_eval_non_int)]
pub struct ConstEvalNonIntError {
#[primary_span]
pub span: Span,
}
8 changes: 3 additions & 5 deletions compiler/rustc_middle/src/ty/adt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,11 +458,9 @@ impl<'tcx> AdtDef<'tcx> {
Some(Discr { val: b, ty })
} else {
info!("invalid enum discriminant: {:#?}", val);
crate::mir::interpret::struct_error(
tcx.at(tcx.def_span(expr_did)),
"constant evaluation of enum discriminant resulted in non-integer",
)
.emit();
tcx.sess.emit_err(crate::error::ConstEvalNonIntError {
span: tcx.def_span(expr_did),
});
None
}
}
Expand Down

0 comments on commit a3abc61

Please sign in to comment.