@@ -279,13 +279,23 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
279279 }
280280 Entry :: Occupied ( mut entry) => {
281281 debug ! ( " - composing on top of {:?}" , entry. get( ) ) ;
282- match ( & entry. get ( ) [ ..] , & adj[ ..] ) {
283- // Applying any adjustment on top of a NeverToAny
284- // is a valid NeverToAny adjustment, because it can't
285- // be reached.
286- ( & [ Adjustment { kind : Adjust :: NeverToAny , .. } ] , _) => return ,
282+ match ( & mut entry. get_mut ( ) [ ..] , & adj[ ..] ) {
287283 (
288- & [
284+ [ Adjustment { kind : Adjust :: NeverToAny , target } ] ,
285+ & [ .., Adjustment { target : new_target, .. } ] ,
286+ ) => {
287+ // NeverToAny coercion can target any type, so instead of adding a new
288+ // adjustment on top we can change the target.
289+ //
290+ // This is required for things like `a == a` (where `a: !`) to produce
291+ // valid MIR -- we need borrow adjustment from things like `==` to change
292+ // the type to `&!` (or `&()` depending on the fallback). This might be
293+ // relevant even in unreachable code.
294+ * target = new_target;
295+ }
296+
297+ (
298+ & mut [
289299 Adjustment { kind : Adjust :: Deref ( _) , .. } ,
290300 Adjustment { kind : Adjust :: Borrow ( AutoBorrow :: Ref ( ..) ) , .. } ,
291301 ] ,
@@ -294,11 +304,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
294304 .., // Any following adjustments are allowed.
295305 ] ,
296306 ) => {
297- // A reborrow has no effect before a dereference.
307+ // A reborrow has no effect before a dereference, so we can safely replace adjustments.
308+ * entry. get_mut ( ) = adj;
298309 }
299- // FIXME: currently we never try to compose autoderefs
300- // and ReifyFnPointer/UnsafeFnPointer, but we could.
310+
301311 _ => {
312+ // FIXME: currently we never try to compose autoderefs
313+ // and ReifyFnPointer/UnsafeFnPointer, but we could.
302314 self . dcx ( ) . span_delayed_bug (
303315 expr. span ,
304316 format ! (
@@ -308,9 +320,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
308320 adj
309321 ) ,
310322 ) ;
323+
324+ * entry. get_mut ( ) = adj;
311325 }
312326 }
313- * entry. get_mut ( ) = adj;
314327 }
315328 }
316329
0 commit comments