@@ -219,28 +219,9 @@ impl<'cx, 'tcx> WritebackCx<'cx, 'tcx> {
219219 fn fix_index_builtin_expr ( & mut self , e : & hir:: Expr < ' _ > ) {
220220 if let hir:: ExprKind :: Index ( ref base, ref index, _) = e. kind {
221221 // All valid indexing looks like this; might encounter non-valid indexes at this point.
222- let base_ty = self . typeck_results . expr_ty_adjusted_opt ( base) ;
223- if base_ty. is_none ( ) {
224- // When encountering `return [0][0]` outside of a `fn` body we can encounter a base
225- // that isn't in the type table. We assume more relevant errors have already been
226- // emitted. (#64638)
227- assert ! ( self . tcx( ) . dcx( ) . has_errors( ) . is_some( ) , "bad base: `{base:?}`" ) ;
228- }
229- if let Some ( base_ty) = base_ty
230- && let ty:: Ref ( _, base_ty_inner, _) = * base_ty. kind ( )
231- {
232- let index_ty =
233- self . typeck_results . expr_ty_adjusted_opt ( index) . unwrap_or_else ( || {
234- // When encountering `return [0][0]` outside of a `fn` body we would attempt
235- // to access an nonexistent index. We assume that more relevant errors will
236- // already have been emitted, so we only gate on this with an ICE if no
237- // error has been emitted. (#64638)
238- Ty :: new_error_with_message (
239- self . fcx . tcx ,
240- e. span ,
241- format ! ( "bad index {index:?} for base: `{base:?}`" ) ,
242- )
243- } ) ;
222+ let base_ty = self . typeck_results . expr_ty_adjusted ( base) ;
223+ if let ty:: Ref ( _, base_ty_inner, _) = * base_ty. kind ( ) {
224+ let index_ty = self . typeck_results . expr_ty_adjusted ( index) ;
244225 if self . is_builtin_index ( e, base_ty_inner, index_ty) {
245226 // Remove the method call record
246227 self . typeck_results . type_dependent_defs_mut ( ) . remove ( e. hir_id ) ;
0 commit comments