@@ -192,7 +192,10 @@ impl MirLowerCtx<'_> {
192
192
let base_ty = self . expr_ty_after_adjustments ( * base) ;
193
193
let index_ty = self . expr_ty_after_adjustments ( * index) ;
194
194
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
+ )
196
199
{
197
200
let Some ( index_fn) = self . infer . method_resolution ( expr_id) else {
198
201
return Err ( MirLowerError :: UnresolvedMethod ) ;
@@ -206,15 +209,16 @@ impl MirLowerCtx<'_> {
206
209
return self . lower_overloaded_index (
207
210
current,
208
211
base_place,
209
- self . expr_ty_after_adjustments ( * base ) ,
212
+ base_ty ,
210
213
self . expr_ty ( expr_id) ,
211
214
index_operand,
212
215
expr_id. into ( ) ,
213
216
index_fn,
214
217
) ;
215
218
}
216
219
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 {
218
222
return Ok ( None ) ;
219
223
} ;
220
224
let l_index = self . temp ( self . expr_ty_after_adjustments ( * index) ) ?;
@@ -238,23 +242,14 @@ impl MirLowerCtx<'_> {
238
242
span : MirSpan ,
239
243
index_fn : ( FunctionId , Substitution ) ,
240
244
) -> 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 } )
248
248
}
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 ) ,
254
250
} ;
255
- let base_ref = TyKind :: Ref ( mutability, static_lifetime ( ) , base_ty) . intern ( Interner ) ;
256
251
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 ( ) ;
258
253
self . push_assignment ( current, ref_place. clone ( ) , Rvalue :: Ref ( borrow_kind, place) , span) ;
259
254
let mut result: Place = self . temp ( result_ref) ?. into ( ) ;
260
255
let index_fn_op = Operand :: const_zst (
0 commit comments