review comments
This commit is contained in:
parent
2ae87ff59d
commit
0e6fb8e8da
1 changed files with 14 additions and 11 deletions
|
@ -192,20 +192,23 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
|
|||
// All valid indexing looks like this; might encounter non-valid indexes at this point.
|
||||
let base_ty = tables.expr_ty_adjusted_opt(&base).map(|t| &t.kind);
|
||||
if base_ty.is_none() {
|
||||
// When encountering `return [0][0]` outside of a `fn` body we can encounter a base
|
||||
// that isn't in the type table. We assume more relevant errors have already been
|
||||
// emitted, so we delay an ICE if none have. (#64638)
|
||||
self.tcx().sess.delay_span_bug(e.span, &format!("bad base: `{:?}`", base));
|
||||
return;
|
||||
}
|
||||
if let Some(ty::Ref(_, base_ty, _)) = base_ty {
|
||||
let index_ty = match tables.expr_ty_adjusted_opt(&index) {
|
||||
Some(t) => t,
|
||||
None => {
|
||||
self.tcx().sess.delay_span_bug(
|
||||
e.span,
|
||||
&format!("bad index {:?} for base: `{:?}`", index, base),
|
||||
);
|
||||
self.fcx.tcx.types.err
|
||||
}
|
||||
};
|
||||
let index_ty = tables.expr_ty_adjusted_opt(&index).unwrap_or_else(|| {
|
||||
// When encountering `return [0][0]` outside of a `fn` body we would attempt
|
||||
// to access an unexistend index. We assume that more relevant errors will
|
||||
// already have been emitted, so we only gate on this with an ICE if no
|
||||
// error has been emitted. (#64638)
|
||||
self.tcx().sess.delay_span_bug(
|
||||
e.span,
|
||||
&format!("bad index {:?} for base: `{:?}`", index, base),
|
||||
);
|
||||
self.fcx.tcx.types.err
|
||||
});
|
||||
let index_ty = self.fcx.resolve_vars_if_possible(&index_ty);
|
||||
|
||||
if base_ty.builtin_index().is_some() && index_ty == self.fcx.tcx.types.usize {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue