Skip to content

Commit fface0c

Browse files
committed
Do not suggest ref multiple times for the same binding
1 parent 98cb7c8 commit fface0c

File tree

2 files changed

+3
-9
lines changed

2 files changed

+3
-9
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
171171

172172
let mut is_loop_move = false;
173173
let mut in_pattern = false;
174+
let mut seen_spans = FxHashSet::default();
174175

175176
for move_site in &move_site_vec {
176177
let move_out = self.move_data.moves[(*move_site).moi];
@@ -320,14 +321,15 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
320321
self.suggest_cloning(&mut err, ty, move_span);
321322
}
322323
}
323-
if let Some(pat) = finder.pat {
324+
if let Some(pat) = finder.pat && !seen_spans.contains(&pat.span) {
324325
in_pattern = true;
325326
err.span_suggestion_verbose(
326327
pat.span.shrink_to_lo(),
327328
"borrow this binding in the pattern to avoid moving the value",
328329
"ref ".to_string(),
329330
Applicability::MachineApplicable,
330331
);
332+
seen_spans.insert(pat.span);
331333
}
332334
}
333335

src/test/ui/borrowck/bindings-after-at-or-patterns-slice-patterns-box-patterns.stderr

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,6 @@ help: borrow this binding in the pattern to avoid moving the value
8888
|
8989
LL | ref foo @ Some(Test::Foo | Test::Bar) => (),
9090
| +++
91-
help: borrow this binding in the pattern to avoid moving the value
92-
|
93-
LL | ref foo @ Some(Test::Foo | Test::Bar) => (),
94-
| +++
9591

9692
error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable
9793
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:86:5
@@ -148,10 +144,6 @@ help: borrow this binding in the pattern to avoid moving the value
148144
|
149145
LL | ref a @ [.., Some(Test::Foo | Test::Bar)] => (),
150146
| +++
151-
help: borrow this binding in the pattern to avoid moving the value
152-
|
153-
LL | ref a @ [.., Some(Test::Foo | Test::Bar)] => (),
154-
| +++
155147

156148
error[E0502]: cannot borrow `x` as mutable because it is also borrowed as immutable
157149
--> $DIR/bindings-after-at-or-patterns-slice-patterns-box-patterns.rs:144:5

0 commit comments

Comments
 (0)