Skip to content
Permalink
Browse files

Improve invalid assignment error

  • Loading branch information
varkor committed Dec 22, 2019
1 parent a5991c5 commit b7bfdbe68147f2ea8ca4870270643180bef76e02
@@ -753,9 +753,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}
err.emit();
} else if !lhs.is_syntactic_place_expr() {
struct_span_err!(self.tcx.sess, expr.span, E0070, "invalid left-hand side expression")
.span_label(expr.span, "left-hand of expression not valid")
.emit();
struct_span_err!(
self.tcx.sess,
expr.span,
E0070,
"invalid left-hand side of assignment",
).span_label(lhs.span, "cannot assign to this expression").emit();
}

self.require_type_is_sized(lhs_ty, lhs.span, traits::AssignmentLhsSized);
@@ -36,12 +36,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
if !lhs_expr.is_syntactic_place_expr() {
struct_span_err!(
self.tcx.sess,
lhs_expr.span,
op.span,
E0067,
"invalid left-hand side expression"
)
.span_label(lhs_expr.span, "invalid expression for left-hand side")
.emit();
"invalid left-hand side of assignment",
).span_label(lhs_expr.span, "cannot assign to this expression").emit();
}
ty
}
@@ -1,10 +1,10 @@
fn main() {
1 = 2; //~ ERROR invalid left-hand side expression
1 += 2; //~ ERROR invalid left-hand side expression
(1, 2) = (3, 4); //~ ERROR invalid left-hand side expression
1 = 2; //~ ERROR invalid left-hand side of assignment
1 += 2; //~ ERROR invalid left-hand side of assignment
(1, 2) = (3, 4); //~ ERROR invalid left-hand side of assignment

let (a, b) = (1, 2);
(a, b) = (3, 4); //~ ERROR invalid left-hand side expression
(a, b) = (3, 4); //~ ERROR invalid left-hand side of assignment

None = Some(3); //~ ERROR invalid left-hand side expression
None = Some(3); //~ ERROR invalid left-hand side of assignment
}
@@ -1,32 +1,42 @@
error[E0070]: invalid left-hand side expression
error[E0070]: invalid left-hand side of assignment
--> $DIR/bad-expr-lhs.rs:2:5
|
LL | 1 = 2;
| ^^^^^ left-hand of expression not valid
| -^^^^
| |
| cannot assign to this expression

error[E0067]: invalid left-hand side expression
--> $DIR/bad-expr-lhs.rs:3:5
error[E0067]: invalid left-hand side of assignment
--> $DIR/bad-expr-lhs.rs:3:7
|
LL | 1 += 2;
| ^ invalid expression for left-hand side
| - ^^
| |
| cannot assign to this expression

error[E0070]: invalid left-hand side expression
error[E0070]: invalid left-hand side of assignment
--> $DIR/bad-expr-lhs.rs:4:5
|
LL | (1, 2) = (3, 4);
| ^^^^^^^^^^^^^^^ left-hand of expression not valid
| ------^^^^^^^^^
| |
| cannot assign to this expression

error[E0070]: invalid left-hand side expression
error[E0070]: invalid left-hand side of assignment
--> $DIR/bad-expr-lhs.rs:7:5
|
LL | (a, b) = (3, 4);
| ^^^^^^^^^^^^^^^ left-hand of expression not valid
| ------^^^^^^^^^
| |
| cannot assign to this expression

error[E0070]: invalid left-hand side expression
error[E0070]: invalid left-hand side of assignment
--> $DIR/bad-expr-lhs.rs:9:5
|
LL | None = Some(3);
| ^^^^^^^^^^^^^^ left-hand of expression not valid
| ----^^^^^^^^^^
| |
| cannot assign to this expression

error: aborting due to 5 previous errors

@@ -8,11 +8,13 @@ LL | LinkedList::new() += 1;
|
= note: an implementation of `std::ops::AddAssign` might be missing for `std::collections::LinkedList<_>`

error[E0067]: invalid left-hand side expression
--> $DIR/E0067.rs:4:5
error[E0067]: invalid left-hand side of assignment
--> $DIR/E0067.rs:4:23
|
LL | LinkedList::new() += 1;
| ^^^^^^^^^^^^^^^^^ invalid expression for left-hand side
| ----------------- ^^
| |
| cannot assign to this expression

error: aborting due to 2 previous errors

@@ -1,26 +1,32 @@
error[E0070]: invalid left-hand side expression
error[E0070]: invalid left-hand side of assignment
--> $DIR/E0070.rs:6:5
|
LL | SOME_CONST = 14;
| ^^^^^^^^^^^^^^^ left-hand of expression not valid
| ----------^^^^^
| |
| cannot assign to this expression

error[E0070]: invalid left-hand side expression
error[E0070]: invalid left-hand side of assignment
--> $DIR/E0070.rs:7:5
|
LL | 1 = 3;
| ^^^^^ left-hand of expression not valid
| -^^^^
| |
| cannot assign to this expression

