Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions compiler/rustc_hir_typeck/src/coercion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,17 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
)
.must_apply_modulo_regions() =>
{
// Ordinary non-argument coercion contexts should keep an identity use
// as a move/copy when normal unification is sufficient. Argument
// coercions use this path for implicit generic reborrows, so preserve
// the existing reborrow-first behavior there.
if self.allow_two_phase == AllowTwoPhase::No {
let plain_unify = self.commit_if_ok(|_| self.unify(a, b, ForceLeakCheck::No));
if plain_unify.is_ok() {
return plain_unify;
}
}

let reborrow_coerce = self.commit_if_ok(|_| self.coerce_reborrow(a, b));
if reborrow_coerce.is_ok() {
return reborrow_coerce;
Expand Down
26 changes: 26 additions & 0 deletions tests/ui/reborrow/identity_move.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
//@ run-pass

#![feature(reborrow)]

use std::marker::Reborrow;

struct Thing<'a>(&'a mut usize);

impl<'a> Reborrow for Thing<'a> {}

impl Drop for Thing<'_> {
fn drop(&mut self) {
*self.0 += 1;
}
}

fn main() {
let mut drops = 0;

{
let thing = Thing(&mut drops);
let _moved: Thing<'_> = thing;
}

assert_eq!(drops, 1);
}
Loading