Tweak output to account for alternative bindings in the same pattern
This commit is contained in:
parent
24f80ea7d7
commit
5993f5d0f8
@ -192,26 +192,23 @@ pub(crate) fn report_use_of_moved_or_uninitialized(
|
||||
is_loop_move = true;
|
||||
}
|
||||
|
||||
self.suggest_ref_or_clone(
|
||||
mpi,
|
||||
move_span,
|
||||
&mut err,
|
||||
&mut seen_spans,
|
||||
&mut in_pattern,
|
||||
);
|
||||
if !seen_spans.contains(&move_span) {
|
||||
self.suggest_ref_or_clone(mpi, move_span, &mut err, &mut in_pattern);
|
||||
|
||||
self.explain_captures(
|
||||
&mut err,
|
||||
span,
|
||||
move_span,
|
||||
move_spans,
|
||||
*moved_place,
|
||||
partially_str,
|
||||
loop_message,
|
||||
move_msg,
|
||||
is_loop_move,
|
||||
maybe_reinitialized_locations.is_empty(),
|
||||
);
|
||||
self.explain_captures(
|
||||
&mut err,
|
||||
span,
|
||||
move_span,
|
||||
move_spans,
|
||||
*moved_place,
|
||||
partially_str,
|
||||
loop_message,
|
||||
move_msg,
|
||||
is_loop_move,
|
||||
maybe_reinitialized_locations.is_empty(),
|
||||
);
|
||||
}
|
||||
seen_spans.insert(move_span);
|
||||
}
|
||||
|
||||
use_spans.var_path_only_subdiag(&mut err, desired_action);
|
||||
@ -312,7 +309,6 @@ fn suggest_ref_or_clone(
|
||||
mpi: MovePathIndex,
|
||||
move_span: Span,
|
||||
err: &mut DiagnosticBuilder<'_, ErrorGuaranteed>,
|
||||
seen_spans: &mut FxHashSet<Span>,
|
||||
in_pattern: &mut bool,
|
||||
) {
|
||||
struct ExpressionFinder<'hir> {
|
||||
@ -436,7 +432,7 @@ fn visit_pat(&mut self, p: &'hir hir::Pat<'hir>) {
|
||||
}
|
||||
}
|
||||
}
|
||||
if let Some(pat) = finder.pat && !seen_spans.contains(&pat.span) {
|
||||
if let Some(pat) = finder.pat {
|
||||
*in_pattern = true;
|
||||
err.span_suggestion_verbose(
|
||||
pat.span.shrink_to_lo(),
|
||||
@ -444,7 +440,6 @@ fn visit_pat(&mut self, p: &'hir hir::Pat<'hir>) {
|
||||
"ref ".to_string(),
|
||||
Applicability::MachineApplicable,
|
||||
);
|
||||
seen_spans.insert(pat.span);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -76,10 +76,7 @@ LL | fn bindings_after_at_or_patterns_move(x: Option<Test>) {
|
||||
| - move occurs because `x` has type `Option<Test>`, which does not implement the `Copy` trait
|
||||
LL | match x {
|
||||
LL | foo @ Some(Test::Foo | Test::Bar) => (),
|
||||
| ---
|
||||
| |
|
||||
| value moved here
|
||||
| value moved here
|
||||
| --- value moved here
|
||||
...
|
||||
LL | &x;
|
||||
| ^^ value borrowed here after move
|
||||
@ -132,10 +129,7 @@ LL | fn bindings_after_at_slice_patterns_or_patterns_moves(x: [Option<Test>; 4])
|
||||
| - move occurs because `x` has type `[Option<Test>; 4]`, which does not implement the `Copy` trait
|
||||
LL | match x {
|
||||
LL | a @ [.., Some(Test::Foo | Test::Bar)] => (),
|
||||
| -
|
||||
| |
|
||||
| value moved here
|
||||
| value moved here
|
||||
| - value moved here
|
||||
...
|
||||
LL | &x;
|
||||
| ^^ value borrowed here after move
|
||||
|
Loading…
Reference in New Issue
Block a user