-
Notifications
You must be signed in to change notification settings - Fork 13.3k
[const_panic] Report const_panic diagnostics identically to compiler_error invocations #79695
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,12 +22,15 @@ pub enum ConstEvalErrKind { | |
Panic { msg: Symbol, line: u32, col: u32, file: Symbol }, | ||
} | ||
|
||
// The errors become `MachineStop` with plain strings when being raised. | ||
// Non-panic errors become `MachineStop` with plain strings when being raised. | ||
// `ConstEvalErr` (in `librustc_middle/mir/interpret/error.rs`) knows to | ||
// handle these. | ||
impl<'tcx> Into<InterpErrorInfo<'tcx>> for ConstEvalErrKind { | ||
fn into(self) -> InterpErrorInfo<'tcx> { | ||
err_machine_stop!(self.to_string()).into() | ||
match self { | ||
ConstEvalErrKind::Panic { msg, .. } => InterpError::Panic(msg).into(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we can mirror what miri does here. Instead of having an enum TerminationInfo {
Generic(String),
Panic(String),
} Then you can downcast to |
||
_ => err_machine_stop!(self.to_string()).into(), | ||
} | ||
} | ||
} | ||
|
||
|
@@ -150,13 +153,14 @@ impl<'tcx> ConstEvalErr<'tcx> { | |
}; | ||
trace!("reporting const eval failure at {:?}", self.span); | ||
|
||
let err_msg = match &self.error { | ||
let (err_msg, is_panic) = match &self.error { | ||
InterpError::MachineStop(msg) => { | ||
// A custom error (`ConstEvalErrKind` in `librustc_mir/interp/const_eval/error.rs`). | ||
// Should be turned into a string by now. | ||
msg.downcast_ref::<String>().expect("invalid MachineStop payload").clone() | ||
(msg.downcast_ref::<String>().expect("invalid MachineStop payload").clone(), false) | ||
} | ||
err => err.to_string(), | ||
InterpError::Panic(msg) => (msg.to_string(), true), | ||
err => (err.to_string(), false), | ||
}; | ||
|
||
let finish = |mut err: DiagnosticBuilder<'_>, span_msg: Option<String>| { | ||
|
@@ -193,7 +197,13 @@ impl<'tcx> ConstEvalErr<'tcx> { | |
rustc_session::lint::builtin::CONST_ERR, | ||
hir_id, | ||
tcx.span, | ||
|lint| finish(lint.build(message), Some(err_msg)), | ||
|lint| { | ||
if is_panic { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think something similar needs to be done for the |
||
finish(lint.build(&err_msg), None) | ||
} else { | ||
finish(lint.build(message), Some(err_msg)) | ||
} | ||
}, | ||
); | ||
ErrorHandled::Linted | ||
} else { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a CTFE-only error, I don't think it should be added here. This is more of a case for the
MachineStopType
.