@@ -119,7 +119,7 @@ pub fn trans_into<'blk, 'tcx>(bcx: Block<'blk, 'tcx>,
119
119
120
120
debuginfo:: set_source_location ( bcx. fcx , expr. id , expr. span ) ;
121
121
122
- if bcx . tcx ( ) . tables . borrow ( ) . adjustments . contains_key ( & expr. id ) {
122
+ if adjustment_required ( bcx , expr) {
123
123
// use trans, which may be less efficient but
124
124
// which will perform the adjustments:
125
125
let datum = unpack_datum ! ( bcx, trans( bcx, expr) ) ;
@@ -334,6 +334,37 @@ pub fn unsized_info<'ccx, 'tcx>(ccx: &CrateContext<'ccx, 'tcx>,
334
334
}
335
335
}
336
336
337
+ fn adjustment_required < ' blk , ' tcx > ( bcx : Block < ' blk , ' tcx > ,
338
+ expr : & hir:: Expr ) -> bool {
339
+ let adjustment = match bcx. tcx ( ) . tables . borrow ( ) . adjustments . get ( & expr. id ) . cloned ( ) {
340
+ None => { return false ; }
341
+ Some ( adj) => adj
342
+ } ;
343
+
344
+ // Don't skip a conversion from Box<T> to &T, etc.
345
+ if bcx. tcx ( ) . is_overloaded_autoderef ( expr. id , 0 ) {
346
+ return true ;
347
+ }
348
+
349
+ match adjustment {
350
+ AdjustReifyFnPointer => {
351
+ // FIXME(#19925) once fn item types are
352
+ // zero-sized, we'll need to return true here
353
+ false
354
+ }
355
+ AdjustUnsafeFnPointer => {
356
+ // purely a type-level thing
357
+ false
358
+ }
359
+ AdjustDerefRef ( ref adj) => {
360
+ // We are a bit paranoid about adjustments and thus might have a re-
361
+ // borrow here which merely derefs and then refs again (it might have
362
+ // a different region or mutability, but we don't care here).
363
+ !( adj. autoderefs == 1 && adj. autoref . is_some ( ) && adj. unsize . is_none ( ) )
364
+ }
365
+ }
366
+ }
367
+
337
368
/// Helper for trans that apply adjustments from `expr` to `datum`, which should be the unadjusted
338
369
/// translation of `expr`.
339
370
fn apply_adjustments < ' blk , ' tcx > ( bcx : Block < ' blk , ' tcx > ,
0 commit comments