error[E0308]: mismatched types
--> $DIR/E0070.rs:8:25
|
LL | some_other_func() = 4;
| ^ expected `()`, found integer

error[E0070]: invalid left-hand side expression
error[E0070]: invalid left-hand side of assignment
--> $DIR/E0070.rs:8:5
|
LL | some_other_func() = 4;
| ^^^^^^^^^^^^^^^^^^^^^ left-hand of expression not valid
| -----------------^^^^
| |
| cannot assign to this expression

error: aborting due to 4 previous errors

@@ -4,7 +4,7 @@ mod A {

fn main() {
A::C = 1;
//~^ ERROR: invalid left-hand side expression
//~^ ERROR: invalid left-hand side of assignment
//~| ERROR: mismatched types
//~| ERROR: struct `C` is private
}
@@ -10,11 +10,13 @@ error[E0308]: mismatched types
LL | A::C = 1;
| ^ expected struct `A::C`, found integer

error[E0070]: invalid left-hand side expression
error[E0070]: invalid left-hand side of assignment
--> $DIR/issue-13407.rs:6:5
|
LL | A::C = 1;
| ^^^^^^^^ left-hand of expression not valid
| ----^^^^
| |
| cannot assign to this expression

error: aborting due to 3 previous errors

@@ -1,7 +1,9 @@
macro_rules! not_a_place {
($thing:expr) => {
$thing = 42;
//~^ ERROR invalid left-hand side expression
//~^ ERROR invalid left-hand side of assignment
$thing += 42;
//~^ ERROR invalid left-hand side of assignment
}
}

@@ -1,12 +1,28 @@
error[E0070]: invalid left-hand side expression
error[E0070]: invalid left-hand side of assignment
--> $DIR/issue-26093.rs:3:9
|
LL | $thing = 42;
| ^^^^^^^^^^^ left-hand of expression not valid
| ^^^^^^^^^^^
...
LL | not_a_place!(99);
| ----------------- in this macro invocation
| -----------------
| | |
| | cannot assign to this expression
| in this macro invocation

error: aborting due to previous error
error[E0067]: invalid left-hand side of assignment
--> $DIR/issue-26093.rs:5:16
|
LL | $thing += 42;
| ^^
...
LL | not_a_place!(99);
| -----------------
| | |
| | cannot assign to this expression
| in this macro invocation

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0070`.
Some errors have detailed explanations: E0067, E0070.
For more information about an error, try `rustc --explain E0067`.
@@ -3,7 +3,7 @@ fn main () {
//~^ ERROR expected one of `,` or `>`, found `=`
//~| ERROR expected value, found struct `Vec`
//~| ERROR mismatched types
//~| ERROR invalid left-hand side expression
//~| ERROR invalid left-hand side of assignment
//~| ERROR expected expression, found reserved identifier `_`
//~| ERROR expected expression, found reserved identifier `_`
let sr2: Vec<(u32, _, _)> = sr.iter().map(|(faction, th_sender, th_receiver)| {}).collect();
@@ -35,11 +35,13 @@ LL | let sr: Vec<(u32, _, _) = vec![];
found struct `std::vec::Vec<_>`
= note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)

error[E0070]: invalid left-hand side expression
error[E0070]: invalid left-hand side of assignment
--> $DIR/issue-34334.rs:2:13
|
LL | let sr: Vec<(u32, _, _) = vec![];
| ^^^^^^^^^^^^^^^^^^^^^^^^ left-hand of expression not valid
| ---------------^^^^^^^^^
| |
| cannot assign to this expression

error[E0599]: no method named `iter` found for type `()` in the current scope
--> $DIR/issue-34334.rs:9:36
@@ -30,5 +30,5 @@ fn main() {
// A test to check that not expecting `bool` behaves well:
let _: usize = 0 = 0;
//~^ ERROR mismatched types [E0308]
//~| ERROR invalid left-hand side expression [E0070]
//~| ERROR invalid left-hand side of assignment [E0070]
}
@@ -97,11 +97,13 @@ LL | || (0 = 0);
| expected `bool`, found `()`
| help: try comparing for equality: `0 == 0`

error[E0070]: invalid left-hand side expression
error[E0070]: invalid left-hand side of assignment
--> $DIR/assignment-expected-bool.rs:31:20
|
LL | let _: usize = 0 = 0;
| ^^^^^ left-hand of expression not valid
| -^^^^
| |
| cannot assign to this expression

error[E0308]: mismatched types
--> $DIR/assignment-expected-bool.rs:31:20
@@ -26,7 +26,7 @@ fn main() {
//~^ ERROR mismatched types
println!("{}", x);
}
// "invalid left-hand side expression" error is suppresed
// "invalid left-hand side of assignment" error is suppresed
if 3 = x {
//~^ ERROR mismatched types
println!("{}", x);

0 comments on commit b7bfdbe

Please sign in to comment.
You can’t perform that action at this time.