@@ -192,7 +192,10 @@ impl MirLowerCtx<'_> {
192192 let base_ty = self . expr_ty_after_adjustments ( * base) ;
193193 let index_ty = self . expr_ty_after_adjustments ( * index) ;
194194 if index_ty != TyBuilder :: usize ( )
195- || !matches ! ( base_ty. kind( Interner ) , TyKind :: Array ( ..) | TyKind :: Slice ( ..) )
195+ || !matches ! (
196+ base_ty. strip_reference( ) . kind( Interner ) ,
197+ TyKind :: Array ( ..) | TyKind :: Slice ( ..)
198+ )
196199 {
197200 let Some ( index_fn) = self . infer . method_resolution ( expr_id) else {
198201 return Err ( MirLowerError :: UnresolvedMethod ) ;
@@ -206,15 +209,16 @@ impl MirLowerCtx<'_> {
206209 return self . lower_overloaded_index (
207210 current,
208211 base_place,
209- self . expr_ty_after_adjustments ( * base ) ,
212+ base_ty ,
210213 self . expr_ty ( expr_id) ,
211214 index_operand,
212215 expr_id. into ( ) ,
213216 index_fn,
214217 ) ;
215218 }
216219 let Some ( ( mut p_base, current) ) =
217- self . lower_expr_as_place ( current, * base, true ) ? else {
220+ self . lower_expr_as_place_without_adjust ( current, * base, true ) ?
221+ else {
218222 return Ok ( None ) ;
219223 } ;
220224 let l_index = self . temp ( self . expr_ty_after_adjustments ( * index) ) ?;
@@ -238,23 +242,14 @@ impl MirLowerCtx<'_> {
238242 span : MirSpan ,
239243 index_fn : ( FunctionId , Substitution ) ,
240244 ) -> Result < Option < ( Place , BasicBlockId ) > > {
241- let is_mutable = ' b: {
242- if let Some ( index_mut_trait) = self . resolve_lang_item ( LangItem :: IndexMut ) ?. as_trait ( ) {
243- if let Some ( index_mut_fn) =
244- self . db . trait_data ( index_mut_trait) . method_by_name ( & name ! [ index_mut] )
245- {
246- break ' b index_mut_fn == index_fn. 0 ;
247- }
245+ let ( mutability, borrow_kind) = match base_ty. as_reference ( ) {
246+ Some ( ( _, _, mutability) ) => {
247+ ( mutability, BorrowKind :: Mut { allow_two_phase_borrow : false } )
248248 }
249- false
250- } ;
251- let ( mutability, borrow_kind) = match is_mutable {
252- true => ( Mutability :: Mut , BorrowKind :: Mut { allow_two_phase_borrow : false } ) ,
253- false => ( Mutability :: Not , BorrowKind :: Shared ) ,
249+ None => ( Mutability :: Not , BorrowKind :: Shared ) ,
254250 } ;
255- let base_ref = TyKind :: Ref ( mutability, static_lifetime ( ) , base_ty) . intern ( Interner ) ;
256251 let result_ref = TyKind :: Ref ( mutability, static_lifetime ( ) , result_ty) . intern ( Interner ) ;
257- let ref_place: Place = self . temp ( base_ref ) ?. into ( ) ;
252+ let ref_place: Place = self . temp ( base_ty ) ?. into ( ) ;
258253 self . push_assignment ( current, ref_place. clone ( ) , Rvalue :: Ref ( borrow_kind, place) , span) ;
259254 let mut result: Place = self . temp ( result_ref) ?. into ( ) ;
260255 let index_fn_op = Operand :: const_zst (
0 commit comments