@@ -168,29 +168,13 @@ enum ProbeResult {
168
168
/// (at most) one of these. Either the receiver has type `T` and we convert it to `&T` (or with
169
169
/// `mut`), or it has type `*mut T` and we convert it to `*const T`.
170
170
#[ derive( Debug , PartialEq , Clone ) ]
171
- pub enum AutorefOrPtrAdjustment < ' tcx > {
172
- /// Receiver has type `T`, add `&` or `&mut` (it `T` is `mut`), and maybe also "unsize" it.
173
- /// Unsizing is used to convert a `[T; N]` to `[T]`, which only makes sense when autorefing.
174
- Autoref {
175
- mutbl : hir:: Mutability ,
176
-
177
- /// Indicates that the source expression should be "unsized" to a target type. This should
178
- /// probably eventually go away in favor of just coercing method receivers.
179
- unsize : Option < Ty < ' tcx > > ,
180
- } ,
171
+ pub enum AutorefOrPtrAdjustment {
172
+ /// Receiver has type `T`, add `&` or `&mut` (it `T` is `mut`)
173
+ Autoref { mutbl : hir:: Mutability } ,
181
174
/// Receiver has type `*mut T`, convert to `*const T`
182
175
ToConstPtr ,
183
176
}
184
177
185
- impl < ' tcx > AutorefOrPtrAdjustment < ' tcx > {
186
- fn get_unsize ( & self ) -> Option < Ty < ' tcx > > {
187
- match self {
188
- AutorefOrPtrAdjustment :: Autoref { mutbl : _, unsize } => * unsize,
189
- AutorefOrPtrAdjustment :: ToConstPtr => None ,
190
- }
191
- }
192
- }
193
-
194
178
#[ derive( Debug , PartialEq , Clone ) ]
195
179
pub struct Pick < ' tcx > {
196
180
pub item : ty:: AssocItem ,
@@ -204,7 +188,7 @@ pub struct Pick<'tcx> {
204
188
205
189
/// Indicates that we want to add an autoref (and maybe also unsize it), or if the receiver is
206
190
/// `*mut T`, convert it to `*const T`.
207
- pub autoref_or_ptr_adjustment : Option < AutorefOrPtrAdjustment < ' tcx > > ,
191
+ pub autoref_or_ptr_adjustment : Option < AutorefOrPtrAdjustment > ,
208
192
pub self_ty : Ty < ' tcx > ,
209
193
}
210
194
@@ -371,7 +355,6 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
371
355
) ,
372
356
autoderefs: 0 ,
373
357
from_unsafe_deref: false ,
374
- unsize: false ,
375
358
} ] ) ,
376
359
opt_bad_ty : None ,
377
360
reached_recursion_limit : false ,
@@ -483,7 +466,7 @@ fn method_autoderef_steps<'tcx>(
483
466
. include_raw_pointers ( )
484
467
. silence_errors ( ) ;
485
468
let mut reached_raw_pointer = false ;
486
- let mut steps: Vec < _ > = autoderef
469
+ let steps: Vec < _ > = autoderef
487
470
. by_ref ( )
488
471
. map ( |( ty, d) | {
489
472
let step = CandidateStep {
@@ -493,7 +476,6 @@ fn method_autoderef_steps<'tcx>(
493
476
) ,
494
477
autoderefs : d,
495
478
from_unsafe_deref : reached_raw_pointer,
496
- unsize : false ,
497
479
} ;
498
480
if let ty:: RawPtr ( _) = ty. kind ( ) {
499
481
// all the subsequent steps will be from_unsafe_deref
@@ -510,23 +492,6 @@ fn method_autoderef_steps<'tcx>(
510
492
ty : infcx
511
493
. make_query_response_ignoring_pending_obligations ( inference_vars, final_ty) ,
512
494
} ) ,
513
- ty:: Array ( elem_ty, _) => {
514
- let dereferences = steps. len ( ) - 1 ;
515
-
516
- steps. push ( CandidateStep {
517
- self_ty : infcx. make_query_response_ignoring_pending_obligations (
518
- inference_vars,
519
- infcx. tcx . mk_slice ( elem_ty) ,
520
- ) ,
521
- autoderefs : dereferences,
522
- // this could be from an unsafe deref if we had
523
- // a *mut/const [T; N]
524
- from_unsafe_deref : reached_raw_pointer,
525
- unsize : true ,
526
- } ) ;
527
-
528
- None
529
- }
530
495
_ => None ,
531
496
} ;
532
497
@@ -1189,21 +1154,14 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1189
1154
self_ty : Ty < ' tcx > ,
1190
1155
unstable_candidates : Option < & mut Vec < ( Candidate < ' tcx > , Symbol ) > > ,
1191
1156
) -> Option < PickResult < ' tcx > > {
1192
- if step. unsize {
1193
- return None ;
1194
- }
1195
-
1196
1157
self . pick_method ( self_ty, unstable_candidates) . map ( |r| {
1197
1158
r. map ( |mut pick| {
1198
1159
pick. autoderefs = step. autoderefs ;
1199
1160
1200
1161
// Insert a `&*` or `&mut *` if this is a reference type:
1201
1162
if let ty:: Ref ( _, _, mutbl) = * step. self_ty . value . value . kind ( ) {
1202
1163
pick. autoderefs += 1 ;
1203
- pick. autoref_or_ptr_adjustment = Some ( AutorefOrPtrAdjustment :: Autoref {
1204
- mutbl,
1205
- unsize : pick. autoref_or_ptr_adjustment . and_then ( |a| a. get_unsize ( ) ) ,
1206
- } )
1164
+ pick. autoref_or_ptr_adjustment = Some ( AutorefOrPtrAdjustment :: Autoref { mutbl } )
1207
1165
}
1208
1166
1209
1167
pick
@@ -1227,10 +1185,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1227
1185
self . pick_method ( autoref_ty, unstable_candidates) . map ( |r| {
1228
1186
r. map ( |mut pick| {
1229
1187
pick. autoderefs = step. autoderefs ;
1230
- pick. autoref_or_ptr_adjustment = Some ( AutorefOrPtrAdjustment :: Autoref {
1231
- mutbl,
1232
- unsize : step. unsize . then_some ( self_ty) ,
1233
- } ) ;
1188
+ pick. autoref_or_ptr_adjustment = Some ( AutorefOrPtrAdjustment :: Autoref { mutbl } ) ;
1234
1189
pick
1235
1190
} )
1236
1191
} )
@@ -1245,11 +1200,6 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1245
1200
self_ty : Ty < ' tcx > ,
1246
1201
unstable_candidates : Option < & mut Vec < ( Candidate < ' tcx > , Symbol ) > > ,
1247
1202
) -> Option < PickResult < ' tcx > > {
1248
- // Don't convert an unsized reference to ptr
1249
- if step. unsize {
1250
- return None ;
1251
- }
1252
-
1253
1203
let ty = match self_ty. kind ( ) {
1254
1204
ty:: RawPtr ( ty:: TypeAndMut { ty, mutbl : hir:: Mutability :: Mut } ) => ty,
1255
1205
_ => return None ,
0 commit comments