Skip to content

Commit 0e6fb8e

Browse files
committed
review comments
1 parent 2ae87ff commit 0e6fb8e

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

src/librustc_typeck/check/writeback.rs

+14-11
Original file line numberDiff line numberDiff line change
@@ -192,20 +192,23 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
192192
// All valid indexing looks like this; might encounter non-valid indexes at this point.
193193
let base_ty = tables.expr_ty_adjusted_opt(&base).map(|t| &t.kind);
194194
if base_ty.is_none() {
195+
// When encountering `return [0][0]` outside of a `fn` body we can encounter a base
196+
// that isn't in the type table. We assume more relevant errors have already been
197+
// emitted, so we delay an ICE if none have. (#64638)
195198
self.tcx().sess.delay_span_bug(e.span, &format!("bad base: `{:?}`", base));
196-
return;
197199
}
198200
if let Some(ty::Ref(_, base_ty, _)) = base_ty {
199-
let index_ty = match tables.expr_ty_adjusted_opt(&index) {
200-
Some(t) => t,
201-
None => {
202-
self.tcx().sess.delay_span_bug(
203-
e.span,
204-
&format!("bad index {:?} for base: `{:?}`", index, base),
205-
);
206-
self.fcx.tcx.types.err
207-
}
208-
};
201+
let index_ty = tables.expr_ty_adjusted_opt(&index).unwrap_or_else(|| {
202+
// When encountering `return [0][0]` outside of a `fn` body we would attempt
203+
// to access an unexistend index. We assume that more relevant errors will
204+
// already have been emitted, so we only gate on this with an ICE if no
205+
// error has been emitted. (#64638)
206+
self.tcx().sess.delay_span_bug(
207+
e.span,
208+
&format!("bad index {:?} for base: `{:?}`", index, base),
209+
);
210+
self.fcx.tcx.types.err
211+
});
209212
let index_ty = self.fcx.resolve_vars_if_possible(&index_ty);
210213

211214
if base_ty.builtin_index().is_some() && index_ty == self.fcx.tcx.types.usize {

0 commit comments

Comments
 (0)