From b8bd1d0826b8f792eccb97a6560d002832bff562 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Esteban=20K=C3=BCber?= Date: Thu, 8 Dec 2022 21:09:56 -0800 Subject: [PATCH] Fix span for `&mut ` removal suggestion --- .../src/diagnostics/move_errors.rs | 1 + .../borrowck-vec-pattern-nesting.stderr | 6 ++-- .../duplicate-suggestions.stderr | 20 ++++++------ .../dont-suggest-ref/simple.stderr | 32 +++++++++---------- 4 files changed, 30 insertions(+), 29 deletions(-) diff --git a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs index 862ae091604..033e4283645 100644 --- a/compiler/rustc_borrowck/src/diagnostics/move_errors.rs +++ b/compiler/rustc_borrowck/src/diagnostics/move_errors.rs @@ -481,6 +481,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { let (pat_span, suggestion, to_remove) = if inner_pat_snippet.starts_with("mut") && inner_pat_snippet["mut".len()..].starts_with(rustc_lexer::is_whitespace) { + let inner_pat_snippet = inner_pat_snippet["mut".len()..].trim_start(); let pat_span = pat_span.with_hi( pat_span.lo() + BytePos((pat_snippet.len() - inner_pat_snippet.len()) as u32), diff --git a/src/test/ui/borrowck/borrowck-vec-pattern-nesting.stderr b/src/test/ui/borrowck/borrowck-vec-pattern-nesting.stderr index 72d11b5d81a..0dc5e64e4ff 100644 --- a/src/test/ui/borrowck/borrowck-vec-pattern-nesting.stderr +++ b/src/test/ui/borrowck/borrowck-vec-pattern-nesting.stderr @@ -37,7 +37,7 @@ LL | &mut [_a, help: consider removing the mutable borrow | LL - &mut [_a, -LL + mut [_a, +LL + [_a, | error[E0508]: cannot move out of type `[Box]`, a non-copy slice @@ -69,7 +69,7 @@ LL | _b] => {} help: consider removing the mutable borrow | LL - &mut [ -LL + mut [ +LL + [ | error[E0508]: cannot move out of type `[Box]`, a non-copy slice @@ -102,7 +102,7 @@ LL | &mut [_a, _b, _c] => {} help: consider removing the mutable borrow | LL - &mut [_a, _b, _c] => {} -LL + mut [_a, _b, _c] => {} +LL + [_a, _b, _c] => {} | error[E0508]: cannot move out of type `[Box]`, a non-copy slice diff --git a/src/test/ui/suggestions/dont-suggest-ref/duplicate-suggestions.stderr b/src/test/ui/suggestions/dont-suggest-ref/duplicate-suggestions.stderr index 6ea7266a01b..b96b3713f2a 100644 --- a/src/test/ui/suggestions/dont-suggest-ref/duplicate-suggestions.stderr +++ b/src/test/ui/suggestions/dont-suggest-ref/duplicate-suggestions.stderr @@ -139,7 +139,7 @@ LL | let &mut (X(_t), X(_u)) = &mut (xm.clone(), xm.clone()); help: consider removing the mutable borrow | LL - let &mut (X(_t), X(_u)) = &mut (xm.clone(), xm.clone()); -LL + let mut (X(_t), X(_u)) = &mut (xm.clone(), xm.clone()); +LL + let (X(_t), X(_u)) = &mut (xm.clone(), xm.clone()); | error[E0507]: cannot move out of a mutable reference @@ -155,7 +155,7 @@ LL | if let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.c help: consider removing the mutable borrow | LL - if let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } -LL + if let mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } +LL + if let (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } | error[E0507]: cannot move out of a mutable reference @@ -171,7 +171,7 @@ LL | while let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), e help: consider removing the mutable borrow | LL - while let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } -LL + while let mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } +LL + while let (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { } | error[E0507]: cannot move out of a mutable reference @@ -192,12 +192,12 @@ LL | &mut (Either::Two(_t), Either::One(_u)) => (), help: consider removing the mutable borrow | LL - &mut (Either::One(_t), Either::Two(_u)) => (), -LL + mut (Either::One(_t), Either::Two(_u)) => (), +LL + (Either::One(_t), Either::Two(_u)) => (), | help: consider removing the mutable borrow | LL - &mut (Either::Two(_t), Either::One(_u)) => (), -LL + mut (Either::Two(_t), Either::One(_u)) => (), +LL + (Either::Two(_t), Either::One(_u)) => (), | error[E0507]: cannot move out of a mutable reference @@ -215,7 +215,7 @@ LL | &mut (Either::One(_t), Either::Two(_u)) help: consider removing the mutable borrow | LL - &mut (Either::One(_t), Either::Two(_u)) -LL + mut (Either::One(_t), Either::Two(_u)) +LL + (Either::One(_t), Either::Two(_u)) | error[E0507]: cannot move out of a mutable reference @@ -233,7 +233,7 @@ LL | &mut (Either::One(_t), Either::Two(_u)) => (), help: consider removing the mutable borrow | LL - &mut (Either::One(_t), Either::Two(_u)) => (), -LL + mut (Either::One(_t), Either::Two(_u)) => (), +LL + (Either::One(_t), Either::Two(_u)) => (), | error[E0507]: cannot move out of a mutable reference @@ -251,7 +251,7 @@ LL | &mut (Either::One(_t), Either::Two(_u)) => (), help: consider removing the mutable borrow | LL - &mut (Either::One(_t), Either::Two(_u)) => (), -LL + mut (Either::One(_t), Either::Two(_u)) => (), +LL + (Either::One(_t), Either::Two(_u)) => (), | error[E0507]: cannot move out of a mutable reference @@ -269,7 +269,7 @@ LL | &mut (Either::One(_t), Either::Two(_u)) => (), help: consider removing the mutable borrow | LL - &mut (Either::One(_t), Either::Two(_u)) => (), -LL + mut (Either::One(_t), Either::Two(_u)) => (), +LL + (Either::One(_t), Either::Two(_u)) => (), | error[E0507]: cannot move out of a shared reference @@ -301,7 +301,7 @@ LL | fn f6(&mut (X(_t), X(_u)): &mut (X, X)) { } help: consider removing the mutable borrow | LL - fn f6(&mut (X(_t), X(_u)): &mut (X, X)) { } -LL + fn f6(mut (X(_t), X(_u)): &mut (X, X)) { } +LL + fn f6((X(_t), X(_u)): &mut (X, X)) { } | error: aborting due to 17 previous errors diff --git a/src/test/ui/suggestions/dont-suggest-ref/simple.stderr b/src/test/ui/suggestions/dont-suggest-ref/simple.stderr index 39fd1c47697..9009aeec746 100644 --- a/src/test/ui/suggestions/dont-suggest-ref/simple.stderr +++ b/src/test/ui/suggestions/dont-suggest-ref/simple.stderr @@ -447,7 +447,7 @@ LL | let &mut X(_t) = sm; help: consider removing the mutable borrow | LL - let &mut X(_t) = sm; -LL + let mut X(_t) = sm; +LL + let X(_t) = sm; | error[E0507]: cannot move out of `rm` as enum variant `One` which is behind a mutable reference @@ -462,7 +462,7 @@ LL | if let &mut Either::One(_t) = rm { } help: consider removing the mutable borrow | LL - if let &mut Either::One(_t) = rm { } -LL + if let mut Either::One(_t) = rm { } +LL + if let Either::One(_t) = rm { } | error[E0507]: cannot move out of `rm` as enum variant `One` which is behind a mutable reference @@ -477,7 +477,7 @@ LL | while let &mut Either::One(_t) = rm { } help: consider removing the mutable borrow | LL - while let &mut Either::One(_t) = rm { } -LL + while let mut Either::One(_t) = rm { } +LL + while let Either::One(_t) = rm { } | error[E0507]: cannot move out of `rm` as enum variant `Two` which is behind a mutable reference @@ -496,12 +496,12 @@ LL | &mut Either::Two(_t) => (), help: consider removing the mutable borrow | LL - &mut Either::One(_t) => (), -LL + mut Either::One(_t) => (), +LL + Either::One(_t) => (), | help: consider removing the mutable borrow | LL - &mut Either::Two(_t) => (), -LL + mut Either::Two(_t) => (), +LL + Either::Two(_t) => (), | error[E0507]: cannot move out of `rm` as enum variant `One` which is behind a mutable reference @@ -519,7 +519,7 @@ LL | &mut Either::One(_t) => (), help: consider removing the mutable borrow | LL - &mut Either::One(_t) => (), -LL + mut Either::One(_t) => (), +LL + Either::One(_t) => (), | error[E0507]: cannot move out of `rm` as enum variant `One` which is behind a mutable reference @@ -537,7 +537,7 @@ LL | &mut Either::One(_t) => (), help: consider removing the mutable borrow | LL - &mut Either::One(_t) => (), -LL + mut Either::One(_t) => (), +LL + Either::One(_t) => (), | error[E0507]: cannot move out of `rm` as enum variant `One` which is behind a mutable reference @@ -555,7 +555,7 @@ LL | &mut Either::One(_t) => (), help: consider removing the mutable borrow | LL - &mut Either::One(_t) => (), -LL + mut Either::One(_t) => (), +LL + Either::One(_t) => (), | error[E0507]: cannot move out of a shared reference @@ -792,7 +792,7 @@ LL | let &mut X(_t) = &mut xm; help: consider removing the mutable borrow | LL - let &mut X(_t) = &mut xm; -LL + let mut X(_t) = &mut xm; +LL + let X(_t) = &mut xm; | error[E0507]: cannot move out of a mutable reference @@ -807,7 +807,7 @@ LL | if let &mut Either::One(_t) = &mut em { } help: consider removing the mutable borrow | LL - if let &mut Either::One(_t) = &mut em { } -LL + if let mut Either::One(_t) = &mut em { } +LL + if let Either::One(_t) = &mut em { } | error[E0507]: cannot move out of a mutable reference @@ -822,7 +822,7 @@ LL | while let &mut Either::One(_t) = &mut em { } help: consider removing the mutable borrow | LL - while let &mut Either::One(_t) = &mut em { } -LL + while let mut Either::One(_t) = &mut em { } +LL + while let Either::One(_t) = &mut em { } | error[E0507]: cannot move out of a mutable reference @@ -840,7 +840,7 @@ LL | &mut Either::One(_t) help: consider removing the mutable borrow | LL - &mut Either::One(_t) -LL + mut Either::One(_t) +LL + Either::One(_t) | error[E0507]: cannot move out of a mutable reference @@ -858,7 +858,7 @@ LL | &mut Either::One(_t) => (), help: consider removing the mutable borrow | LL - &mut Either::One(_t) => (), -LL + mut Either::One(_t) => (), +LL + Either::One(_t) => (), | error[E0507]: cannot move out of a mutable reference @@ -876,7 +876,7 @@ LL | &mut Either::One(_t) => (), help: consider removing the mutable borrow | LL - &mut Either::One(_t) => (), -LL + mut Either::One(_t) => (), +LL + Either::One(_t) => (), | error[E0507]: cannot move out of a mutable reference @@ -894,7 +894,7 @@ LL | &mut Either::One(_t) => (), help: consider removing the mutable borrow | LL - &mut Either::One(_t) => (), -LL + mut Either::One(_t) => (), +LL + Either::One(_t) => (), | error[E0507]: cannot move out of a shared reference @@ -924,7 +924,7 @@ LL | fn f2(&mut X(_t): &mut X) { } help: consider removing the mutable borrow | LL - fn f2(&mut X(_t): &mut X) { } -LL + fn f2(mut X(_t): &mut X) { } +LL + fn f2(X(_t): &mut X) { } | error[E0507]: cannot move out of a shared reference