Skip to content

Commit b8bd1d0

Browse files
committed
Fix span for &mut removal suggestion
1 parent dd72b1a commit b8bd1d0

File tree

4 files changed

+30
-29
lines changed

4 files changed

+30
-29
lines changed

compiler/rustc_borrowck/src/diagnostics/move_errors.rs

+1
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> {
481481
let (pat_span, suggestion, to_remove) = if inner_pat_snippet.starts_with("mut")
482482
&& inner_pat_snippet["mut".len()..].starts_with(rustc_lexer::is_whitespace)
483483
{
484+
let inner_pat_snippet = inner_pat_snippet["mut".len()..].trim_start();
484485
let pat_span = pat_span.with_hi(
485486
pat_span.lo()
486487
+ BytePos((pat_snippet.len() - inner_pat_snippet.len()) as u32),

src/test/ui/borrowck/borrowck-vec-pattern-nesting.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ LL | &mut [_a,
3737
help: consider removing the mutable borrow
3838
|
3939
LL - &mut [_a,
40-
LL + mut [_a,
40+
LL + [_a,
4141
|
4242

4343
error[E0508]: cannot move out of type `[Box<isize>]`, a non-copy slice
@@ -69,7 +69,7 @@ LL | _b] => {}
6969
help: consider removing the mutable borrow
7070
|
7171
LL - &mut [
72-
LL + mut [
72+
LL + [
7373
|
7474

7575
error[E0508]: cannot move out of type `[Box<isize>]`, a non-copy slice
@@ -102,7 +102,7 @@ LL | &mut [_a, _b, _c] => {}
102102
help: consider removing the mutable borrow
103103
|
104104
LL - &mut [_a, _b, _c] => {}
105-
LL + mut [_a, _b, _c] => {}
105+
LL + [_a, _b, _c] => {}
106106
|
107107

108108
error[E0508]: cannot move out of type `[Box<isize>]`, a non-copy slice

src/test/ui/suggestions/dont-suggest-ref/duplicate-suggestions.stderr

+10-10
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ LL | let &mut (X(_t), X(_u)) = &mut (xm.clone(), xm.clone());
139139
help: consider removing the mutable borrow
140140
|
141141
LL - let &mut (X(_t), X(_u)) = &mut (xm.clone(), xm.clone());
142-
LL + let mut (X(_t), X(_u)) = &mut (xm.clone(), xm.clone());
142+
LL + let (X(_t), X(_u)) = &mut (xm.clone(), xm.clone());
143143
|
144144

145145
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
155155
help: consider removing the mutable borrow
156156
|
157157
LL - if let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { }
158-
LL + if let mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { }
158+
LL + if let (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { }
159159
|
160160

161161
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
171171
help: consider removing the mutable borrow
172172
|
173173
LL - while let &mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { }
174-
LL + while let mut (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { }
174+
LL + while let (Either::One(_t), Either::Two(_u)) = &mut (em.clone(), em.clone()) { }
175175
|
176176

177177
error[E0507]: cannot move out of a mutable reference
@@ -192,12 +192,12 @@ LL | &mut (Either::Two(_t), Either::One(_u)) => (),
192192
help: consider removing the mutable borrow
193193
|
194194
LL - &mut (Either::One(_t), Either::Two(_u)) => (),
195-
LL + mut (Either::One(_t), Either::Two(_u)) => (),
195+
LL + (Either::One(_t), Either::Two(_u)) => (),
196196
|
197197
help: consider removing the mutable borrow
198198
|
199199
LL - &mut (Either::Two(_t), Either::One(_u)) => (),
200-
LL + mut (Either::Two(_t), Either::One(_u)) => (),
200+
LL + (Either::Two(_t), Either::One(_u)) => (),
201201
|
202202

203203
error[E0507]: cannot move out of a mutable reference
@@ -215,7 +215,7 @@ LL | &mut (Either::One(_t), Either::Two(_u))
215215
help: consider removing the mutable borrow
216216
|
217217
LL - &mut (Either::One(_t), Either::Two(_u))
218-
LL + mut (Either::One(_t), Either::Two(_u))
218+
LL + (Either::One(_t), Either::Two(_u))
219219
|
220220

221221
error[E0507]: cannot move out of a mutable reference
@@ -233,7 +233,7 @@ LL | &mut (Either::One(_t), Either::Two(_u)) => (),
233233
help: consider removing the mutable borrow
234234
|
235235
LL - &mut (Either::One(_t), Either::Two(_u)) => (),
236-
LL + mut (Either::One(_t), Either::Two(_u)) => (),
236+
LL + (Either::One(_t), Either::Two(_u)) => (),
237237
|
238238

239239
error[E0507]: cannot move out of a mutable reference
@@ -251,7 +251,7 @@ LL | &mut (Either::One(_t), Either::Two(_u)) => (),
251251
help: consider removing the mutable borrow
252252
|
253253
LL - &mut (Either::One(_t), Either::Two(_u)) => (),
254-
LL + mut (Either::One(_t), Either::Two(_u)) => (),
254+
LL + (Either::One(_t), Either::Two(_u)) => (),
255255
|
256256

257257
error[E0507]: cannot move out of a mutable reference
@@ -269,7 +269,7 @@ LL | &mut (Either::One(_t), Either::Two(_u)) => (),
269269
help: consider removing the mutable borrow
270270
|
271271
LL - &mut (Either::One(_t), Either::Two(_u)) => (),
272-
LL + mut (Either::One(_t), Either::Two(_u)) => (),
272+
LL + (Either::One(_t), Either::Two(_u)) => (),
273273
|
274274

275275
error[E0507]: cannot move out of a shared reference
@@ -301,7 +301,7 @@ LL | fn f6(&mut (X(_t), X(_u)): &mut (X, X)) { }
301301
help: consider removing the mutable borrow
302302
|
303303
LL - fn f6(&mut (X(_t), X(_u)): &mut (X, X)) { }
304-
LL + fn f6(mut (X(_t), X(_u)): &mut (X, X)) { }
304+
LL + fn f6((X(_t), X(_u)): &mut (X, X)) { }
305305
|
306306

307307
error: aborting due to 17 previous errors

src/test/ui/suggestions/dont-suggest-ref/simple.stderr

+16-16
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ LL | let &mut X(_t) = sm;
447447
help: consider removing the mutable borrow
448448
|
449449
LL - let &mut X(_t) = sm;
450-
LL + let mut X(_t) = sm;
450+
LL + let X(_t) = sm;
451451
|
452452

453453
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 { }
462462
help: consider removing the mutable borrow
463463
|
464464
LL - if let &mut Either::One(_t) = rm { }
465-
LL + if let mut Either::One(_t) = rm { }
465+
LL + if let Either::One(_t) = rm { }
466466
|
467467

468468
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 { }
477477
help: consider removing the mutable borrow
478478
|
479479
LL - while let &mut Either::One(_t) = rm { }
480-
LL + while let mut Either::One(_t) = rm { }
480+
LL + while let Either::One(_t) = rm { }
481481
|
482482

483483
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) => (),
496496
help: consider removing the mutable borrow
497497
|
498498
LL - &mut Either::One(_t) => (),
499-
LL + mut Either::One(_t) => (),
499+
LL + Either::One(_t) => (),
500500
|
501501
help: consider removing the mutable borrow
502502
|
503503
LL - &mut Either::Two(_t) => (),
504-
LL + mut Either::Two(_t) => (),
504+
LL + Either::Two(_t) => (),
505505
|
506506

507507
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) => (),
519519
help: consider removing the mutable borrow
520520
|
521521
LL - &mut Either::One(_t) => (),
522-
LL + mut Either::One(_t) => (),
522+
LL + Either::One(_t) => (),
523523
|
524524

525525
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) => (),
537537
help: consider removing the mutable borrow
538538
|
539539
LL - &mut Either::One(_t) => (),
540-
LL + mut Either::One(_t) => (),
540+
LL + Either::One(_t) => (),
541541
|
542542

543543
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) => (),
555555
help: consider removing the mutable borrow
556556
|
557557
LL - &mut Either::One(_t) => (),
558-
LL + mut Either::One(_t) => (),
558+
LL + Either::One(_t) => (),
559559
|
560560

561561
error[E0507]: cannot move out of a shared reference
@@ -792,7 +792,7 @@ LL | let &mut X(_t) = &mut xm;
792792
help: consider removing the mutable borrow
793793
|
794794
LL - let &mut X(_t) = &mut xm;
795-
LL + let mut X(_t) = &mut xm;
795+
LL + let X(_t) = &mut xm;
796796
|
797797

798798
error[E0507]: cannot move out of a mutable reference
@@ -807,7 +807,7 @@ LL | if let &mut Either::One(_t) = &mut em { }
807807
help: consider removing the mutable borrow
808808
|
809809
LL - if let &mut Either::One(_t) = &mut em { }
810-
LL + if let mut Either::One(_t) = &mut em { }
810+
LL + if let Either::One(_t) = &mut em { }
811811
|
812812

813813
error[E0507]: cannot move out of a mutable reference
@@ -822,7 +822,7 @@ LL | while let &mut Either::One(_t) = &mut em { }
822822
help: consider removing the mutable borrow
823823
|
824824
LL - while let &mut Either::One(_t) = &mut em { }
825-
LL + while let mut Either::One(_t) = &mut em { }
825+
LL + while let Either::One(_t) = &mut em { }
826826
|
827827

828828
error[E0507]: cannot move out of a mutable reference
@@ -840,7 +840,7 @@ LL | &mut Either::One(_t)
840840
help: consider removing the mutable borrow
841841
|
842842
LL - &mut Either::One(_t)
843-
LL + mut Either::One(_t)
843+
LL + Either::One(_t)
844844
|
845845

846846
error[E0507]: cannot move out of a mutable reference
@@ -858,7 +858,7 @@ LL | &mut Either::One(_t) => (),
858858
help: consider removing the mutable borrow
859859
|
860860
LL - &mut Either::One(_t) => (),
861-
LL + mut Either::One(_t) => (),
861+
LL + Either::One(_t) => (),
862862
|
863863

864864
error[E0507]: cannot move out of a mutable reference
@@ -876,7 +876,7 @@ LL | &mut Either::One(_t) => (),
876876
help: consider removing the mutable borrow
877877
|
878878
LL - &mut Either::One(_t) => (),
879-
LL + mut Either::One(_t) => (),
879+
LL + Either::One(_t) => (),
880880
|
881881

882882
error[E0507]: cannot move out of a mutable reference
@@ -894,7 +894,7 @@ LL | &mut Either::One(_t) => (),
894894
help: consider removing the mutable borrow
895895
|
896896
LL - &mut Either::One(_t) => (),
897-
LL + mut Either::One(_t) => (),
897+
LL + Either::One(_t) => (),
898898
|
899899

900900
error[E0507]: cannot move out of a shared reference
@@ -924,7 +924,7 @@ LL | fn f2(&mut X(_t): &mut X) { }
924924
help: consider removing the mutable borrow
925925
|
926926
LL - fn f2(&mut X(_t): &mut X) { }
927-
LL + fn f2(mut X(_t): &mut X) { }
927+
LL + fn f2(X(_t): &mut X) { }
928928
|
929929

930930
error[E0507]: cannot move out of a shared reference

0 commit comments

Comments
 (0)