fix ICE for deref coercions with type errors
This commit is contained in:
parent
b17491c8f6
commit
95c5b06000
4 changed files with 39 additions and 12 deletions
|
@ -91,10 +91,6 @@ impl<'a, 'tcx> Iterator for Autoderef<'a, 'tcx> {
|
|||
return None;
|
||||
};
|
||||
|
||||
if new_ty.references_error() {
|
||||
return None;
|
||||
}
|
||||
|
||||
self.state.steps.push((self.state.cur_ty, kind));
|
||||
debug!(
|
||||
"autoderef stage #{:?} is {:?} from {:?}",
|
||||
|
@ -137,6 +133,10 @@ impl<'a, 'tcx> Autoderef<'a, 'tcx> {
|
|||
debug!("overloaded_deref_ty({:?})", ty);
|
||||
let tcx = self.infcx.tcx;
|
||||
|
||||
if ty.references_error() {
|
||||
return None;
|
||||
}
|
||||
|
||||
// <ty as Deref>
|
||||
let trait_ref = ty::TraitRef::new(tcx, tcx.lang_items().deref_trait()?, [ty]);
|
||||
let cause = traits::ObligationCause::misc(self.span, self.body_id);
|
||||
|
|
|
@ -1635,6 +1635,12 @@ fn check_method_receiver<'tcx>(
|
|||
let receiver_ty = sig.inputs()[0];
|
||||
let receiver_ty = wfcx.normalize(span, None, receiver_ty);
|
||||
|
||||
// If the receiver already has errors reported, consider it valid to avoid
|
||||
// unnecessary errors (#58712).
|
||||
if receiver_ty.references_error() {
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if tcx.features().arbitrary_self_types {
|
||||
if !receiver_is_valid(wfcx, span, receiver_ty, self_ty, true) {
|
||||
// Report error; `arbitrary_self_types` was enabled.
|
||||
|
@ -1749,9 +1755,7 @@ fn receiver_is_valid<'tcx>(
|
|||
}
|
||||
} else {
|
||||
debug!("receiver_is_valid: type `{:?}` does not deref to `{:?}`", receiver_ty, self_ty);
|
||||
// If the receiver already has errors reported due to it, consider it valid to avoid
|
||||
// unnecessary errors (#58712).
|
||||
return receiver_ty.references_error();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue