From c613aa5a95a83ec77b4b0af1e74019cb8aca75b4 Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Sat, 30 Jun 2018 11:02:38 +0100 Subject: Improve error messages when assigning to a local that starts initialized --- src/test/compile-fail/immut-function-arguments.rs | 4 ++-- src/test/ui/command-line-diagnostics.nll.stderr | 3 ++- src/test/ui/did_you_mean/issue-35937.nll.stderr | 14 ++++++-------- 3 files changed, 10 insertions(+), 11 deletions(-) (limited to 'src/test') diff --git a/src/test/compile-fail/immut-function-arguments.rs b/src/test/compile-fail/immut-function-arguments.rs index b32056fcb91..61a074952ef 100644 --- a/src/test/compile-fail/immut-function-arguments.rs +++ b/src/test/compile-fail/immut-function-arguments.rs @@ -13,12 +13,12 @@ fn f(y: Box) { *y = 5; //[ast]~ ERROR cannot assign - //[mir]~^ ERROR cannot assign twice + //[mir]~^ ERROR cannot assign } fn g() { let _frob = |q: Box| { *q = 2; }; //[ast]~ ERROR cannot assign - //[mir]~^ ERROR cannot assign twice + //[mir]~^ ERROR cannot assign } fn main() {} diff --git a/src/test/ui/command-line-diagnostics.nll.stderr b/src/test/ui/command-line-diagnostics.nll.stderr index 10dcf7d0e65..46bb7c5af57 100644 --- a/src/test/ui/command-line-diagnostics.nll.stderr +++ b/src/test/ui/command-line-diagnostics.nll.stderr @@ -2,8 +2,9 @@ error[E0384]: cannot assign twice to immutable variable `x` --> $DIR/command-line-diagnostics.rs:16:5 | LL | let x = 42; - | - -- first assignment to `x` + | - | | + | first assignment to `x` | consider changing this to `mut x` LL | x = 43; | ^^^^^^ cannot assign twice to immutable variable diff --git a/src/test/ui/did_you_mean/issue-35937.nll.stderr b/src/test/ui/did_you_mean/issue-35937.nll.stderr index 0c1dcb29d4d..7eaa4c7d5fe 100644 --- a/src/test/ui/did_you_mean/issue-35937.nll.stderr +++ b/src/test/ui/did_you_mean/issue-35937.nll.stderr @@ -6,26 +6,24 @@ LL | let f = Foo { v: Vec::new() }; LL | f.v.push("cat".to_string()); //~ ERROR cannot borrow | ^^^ cannot borrow as mutable -error[E0384]: cannot assign twice to immutable variable `s.x` +error[E0384]: cannot assign twice to immutable variable `s` --> $DIR/issue-35937.rs:26:5 | LL | let s = S { x: 42 }; - | - ----------- first assignment to `s.x` + | - | | + | first assignment to `s` | consider changing this to `mut s` LL | s.x += 1; //~ ERROR cannot assign | ^^^^^^^^ cannot assign twice to immutable variable -error[E0384]: cannot assign twice to immutable variable `s.x` +error[E0384]: cannot assign to immutable argument `s` --> $DIR/issue-35937.rs:30:5 | LL | fn bar(s: S) { - | - - | | - | first assignment to `s.x` - | consider changing this to `mut s` + | - consider changing this to `mut s` LL | s.x += 1; //~ ERROR cannot assign - | ^^^^^^^^ cannot assign twice to immutable variable + | ^^^^^^^^ cannot assign to immutable argument error: aborting due to 3 previous errors -- cgit 1.4.1-3-g733a5