@@ -410,6 +410,49 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
410410 // is problematic as the HIR is being scraped, but ref bindings may be
411411 // implicit after #42640. We need to make sure that pat_adjustments
412412 // (once introduced) is populated by the time we get here.
413+ //
414+ // arielb1 [writes here in this comment thread][c] that there
415+ // is certainly *some* potential danger, e.g. for an example
416+ // like:
417+ //
418+ // [c]: https://github.com/rust-lang/rust/pull/43399#discussion_r130223956
419+ //
420+ // ```
421+ // let Foo(x) = f()[0];
422+ // ```
423+ //
424+ // Then if the pattern matches by reference, we want to match
425+ // `f()[0]` as a lexpr, so we can't allow it to be
426+ // coerced. But if the pattern matches by value, `f()[0]` is
427+ // still syntactically a lexpr, but we *do* want to allow
428+ // coercions.
429+ //
430+ // However, *likely* we are ok with allowing coercions to
431+ // happen if there are no explicit ref mut patterns - all
432+ // implicit ref mut patterns must occur behind a reference, so
433+ // they will have the "correct" variance and lifetime.
434+ //
435+ // This does mean that the following pattern would be legal:
436+ //
437+ // ```
438+ // struct Foo(Bar);
439+ // struct Bar(u32);
440+ // impl Deref for Foo {
441+ // type Target = Bar;
442+ // fn deref(&self) -> &Bar { &self.0 }
443+ // }
444+ // impl DerefMut for Foo {
445+ // fn deref_mut(&mut self) -> &mut Bar { &mut self.0 }
446+ // }
447+ // fn foo(x: &mut Foo) {
448+ // {
449+ // let Bar(z): &mut Bar = x;
450+ // *z = 42;
451+ // }
452+ // assert_eq!(foo.0.0, 42);
453+ // }
454+ // ```
455+
413456 let contains_ref_bindings = arms. iter ( )
414457 . filter_map ( |a| a. contains_explicit_ref_binding ( ) )
415458 . max_by_key ( |m| match * m {
0 commit comments