@@ -167,26 +167,26 @@ enum ProbeResult {
167
167
/// T`, we could convert it to `*const T`, then autoref to `&*const T`. However, currently we do
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
- #[ derive( Debug , PartialEq , Clone ) ]
171
- pub enum AutorefOrPtrAdjustment < ' tcx > {
170
+ #[ derive( Debug , PartialEq , Copy , Clone ) ]
171
+ pub enum AutorefOrPtrAdjustment {
172
172
/// Receiver has type `T`, add `&` or `&mut` (it `T` is `mut`), and maybe also "unsize" it.
173
173
/// Unsizing is used to convert a `[T; N]` to `[T]`, which only makes sense when autorefing.
174
174
Autoref {
175
175
mutbl : hir:: Mutability ,
176
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 > > ,
177
+ /// Indicates that the source expression should be "unsized" to a target type.
178
+ /// This is special-cased for just arrays unsizing to slices .
179
+ unsize : bool ,
180
180
} ,
181
181
/// Receiver has type `*mut T`, convert to `*const T`
182
182
ToConstPtr ,
183
183
}
184
184
185
- impl < ' tcx > AutorefOrPtrAdjustment < ' tcx > {
186
- fn get_unsize ( & self ) -> Option < Ty < ' tcx > > {
185
+ impl AutorefOrPtrAdjustment {
186
+ fn get_unsize ( & self ) -> bool {
187
187
match self {
188
188
AutorefOrPtrAdjustment :: Autoref { mutbl : _, unsize } => * unsize,
189
- AutorefOrPtrAdjustment :: ToConstPtr => None ,
189
+ AutorefOrPtrAdjustment :: ToConstPtr => false ,
190
190
}
191
191
}
192
192
}
@@ -204,7 +204,7 @@ pub struct Pick<'tcx> {
204
204
205
205
/// Indicates that we want to add an autoref (and maybe also unsize it), or if the receiver is
206
206
/// `*mut T`, convert it to `*const T`.
207
- pub autoref_or_ptr_adjustment : Option < AutorefOrPtrAdjustment < ' tcx > > ,
207
+ pub autoref_or_ptr_adjustment : Option < AutorefOrPtrAdjustment > ,
208
208
pub self_ty : Ty < ' tcx > ,
209
209
}
210
210
@@ -1202,7 +1202,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1202
1202
pick. autoderefs += 1 ;
1203
1203
pick. autoref_or_ptr_adjustment = Some ( AutorefOrPtrAdjustment :: Autoref {
1204
1204
mutbl,
1205
- unsize : pick. autoref_or_ptr_adjustment . and_then ( |a| a. get_unsize ( ) ) ,
1205
+ unsize : pick. autoref_or_ptr_adjustment . map_or ( false , |a| a. get_unsize ( ) ) ,
1206
1206
} )
1207
1207
}
1208
1208
@@ -1227,10 +1227,8 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
1227
1227
self . pick_method ( autoref_ty, unstable_candidates) . map ( |r| {
1228
1228
r. map ( |mut pick| {
1229
1229
pick. autoderefs = step. autoderefs ;
1230
- pick. autoref_or_ptr_adjustment = Some ( AutorefOrPtrAdjustment :: Autoref {
1231
- mutbl,
1232
- unsize : step. unsize . then_some ( self_ty) ,
1233
- } ) ;
1230
+ pick. autoref_or_ptr_adjustment =
1231
+ Some ( AutorefOrPtrAdjustment :: Autoref { mutbl, unsize : step. unsize } ) ;
1234
1232
pick
1235
1233
} )
1236
1234
} )
0 commit comments