Better span for "make binding mutable" suggestion
This commit is contained in:
parent
140392b041
commit
89ecae5d85
@ -3757,13 +3757,11 @@ pub(crate) fn report_illegal_reassignment(
|
|||||||
assigned_span: Span,
|
assigned_span: Span,
|
||||||
err_place: Place<'tcx>,
|
err_place: Place<'tcx>,
|
||||||
) {
|
) {
|
||||||
let (from_arg, local_decl, local_name) = match err_place.as_local() {
|
let (from_arg, local_decl) = match err_place.as_local() {
|
||||||
Some(local) => (
|
Some(local) => {
|
||||||
self.body.local_kind(local) == LocalKind::Arg,
|
(self.body.local_kind(local) == LocalKind::Arg, Some(&self.body.local_decls[local]))
|
||||||
Some(&self.body.local_decls[local]),
|
}
|
||||||
self.local_names[local],
|
None => (false, None),
|
||||||
),
|
|
||||||
None => (false, None, None),
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// If root local is initialized immediately (everything apart from let
|
// If root local is initialized immediately (everything apart from let
|
||||||
@ -3795,13 +3793,12 @@ pub(crate) fn report_illegal_reassignment(
|
|||||||
err.span_label(assigned_span, format!("first assignment to {place_description}"));
|
err.span_label(assigned_span, format!("first assignment to {place_description}"));
|
||||||
}
|
}
|
||||||
if let Some(decl) = local_decl
|
if let Some(decl) = local_decl
|
||||||
&& let Some(name) = local_name
|
|
||||||
&& decl.can_be_made_mutable()
|
&& decl.can_be_made_mutable()
|
||||||
{
|
{
|
||||||
err.span_suggestion(
|
err.span_suggestion_verbose(
|
||||||
decl.source_info.span,
|
decl.source_info.span.shrink_to_lo(),
|
||||||
"consider making this binding mutable",
|
"consider making this binding mutable",
|
||||||
format!("mut {name}"),
|
"mut ".to_string(),
|
||||||
Applicability::MachineApplicable,
|
Applicability::MachineApplicable,
|
||||||
);
|
);
|
||||||
if !from_arg
|
if !from_arg
|
||||||
@ -3813,10 +3810,10 @@ pub(crate) fn report_illegal_reassignment(
|
|||||||
}))
|
}))
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
err.span_suggestion(
|
err.span_suggestion_verbose(
|
||||||
decl.source_info.span,
|
decl.source_info.span.shrink_to_lo(),
|
||||||
"to modify the original value, take a borrow instead",
|
"to modify the original value, take a borrow instead",
|
||||||
format!("ref mut {name}"),
|
"ref mut ".to_string(),
|
||||||
Applicability::MaybeIncorrect,
|
Applicability::MaybeIncorrect,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
fn test() {
|
fn test() {
|
||||||
let v: isize;
|
let v: isize;
|
||||||
//~^ HELP consider making this binding mutable
|
//~^ HELP consider making this binding mutable
|
||||||
//~| SUGGESTION mut v
|
//~| SUGGESTION mut
|
||||||
v = 1; //~ NOTE first assignment
|
v = 1; //~ NOTE first assignment
|
||||||
println!("v={}", v);
|
println!("v={}", v);
|
||||||
v = 2; //~ ERROR cannot assign twice to immutable variable
|
v = 2; //~ ERROR cannot assign twice to immutable variable
|
||||||
|
@ -1,14 +1,16 @@
|
|||||||
error[E0384]: cannot assign twice to immutable variable `v`
|
error[E0384]: cannot assign twice to immutable variable `v`
|
||||||
--> $DIR/assign-imm-local-twice.rs:7:5
|
--> $DIR/assign-imm-local-twice.rs:7:5
|
||||||
|
|
|
|
||||||
LL | let v: isize;
|
|
||||||
| - help: consider making this binding mutable: `mut v`
|
|
||||||
...
|
|
||||||
LL | v = 1;
|
LL | v = 1;
|
||||||
| ----- first assignment to `v`
|
| ----- first assignment to `v`
|
||||||
LL | println!("v={}", v);
|
LL | println!("v={}", v);
|
||||||
LL | v = 2;
|
LL | v = 2;
|
||||||
| ^^^^^ cannot assign twice to immutable variable
|
| ^^^^^ cannot assign twice to immutable variable
|
||||||
|
|
|
||||||
|
help: consider making this binding mutable
|
||||||
|
|
|
||||||
|
LL | let mut v: isize;
|
||||||
|
| +++
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
@ -13,12 +13,14 @@ error[E0384]: cannot assign twice to immutable variable `x`
|
|||||||
--> $DIR/issue-61452.rs:9:5
|
--> $DIR/issue-61452.rs:9:5
|
||||||
|
|
|
|
||||||
LL | pub async fn g(x: usize) {
|
LL | pub async fn g(x: usize) {
|
||||||
| -
|
| - first assignment to `x`
|
||||||
| |
|
|
||||||
| first assignment to `x`
|
|
||||||
| help: consider making this binding mutable: `mut x`
|
|
||||||
LL | x += 1;
|
LL | x += 1;
|
||||||
| ^^^^^^ cannot assign twice to immutable variable
|
| ^^^^^^ cannot assign twice to immutable variable
|
||||||
|
|
|
||||||
|
help: consider making this binding mutable
|
||||||
|
|
|
||||||
|
LL | pub async fn g(mut x: usize) {
|
||||||
|
| +++
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
@ -9,11 +9,11 @@ LL | x += 1;
|
|||||||
help: consider making this binding mutable
|
help: consider making this binding mutable
|
||||||
|
|
|
|
||||||
LL | mut x => {
|
LL | mut x => {
|
||||||
| ~~~~~
|
| +++
|
||||||
help: to modify the original value, take a borrow instead
|
help: to modify the original value, take a borrow instead
|
||||||
|
|
|
|
||||||
LL | ref mut x => {
|
LL | ref mut x => {
|
||||||
| ~~~~~~~~~
|
| +++++++
|
||||||
|
|
||||||
error[E0384]: cannot assign twice to immutable variable `x`
|
error[E0384]: cannot assign twice to immutable variable `x`
|
||||||
--> $DIR/borrowck-match-binding-is-assignment.rs:20:13
|
--> $DIR/borrowck-match-binding-is-assignment.rs:20:13
|
||||||
@ -26,11 +26,11 @@ LL | x += 1;
|
|||||||
help: consider making this binding mutable
|
help: consider making this binding mutable
|
||||||
|
|
|
|
||||||
LL | E::Foo(mut x) => {
|
LL | E::Foo(mut x) => {
|
||||||
| ~~~~~
|
| +++
|
||||||
help: to modify the original value, take a borrow instead
|
help: to modify the original value, take a borrow instead
|
||||||
|
|
|
|
||||||
LL | E::Foo(ref mut x) => {
|
LL | E::Foo(ref mut x) => {
|
||||||
| ~~~~~~~~~
|
| +++++++
|
||||||
|
|
||||||
error[E0384]: cannot assign twice to immutable variable `x`
|
error[E0384]: cannot assign twice to immutable variable `x`
|
||||||
--> $DIR/borrowck-match-binding-is-assignment.rs:26:13
|
--> $DIR/borrowck-match-binding-is-assignment.rs:26:13
|
||||||
@ -43,11 +43,11 @@ LL | x += 1;
|
|||||||
help: consider making this binding mutable
|
help: consider making this binding mutable
|
||||||
|
|
|
|
||||||
LL | S { bar: mut x } => {
|
LL | S { bar: mut x } => {
|
||||||
| ~~~~~
|
| +++
|
||||||
help: to modify the original value, take a borrow instead
|
help: to modify the original value, take a borrow instead
|
||||||
|
|
|
|
||||||
LL | S { bar: ref mut x } => {
|
LL | S { bar: ref mut x } => {
|
||||||
| ~~~~~~~~~
|
| +++++++
|
||||||
|
|
||||||
error[E0384]: cannot assign twice to immutable variable `x`
|
error[E0384]: cannot assign twice to immutable variable `x`
|
||||||
--> $DIR/borrowck-match-binding-is-assignment.rs:32:13
|
--> $DIR/borrowck-match-binding-is-assignment.rs:32:13
|
||||||
@ -60,11 +60,11 @@ LL | x += 1;
|
|||||||
help: consider making this binding mutable
|
help: consider making this binding mutable
|
||||||
|
|
|
|
||||||
LL | (mut x,) => {
|
LL | (mut x,) => {
|
||||||
| ~~~~~
|
| +++
|
||||||
help: to modify the original value, take a borrow instead
|
help: to modify the original value, take a borrow instead
|
||||||
|
|
|
|
||||||
LL | (ref mut x,) => {
|
LL | (ref mut x,) => {
|
||||||
| ~~~~~~~~~
|
| +++++++
|
||||||
|
|
||||||
error[E0384]: cannot assign twice to immutable variable `x`
|
error[E0384]: cannot assign twice to immutable variable `x`
|
||||||
--> $DIR/borrowck-match-binding-is-assignment.rs:38:13
|
--> $DIR/borrowck-match-binding-is-assignment.rs:38:13
|
||||||
@ -77,11 +77,11 @@ LL | x += 1;
|
|||||||
help: consider making this binding mutable
|
help: consider making this binding mutable
|
||||||
|
|
|
|
||||||
LL | [mut x,_,_] => {
|
LL | [mut x,_,_] => {
|
||||||
| ~~~~~
|
| +++
|
||||||
help: to modify the original value, take a borrow instead
|
help: to modify the original value, take a borrow instead
|
||||||
|
|
|
|
||||||
LL | [ref mut x,_,_] => {
|
LL | [ref mut x,_,_] => {
|
||||||
| ~~~~~~~~~
|
| +++++++
|
||||||
|
|
||||||
error: aborting due to 5 previous errors
|
error: aborting due to 5 previous errors
|
||||||
|
|
||||||
|
@ -1,10 +1,13 @@
|
|||||||
error[E0384]: cannot assign to immutable argument `_x`
|
error[E0384]: cannot assign to immutable argument `_x`
|
||||||
--> $DIR/immutable-arg.rs:2:5
|
--> $DIR/immutable-arg.rs:2:5
|
||||||
|
|
|
|
||||||
LL | fn foo(_x: u32) {
|
|
||||||
| -- help: consider making this binding mutable: `mut _x`
|
|
||||||
LL | _x = 4;
|
LL | _x = 4;
|
||||||
| ^^^^^^ cannot assign to immutable argument
|
| ^^^^^^ cannot assign to immutable argument
|
||||||
|
|
|
||||||
|
help: consider making this binding mutable
|
||||||
|
|
|
||||||
|
LL | fn foo(mut _x: u32) {
|
||||||
|
| +++
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
fn test_drop_replace() {
|
fn test_drop_replace() {
|
||||||
let b: Box<isize>;
|
let b: Box<isize>;
|
||||||
//~^ HELP consider making this binding mutable
|
//~^ HELP consider making this binding mutable
|
||||||
//~| SUGGESTION mut b
|
//~| SUGGESTION mut
|
||||||
b = Box::new(1); //~ NOTE first assignment
|
b = Box::new(1); //~ NOTE first assignment
|
||||||
b = Box::new(2); //~ ERROR cannot assign twice to immutable variable `b`
|
b = Box::new(2); //~ ERROR cannot assign twice to immutable variable `b`
|
||||||
//~| NOTE cannot assign twice to immutable
|
//~| NOTE cannot assign twice to immutable
|
||||||
@ -10,13 +10,13 @@ fn test_drop_replace() {
|
|||||||
fn test_call() {
|
fn test_call() {
|
||||||
let b = Box::new(1); //~ NOTE first assignment
|
let b = Box::new(1); //~ NOTE first assignment
|
||||||
//~| HELP consider making this binding mutable
|
//~| HELP consider making this binding mutable
|
||||||
//~| SUGGESTION mut b
|
//~| SUGGESTION mut
|
||||||
b = Box::new(2); //~ ERROR cannot assign twice to immutable variable `b`
|
b = Box::new(2); //~ ERROR cannot assign twice to immutable variable `b`
|
||||||
//~| NOTE cannot assign twice to immutable
|
//~| NOTE cannot assign twice to immutable
|
||||||
}
|
}
|
||||||
|
|
||||||
fn test_args(b: Box<i32>) { //~ HELP consider making this binding mutable
|
fn test_args(b: Box<i32>) { //~ HELP consider making this binding mutable
|
||||||
//~| SUGGESTION mut b
|
//~| SUGGESTION mut
|
||||||
b = Box::new(2); //~ ERROR cannot assign to immutable argument `b`
|
b = Box::new(2); //~ ERROR cannot assign to immutable argument `b`
|
||||||
//~| NOTE cannot assign to immutable argument
|
//~| NOTE cannot assign to immutable argument
|
||||||
}
|
}
|
||||||
|
@ -1,34 +1,40 @@
|
|||||||
error[E0384]: cannot assign twice to immutable variable `b`
|
error[E0384]: cannot assign twice to immutable variable `b`
|
||||||
--> $DIR/issue-45199.rs:6:5
|
--> $DIR/issue-45199.rs:6:5
|
||||||
|
|
|
|
||||||
LL | let b: Box<isize>;
|
|
||||||
| - help: consider making this binding mutable: `mut b`
|
|
||||||
...
|
|
||||||
LL | b = Box::new(1);
|
LL | b = Box::new(1);
|
||||||
| - first assignment to `b`
|
| - first assignment to `b`
|
||||||
LL | b = Box::new(2);
|
LL | b = Box::new(2);
|
||||||
| ^ cannot assign twice to immutable variable
|
| ^ cannot assign twice to immutable variable
|
||||||
|
|
|
||||||
|
help: consider making this binding mutable
|
||||||
|
|
|
||||||
|
LL | let mut b: Box<isize>;
|
||||||
|
| +++
|
||||||
|
|
||||||
error[E0384]: cannot assign twice to immutable variable `b`
|
error[E0384]: cannot assign twice to immutable variable `b`
|
||||||
--> $DIR/issue-45199.rs:14:5
|
--> $DIR/issue-45199.rs:14:5
|
||||||
|
|
|
|
||||||
LL | let b = Box::new(1);
|
LL | let b = Box::new(1);
|
||||||
| -
|
| - first assignment to `b`
|
||||||
| |
|
|
||||||
| first assignment to `b`
|
|
||||||
| help: consider making this binding mutable: `mut b`
|
|
||||||
...
|
...
|
||||||
LL | b = Box::new(2);
|
LL | b = Box::new(2);
|
||||||
| ^ cannot assign twice to immutable variable
|
| ^ cannot assign twice to immutable variable
|
||||||
|
|
|
||||||
|
help: consider making this binding mutable
|
||||||
|
|
|
||||||
|
LL | let mut b = Box::new(1);
|
||||||
|
| +++
|
||||||
|
|
||||||
error[E0384]: cannot assign to immutable argument `b`
|
error[E0384]: cannot assign to immutable argument `b`
|
||||||
--> $DIR/issue-45199.rs:20:5
|
--> $DIR/issue-45199.rs:20:5
|
||||||
|
|
|
|
||||||
LL | fn test_args(b: Box<i32>) {
|
|
||||||
| - help: consider making this binding mutable: `mut b`
|
|
||||||
LL |
|
|
||||||
LL | b = Box::new(2);
|
LL | b = Box::new(2);
|
||||||
| ^ cannot assign to immutable argument
|
| ^ cannot assign to immutable argument
|
||||||
|
|
|
||||||
|
help: consider making this binding mutable
|
||||||
|
|
|
||||||
|
LL | fn test_args(mut b: Box<i32>) {
|
||||||
|
| +++
|
||||||
|
|
||||||
error: aborting due to 3 previous errors
|
error: aborting due to 3 previous errors
|
||||||
|
|
||||||
|
@ -9,11 +9,11 @@ LL | x = 2;
|
|||||||
help: consider making this binding mutable
|
help: consider making this binding mutable
|
||||||
|
|
|
|
||||||
LL | if let Some(mut x) = y {
|
LL | if let Some(mut x) = y {
|
||||||
| ~~~~~
|
| +++
|
||||||
help: to modify the original value, take a borrow instead
|
help: to modify the original value, take a borrow instead
|
||||||
|
|
|
|
||||||
LL | if let Some(ref mut x) = y {
|
LL | if let Some(ref mut x) = y {
|
||||||
| ~~~~~~~~~
|
| +++++++
|
||||||
|
|
||||||
error[E0384]: cannot assign twice to immutable variable `x`
|
error[E0384]: cannot assign twice to immutable variable `x`
|
||||||
--> $DIR/suggest-ref-mut-issue-118596.rs:9:5
|
--> $DIR/suggest-ref-mut-issue-118596.rs:9:5
|
||||||
@ -26,11 +26,11 @@ LL | x = 0;
|
|||||||
help: consider making this binding mutable
|
help: consider making this binding mutable
|
||||||
|
|
|
|
||||||
LL | let [mut x, ref xs_hold @ ..] = arr;
|
LL | let [mut x, ref xs_hold @ ..] = arr;
|
||||||
| ~~~~~
|
| +++
|
||||||
help: to modify the original value, take a borrow instead
|
help: to modify the original value, take a borrow instead
|
||||||
|
|
|
|
||||||
LL | let [ref mut x, ref xs_hold @ ..] = arr;
|
LL | let [ref mut x, ref xs_hold @ ..] = arr;
|
||||||
| ~~~~~~~~~
|
| +++++++
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
@ -2,12 +2,14 @@ error[E0384]: cannot assign twice to immutable variable `a`
|
|||||||
--> $DIR/tainted-promoteds.rs:7:5
|
--> $DIR/tainted-promoteds.rs:7:5
|
||||||
|
|
|
|
||||||
LL | let a = 0;
|
LL | let a = 0;
|
||||||
| -
|
| - first assignment to `a`
|
||||||
| |
|
|
||||||
| first assignment to `a`
|
|
||||||
| help: consider making this binding mutable: `mut a`
|
|
||||||
LL | a = &0 * &1 * &2 * &3;
|
LL | a = &0 * &1 * &2 * &3;
|
||||||
| ^^^^^^^^^^^^^^^^^^^^^ cannot assign twice to immutable variable
|
| ^^^^^^^^^^^^^^^^^^^^^ cannot assign twice to immutable variable
|
||||||
|
|
|
||||||
|
help: consider making this binding mutable
|
||||||
|
|
|
||||||
|
LL | let mut a = 0;
|
||||||
|
| +++
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
@ -2,12 +2,14 @@ error[E0384]: cannot assign twice to immutable variable `x`
|
|||||||
--> $DIR/command-line-diagnostics.rs:6:5
|
--> $DIR/command-line-diagnostics.rs:6:5
|
||||||
|
|
|
|
||||||
LL | let x = 42;
|
LL | let x = 42;
|
||||||
| -
|
| - first assignment to `x`
|
||||||
| |
|
|
||||||
| first assignment to `x`
|
|
||||||
| help: consider making this binding mutable: `mut x`
|
|
||||||
LL | x = 43;
|
LL | x = 43;
|
||||||
| ^^^^^^ cannot assign twice to immutable variable
|
| ^^^^^^ cannot assign twice to immutable variable
|
||||||
|
|
|
||||||
|
help: consider making this binding mutable
|
||||||
|
|
|
||||||
|
LL | let mut x = 42;
|
||||||
|
| +++
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
@ -16,10 +16,13 @@ LL | fn foo<'a>(mut x: Ref<'a, 'a>, y: &'a u32) {
|
|||||||
error[E0384]: cannot assign to immutable argument `y`
|
error[E0384]: cannot assign to immutable argument `y`
|
||||||
--> $DIR/ex3-both-anon-regions-one-is-struct-2.rs:4:5
|
--> $DIR/ex3-both-anon-regions-one-is-struct-2.rs:4:5
|
||||||
|
|
|
|
||||||
LL | fn foo(mut x: Ref, y: &u32) {
|
|
||||||
| - help: consider making this binding mutable: `mut y`
|
|
||||||
LL | y = x.b;
|
LL | y = x.b;
|
||||||
| ^^^^^^^ cannot assign to immutable argument
|
| ^^^^^^^ cannot assign to immutable argument
|
||||||
|
|
|
||||||
|
help: consider making this binding mutable
|
||||||
|
|
|
||||||
|
LL | fn foo(mut x: Ref, mut y: &u32) {
|
||||||
|
| +++
|
||||||
|
|
||||||
error: aborting due to 2 previous errors
|
error: aborting due to 2 previous errors
|
||||||
|
|
||||||
|
@ -1,45 +1,53 @@
|
|||||||
error[E0384]: cannot assign twice to immutable variable `x`
|
error[E0384]: cannot assign twice to immutable variable `x`
|
||||||
--> $DIR/liveness-assign-imm-local-notes.rs:10:9
|
--> $DIR/liveness-assign-imm-local-notes.rs:10:9
|
||||||
|
|
|
|
||||||
LL | let x;
|
|
||||||
| - help: consider making this binding mutable: `mut x`
|
|
||||||
...
|
|
||||||
LL | x = 2;
|
LL | x = 2;
|
||||||
| ----- first assignment to `x`
|
| ----- first assignment to `x`
|
||||||
LL | x = 3;
|
LL | x = 3;
|
||||||
| ^^^^^ cannot assign twice to immutable variable
|
| ^^^^^ cannot assign twice to immutable variable
|
||||||
|
|
|
||||||
|
help: consider making this binding mutable
|
||||||
|
|
|
||||||
|
LL | let mut x;
|
||||||
|
| +++
|
||||||
|
|
||||||
error[E0384]: cannot assign twice to immutable variable `x`
|
error[E0384]: cannot assign twice to immutable variable `x`
|
||||||
--> $DIR/liveness-assign-imm-local-notes.rs:21:13
|
--> $DIR/liveness-assign-imm-local-notes.rs:21:13
|
||||||
|
|
|
|
||||||
LL | let x;
|
|
||||||
| - help: consider making this binding mutable: `mut x`
|
|
||||||
...
|
|
||||||
LL | x = 2;
|
LL | x = 2;
|
||||||
| ----- first assignment to `x`
|
| ----- first assignment to `x`
|
||||||
LL | x = 3;
|
LL | x = 3;
|
||||||
| ^^^^^ cannot assign twice to immutable variable
|
| ^^^^^ cannot assign twice to immutable variable
|
||||||
|
|
|
||||||
|
help: consider making this binding mutable
|
||||||
|
|
|
||||||
|
LL | let mut x;
|
||||||
|
| +++
|
||||||
|
|
||||||
error[E0384]: cannot assign twice to immutable variable `x`
|
error[E0384]: cannot assign twice to immutable variable `x`
|
||||||
--> $DIR/liveness-assign-imm-local-notes.rs:30:13
|
--> $DIR/liveness-assign-imm-local-notes.rs:30:13
|
||||||
|
|
|
|
||||||
LL | let x;
|
|
||||||
| - help: consider making this binding mutable: `mut x`
|
|
||||||
...
|
|
||||||
LL | x = 1;
|
LL | x = 1;
|
||||||
| ^^^^^ cannot assign twice to immutable variable
|
| ^^^^^ cannot assign twice to immutable variable
|
||||||
|
|
|
||||||
|
help: consider making this binding mutable
|
||||||
|
|
|
||||||
|
LL | let mut x;
|
||||||
|
| +++
|
||||||
|
|
||||||
error[E0384]: cannot assign twice to immutable variable `x`
|
error[E0384]: cannot assign twice to immutable variable `x`
|
||||||
--> $DIR/liveness-assign-imm-local-notes.rs:32:13
|
--> $DIR/liveness-assign-imm-local-notes.rs:32:13
|
||||||
|
|
|
|
||||||
LL | let x;
|
|
||||||
| - help: consider making this binding mutable: `mut x`
|
|
||||||
...
|
|
||||||
LL | x = 1;
|
LL | x = 1;
|
||||||
| ----- first assignment to `x`
|
| ----- first assignment to `x`
|
||||||
LL | } else {
|
LL | } else {
|
||||||
LL | x = 2;
|
LL | x = 2;
|
||||||
| ^^^^^ cannot assign twice to immutable variable
|
| ^^^^^ cannot assign twice to immutable variable
|
||||||
|
|
|
||||||
|
help: consider making this binding mutable
|
||||||
|
|
|
||||||
|
LL | let mut x;
|
||||||
|
| +++
|
||||||
|
|
||||||
error: aborting due to 4 previous errors
|
error: aborting due to 4 previous errors
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
fn test() {
|
fn test() {
|
||||||
let v: isize;
|
let v: isize;
|
||||||
//~^ HELP consider making this binding mutable
|
//~^ HELP consider making this binding mutable
|
||||||
//~| SUGGESTION mut v
|
//~| SUGGESTION mut
|
||||||
loop {
|
loop {
|
||||||
v = 1; //~ ERROR cannot assign twice to immutable variable `v`
|
v = 1; //~ ERROR cannot assign twice to immutable variable `v`
|
||||||
//~| NOTE cannot assign twice to immutable variable
|
//~| NOTE cannot assign twice to immutable variable
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
error[E0384]: cannot assign twice to immutable variable `v`
|
error[E0384]: cannot assign twice to immutable variable `v`
|
||||||
--> $DIR/liveness-assign-imm-local-in-loop.rs:6:9
|
--> $DIR/liveness-assign-imm-local-in-loop.rs:6:9
|
||||||
|
|
|
|
||||||
LL | let v: isize;
|
|
||||||
| - help: consider making this binding mutable: `mut v`
|
|
||||||
...
|
|
||||||
LL | v = 1;
|
LL | v = 1;
|
||||||
| ^^^^^ cannot assign twice to immutable variable
|
| ^^^^^ cannot assign twice to immutable variable
|
||||||
|
|
|
||||||
|
help: consider making this binding mutable
|
||||||
|
|
|
||||||
|
LL | let mut v: isize;
|
||||||
|
| +++
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
fn test() {
|
fn test() {
|
||||||
let v: isize;
|
let v: isize;
|
||||||
//~^ HELP consider making this binding mutable
|
//~^ HELP consider making this binding mutable
|
||||||
//~| SUGGESTION mut v
|
//~| SUGGESTION mut
|
||||||
v = 2; //~ NOTE first assignment
|
v = 2; //~ NOTE first assignment
|
||||||
v += 1; //~ ERROR cannot assign twice to immutable variable `v`
|
v += 1; //~ ERROR cannot assign twice to immutable variable `v`
|
||||||
//~| NOTE cannot assign twice to immutable
|
//~| NOTE cannot assign twice to immutable
|
||||||
|
@ -1,13 +1,15 @@
|
|||||||
error[E0384]: cannot assign twice to immutable variable `v`
|
error[E0384]: cannot assign twice to immutable variable `v`
|
||||||
--> $DIR/liveness-assign-imm-local-in-op-eq.rs:6:5
|
--> $DIR/liveness-assign-imm-local-in-op-eq.rs:6:5
|
||||||
|
|
|
|
||||||
LL | let v: isize;
|
|
||||||
| - help: consider making this binding mutable: `mut v`
|
|
||||||
...
|
|
||||||
LL | v = 2;
|
LL | v = 2;
|
||||||
| ----- first assignment to `v`
|
| ----- first assignment to `v`
|
||||||
LL | v += 1;
|
LL | v += 1;
|
||||||
| ^^^^^^ cannot assign twice to immutable variable
|
| ^^^^^^ cannot assign twice to immutable variable
|
||||||
|
|
|
||||||
|
help: consider making this binding mutable
|
||||||
|
|
|
||||||
|
LL | let mut v: isize;
|
||||||
|
| +++
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
fn test() {
|
fn test() {
|
||||||
let b = Box::new(1); //~ NOTE first assignment
|
let b = Box::new(1); //~ NOTE first assignment
|
||||||
//~| HELP consider making this binding mutable
|
//~| HELP consider making this binding mutable
|
||||||
//~| SUGGESTION mut b
|
//~| SUGGESTION mut
|
||||||
drop(b);
|
drop(b);
|
||||||
b = Box::new(2); //~ ERROR cannot assign twice to immutable variable `b`
|
b = Box::new(2); //~ ERROR cannot assign twice to immutable variable `b`
|
||||||
//~| NOTE cannot assign twice to immutable
|
//~| NOTE cannot assign twice to immutable
|
||||||
|
@ -2,13 +2,15 @@ error[E0384]: cannot assign twice to immutable variable `b`
|
|||||||
--> $DIR/liveness-assign-imm-local-with-drop.rs:6:5
|
--> $DIR/liveness-assign-imm-local-with-drop.rs:6:5
|
||||||
|
|
|
|
||||||
LL | let b = Box::new(1);
|
LL | let b = Box::new(1);
|
||||||
| -
|
| - first assignment to `b`
|
||||||
| |
|
|
||||||
| first assignment to `b`
|
|
||||||
| help: consider making this binding mutable: `mut b`
|
|
||||||
...
|
...
|
||||||
LL | b = Box::new(2);
|
LL | b = Box::new(2);
|
||||||
| ^ cannot assign twice to immutable variable
|
| ^ cannot assign twice to immutable variable
|
||||||
|
|
|
||||||
|
help: consider making this binding mutable
|
||||||
|
|
|
||||||
|
LL | let mut b = Box::new(1);
|
||||||
|
| +++
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
fn test() {
|
fn test() {
|
||||||
let v: isize = 1; //~ NOTE first assignment
|
let v: isize = 1; //~ NOTE first assignment
|
||||||
//~| HELP consider making this binding mutable
|
//~| HELP consider making this binding mutable
|
||||||
//~| SUGGESTION mut v
|
//~| SUGGESTION mut
|
||||||
v.clone();
|
v.clone();
|
||||||
v = 2; //~ ERROR cannot assign twice to immutable variable `v`
|
v = 2; //~ ERROR cannot assign twice to immutable variable `v`
|
||||||
//~| NOTE cannot assign twice to immutable
|
//~| NOTE cannot assign twice to immutable
|
||||||
|
@ -2,13 +2,15 @@ error[E0384]: cannot assign twice to immutable variable `v`
|
|||||||
--> $DIR/liveness-assign-imm-local-with-init.rs:6:5
|
--> $DIR/liveness-assign-imm-local-with-init.rs:6:5
|
||||||
|
|
|
|
||||||
LL | let v: isize = 1;
|
LL | let v: isize = 1;
|
||||||
| -
|
| - first assignment to `v`
|
||||||
| |
|
|
||||||
| first assignment to `v`
|
|
||||||
| help: consider making this binding mutable: `mut v`
|
|
||||||
...
|
...
|
||||||
LL | v = 2;
|
LL | v = 2;
|
||||||
| ^^^^^ cannot assign twice to immutable variable
|
| ^^^^^ cannot assign twice to immutable variable
|
||||||
|
|
|
||||||
|
help: consider making this binding mutable
|
||||||
|
|
|
||||||
|
LL | let mut v: isize = 1;
|
||||||
|
| +++
|
||||||
|
|
||||||
error: aborting due to 1 previous error
|
error: aborting due to 1 previous error
|
||||||
|
|
||||||
|
@ -9,11 +9,11 @@ LL | x += 1;
|
|||||||
help: consider making this binding mutable
|
help: consider making this binding mutable
|
||||||
|
|
|
|
||||||
LL | let &mut mut x = foo;
|
LL | let &mut mut x = foo;
|
||||||
| ~~~~~
|
| +++
|
||||||
help: to modify the original value, take a borrow instead
|
help: to modify the original value, take a borrow instead
|
||||||
|
|
|
|
||||||
LL | let &mut ref mut x = foo;
|
LL | let &mut ref mut x = foo;
|
||||||
| ~~~~~~~~~
|
| +++++++
|
||||||
|
|
||||||
error[E0506]: cannot assign to `*foo` because it is borrowed
|
error[E0506]: cannot assign to `*foo` because it is borrowed
|
||||||
--> $DIR/mut-pattern-internal-mutability.rs:13:5
|
--> $DIR/mut-pattern-internal-mutability.rs:13:5
|
||||||
|
@ -78,11 +78,11 @@ LL | | Err(a @ b @ a)
|
|||||||
help: consider making this binding mutable
|
help: consider making this binding mutable
|
||||||
|
|
|
|
||||||
LL | Ok(a @ b @ mut a)
|
LL | Ok(a @ b @ mut a)
|
||||||
| ~~~~~
|
| +++
|
||||||
help: to modify the original value, take a borrow instead
|
help: to modify the original value, take a borrow instead
|
||||||
|
|
|
|
||||||
LL | Ok(a @ b @ ref mut a)
|
LL | Ok(a @ b @ ref mut a)
|
||||||
| ~~~~~~~~~
|
| +++++++
|
||||||
|
|
||||||
error: aborting due to 12 previous errors
|
error: aborting due to 12 previous errors
|
||||||
|
|
||||||
|
@ -22,11 +22,11 @@ LL | _x1 = U;
|
|||||||
help: consider making this binding mutable
|
help: consider making this binding mutable
|
||||||
|
|
|
|
||||||
LL | let [ref _x0_hold, mut _x1, ref xs_hold @ ..] = arr;
|
LL | let [ref _x0_hold, mut _x1, ref xs_hold @ ..] = arr;
|
||||||
| ~~~~~~~
|
| +++
|
||||||
help: to modify the original value, take a borrow instead
|
help: to modify the original value, take a borrow instead
|
||||||
|
|
|
|
||||||
LL | let [ref _x0_hold, ref mut _x1, ref xs_hold @ ..] = arr;
|
LL | let [ref _x0_hold, ref mut _x1, ref xs_hold @ ..] = arr;
|
||||||
| ~~~~~~~~~~~
|
| +++++++
|
||||||
|
|
||||||
error[E0505]: cannot move out of `arr[..]` because it is borrowed
|
error[E0505]: cannot move out of `arr[..]` because it is borrowed
|
||||||
--> $DIR/borrowck-move-ref-pattern.rs:11:10
|
--> $DIR/borrowck-move-ref-pattern.rs:11:10
|
||||||
@ -86,11 +86,11 @@ LL | _x1 = U;
|
|||||||
help: consider making this binding mutable
|
help: consider making this binding mutable
|
||||||
|
|
|
|
||||||
LL | let (ref _x0, mut _x1, ref _x2, ..) = tup;
|
LL | let (ref _x0, mut _x1, ref _x2, ..) = tup;
|
||||||
| ~~~~~~~
|
| +++
|
||||||
help: to modify the original value, take a borrow instead
|
help: to modify the original value, take a borrow instead
|
||||||
|
|
|
|
||||||
LL | let (ref _x0, ref mut _x1, ref _x2, ..) = tup;
|
LL | let (ref _x0, ref mut _x1, ref _x2, ..) = tup;
|
||||||
| ~~~~~~~~~~~
|
| +++++++
|
||||||
|
|
||||||
error[E0502]: cannot borrow `tup.0` as mutable because it is also borrowed as immutable
|
error[E0502]: cannot borrow `tup.0` as mutable because it is also borrowed as immutable
|
||||||
--> $DIR/borrowck-move-ref-pattern.rs:24:20
|
--> $DIR/borrowck-move-ref-pattern.rs:24:20
|
||||||
|
@ -9,11 +9,11 @@ LL | a = 42;
|
|||||||
help: consider making this binding mutable
|
help: consider making this binding mutable
|
||||||
|
|
|
|
||||||
LL | let Foo(mut a) = Foo(0);
|
LL | let Foo(mut a) = Foo(0);
|
||||||
| ~~~~~
|
| +++
|
||||||
help: to modify the original value, take a borrow instead
|
help: to modify the original value, take a borrow instead
|
||||||
|
|
|
|
||||||
LL | let Foo(ref mut a) = Foo(0);
|
LL | let Foo(ref mut a) = Foo(0);
|
||||||
| ~~~~~~~~~
|
| +++++++
|
||||||
|
|
||||||
error[E0384]: cannot assign twice to immutable variable `a`
|
error[E0384]: cannot assign twice to immutable variable `a`
|
||||||
--> $DIR/mut-ref-mut-2021.rs:15:5
|
--> $DIR/mut-ref-mut-2021.rs:15:5
|
||||||
|
Loading…
Reference in New Issue
Block a user