Skip to content

Commit 6402fd0

Browse files
Refine deref suggestions
1 parent 2bddfca commit 6402fd0

2 files changed

Lines changed: 9 additions & 6 deletions

File tree

compiler/rustc_borrowck/src/diagnostics/move_errors.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,10 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
800800
let mut is_raw_ptr = false;
801801
let mut is_ref = false;
802802
let mut is_destructuring_assignment = false;
803+
let mut is_nested_deref = false;
803804
if let Some(inner) = inner {
805+
is_nested_deref =
806+
matches!(inner.kind, hir::ExprKind::Unary(hir::UnOp::Deref, _));
804807
let typck_result = self.infcx.tcx.typeck(self.mir_def_id());
805808
if let Some(inner_type) = typck_result.node_type_opt(inner.hir_id) {
806809
if matches!(inner_type.kind(), ty::RawPtr(..)) {
@@ -829,7 +832,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
829832
String::new(),
830833
Applicability::MaybeIncorrect,
831834
);
832-
} else if !is_raw_ptr && !is_destructuring_assignment {
835+
} else if !is_raw_ptr && !is_destructuring_assignment && !is_nested_deref {
833836
err.span_suggestion_verbose(
834837
span.shrink_to_lo(),
835838
"consider borrowing here",

tests/ui/suggestions/issue-102892.stderr

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,12 +61,12 @@ LL | let (a, b) = **arc; // suggests putting `&**arc` here; with that, fixed
6161
| | ...and here
6262
| data moved here
6363
|
64-
= note: move occurs because these variables have types that don't implement the `Copy` trait
65-
help: consider removing the dereference here
66-
|
67-
LL - let (a, b) = **arc; // suggests putting `&**arc` here; with that, fixed!
68-
LL + let (a, b) = *arc; // suggests putting `&**arc` here; with that, fixed!
64+
help: destructuring assignment cannot borrow from this expression; consider using a `let` binding instead
65+
--> $DIR/issue-102892.rs:11:18
6966
|
67+
LL | let (a, b) = **arc; // suggests putting `&**arc` here; with that, fixed!
68+
| ^^^^^
69+
= note: move occurs because these variables have types that don't implement the `Copy` trait
7070

7171
error: aborting due to 4 previous errors
7272

0 commit comments

Comments
 (0)