Prevent ICE in autodiff validation by emitting user-friendly errors
This commit is contained in:
parent
7c4a55c2ac
commit
6b29bb6680
1 changed files with 8 additions and 2 deletions
|
@ -930,13 +930,19 @@ fn autodiff_attrs(tcx: TyCtxt<'_>, id: DefId) -> Option<AutoDiffAttrs> {
|
|||
}
|
||||
}
|
||||
|
||||
// Validate input and return activities
|
||||
let mut msg = "".to_string();
|
||||
for &input in &arg_activities {
|
||||
if !valid_input_activity(mode, input) {
|
||||
span_bug!(attr.span(), "Invalid input activity {} for {} mode", input, mode);
|
||||
msg = format!("Invalid input activity {} for {} mode", input, mode);
|
||||
}
|
||||
}
|
||||
if !valid_ret_activity(mode, ret_activity) {
|
||||
span_bug!(attr.span(), "Invalid return activity {} for {} mode", ret_activity, mode);
|
||||
msg = format!("Invalid return activity {} for {} mode", ret_activity, mode);
|
||||
}
|
||||
if msg != "".to_string() {
|
||||
tcx.dcx().struct_span_err(attr.span(), msg).with_note("invalid activity").emit();
|
||||
return Some(AutoDiffAttrs::error());
|
||||
}
|
||||
|
||||
Some(AutoDiffAttrs { mode, ret_activity, input_activity: arg_activities })
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue