diff options
| author | bors <bors@rust-lang.org> | 2016-05-15 15:08:46 -0700 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2016-05-15 15:08:46 -0700 |
| commit | 5ebe41835fcc3dbfdbe282a9b4c3780968c0a97a (patch) | |
| tree | 9a1f7d9e9674e795fae579a23c8ad4626a5cecef /src/test/compile-fail | |
| parent | e7420fbbae85a62a62163a2ac5c947b76a8eb62d (diff) | |
| parent | 65cb5f73789723b5eeb4ba9332e3e034939369c4 (diff) | |
| download | rust-5ebe41835fcc3dbfdbe282a9b4c3780968c0a97a.tar.gz rust-5ebe41835fcc3dbfdbe282a9b4c3780968c0a97a.zip | |
Auto merge of #33619 - jonathandturner:improve_structured_errors, r=nikomatsakis
Batch of improvements to errors for new error format This is a batch of improvements to existing errors to help get the most out of the new error format. * Added labels to primary spans (^^^) for a set of errors that didn't currently have them * Highlight the source blue under the secondary notes for better readability * Move some of the "Note:" into secondary spans+labels * Fix span_label to take &mut instead, which makes it work the same as other methods in that set
Diffstat (limited to 'src/test/compile-fail')
22 files changed, 87 insertions, 45 deletions
diff --git a/src/test/compile-fail/augmented-assignments.rs b/src/test/compile-fail/augmented-assignments.rs index 8ac6b419295..92a8b10669c 100644 --- a/src/test/compile-fail/augmented-assignments.rs +++ b/src/test/compile-fail/augmented-assignments.rs @@ -27,7 +27,9 @@ fn main() { x; //~ value moved here let y = Int(2); + //~^use `mut y` here to make mutable y //~ error: cannot borrow immutable local variable `y` as mutable + //~| cannot borrow += Int(1); } diff --git a/src/test/compile-fail/blind-item-block-middle.rs b/src/test/compile-fail/blind-item-block-middle.rs index 930f769771d..287eab7a563 100644 --- a/src/test/compile-fail/blind-item-block-middle.rs +++ b/src/test/compile-fail/blind-item-block-middle.rs @@ -12,6 +12,6 @@ mod foo { pub struct bar; } fn main() { let bar = 5; - //~^ ERROR declaration of `bar` shadows an enum variant or unit-like struct in scope + //~^ ERROR cannot be named the same use foo::bar; } diff --git a/src/test/compile-fail/blind-item-item-shadow.rs b/src/test/compile-fail/blind-item-item-shadow.rs index b08c78e9060..853282ff014 100644 --- a/src/test/compile-fail/blind-item-item-shadow.rs +++ b/src/test/compile-fail/blind-item-item-shadow.rs @@ -10,6 +10,8 @@ mod foo { pub mod foo { } } //~ NOTE previous definition of `foo` here -use foo::foo; //~ ERROR a module named `foo` has already been defined in this module +use foo::foo; +//~^ ERROR a module named `foo` has already been defined in this module +//~| was already imported fn main() {} diff --git a/src/test/compile-fail/borrowck/borrowck-box-insensitivity.rs b/src/test/compile-fail/borrowck/borrowck-box-insensitivity.rs index bde3212c5bc..3fd71f71564 100644 --- a/src/test/compile-fail/borrowck/borrowck-box-insensitivity.rs +++ b/src/test/compile-fail/borrowck/borrowck-box-insensitivity.rs @@ -61,7 +61,9 @@ fn move_after_borrow() { let a: Box<_> = box B { x: box 0, y: box 1 }; let _x = &a.x; //~^ NOTE borrow of `a.x` occurs here - let _y = a.y; //~ ERROR cannot move + let _y = a.y; + //~^ ERROR cannot move + //~| move out of } fn copy_after_mut_borrow() { @@ -75,7 +77,9 @@ fn move_after_mut_borrow() { let mut a: Box<_> = box B { x: box 0, y: box 1 }; let _x = &mut a.x; //~^ NOTE borrow of `a.x` occurs here - let _y = a.y; //~ ERROR cannot move + let _y = a.y; + //~^ ERROR cannot move + //~| move out of } fn borrow_after_mut_borrow() { @@ -127,7 +131,9 @@ fn move_after_borrow_nested() { let a: Box<_> = box D { x: box A { x: box 0, y: 1 }, y: box 2 }; let _x = &a.x.x; //~^ borrow of `a.x.x` occurs here - let _y = a.y; //~ ERROR cannot move + let _y = a.y; + //~^ ERROR cannot move + //~| move out of } fn copy_after_mut_borrow_nested() { @@ -141,7 +147,9 @@ fn move_after_mut_borrow_nested() { let mut a: Box<_> = box D { x: box A { x: box 0, y: 1 }, y: box 2 }; let _x = &mut a.x.x; //~^ NOTE borrow of `a.x.x` occurs here - let _y = a.y; //~ ERROR cannot move + let _y = a.y; + //~^ ERROR cannot move + //~| move out of } fn borrow_after_mut_borrow_nested() { diff --git a/src/test/compile-fail/borrowck/borrowck-let-suggestion-suffixes.rs b/src/test/compile-fail/borrowck/borrowck-let-suggestion-suffixes.rs index f551a2aa811..02aa771c787 100644 --- a/src/test/compile-fail/borrowck/borrowck-let-suggestion-suffixes.rs +++ b/src/test/compile-fail/borrowck/borrowck-let-suggestion-suffixes.rs @@ -26,6 +26,7 @@ fn f() { v3.push(&'x'); // statement 6 //~^ ERROR borrowed value does not live long enough + //~| does not live long enough //~| NOTE ...but borrowed value is only valid for the statement //~| HELP consider using a `let` binding to increase its lifetime @@ -36,6 +37,7 @@ fn f() { v4.push(&'y'); //~^ ERROR borrowed value does not live long enough + //~| does not live long enough //~| NOTE ...but borrowed value is only valid for the statement //~| HELP consider using a `let` binding to increase its lifetime @@ -46,6 +48,7 @@ fn f() { v5.push(&'z'); //~^ ERROR borrowed value does not live long enough + //~| does not live long enough //~| NOTE ...but borrowed value is only valid for the statement //~| HELP consider using a `let` binding to increase its lifetime diff --git a/src/test/compile-fail/borrowck/borrowck-let-suggestion.rs b/src/test/compile-fail/borrowck/borrowck-let-suggestion.rs index 7e9d448275d..866e72f1a52 100644 --- a/src/test/compile-fail/borrowck/borrowck-let-suggestion.rs +++ b/src/test/compile-fail/borrowck/borrowck-let-suggestion.rs @@ -9,10 +9,12 @@ // except according to those terms. fn f() { - let x = [1].iter(); //~ ERROR borrowed value does not live long enough - //~^ NOTE reference must be valid for the block suffix following statement - //~^^ HELP consider using a `let` binding to increase its lifetime - //~^^^ NOTE ...but borrowed value is only valid for the statement at 12:4 + let x = [1].iter(); + //~^ ERROR borrowed value does not live long enough + //~|does not live long enough + //~| NOTE reference must be valid for the block suffix following statement + //~| HELP consider using a `let` binding to increase its lifetime + //~| NOTE ...but borrowed value is only valid for the statement at 12:4 } fn main() { diff --git a/src/test/compile-fail/borrowck/borrowck-move-error-with-note.rs b/src/test/compile-fail/borrowck/borrowck-move-error-with-note.rs index e4b9fb26711..ffa7d192556 100644 --- a/src/test/compile-fail/borrowck/borrowck-move-error-with-note.rs +++ b/src/test/compile-fail/borrowck/borrowck-move-error-with-note.rs @@ -19,6 +19,7 @@ enum Foo { fn blah() { let f = &Foo::Foo1(box 1, box 2); match *f { //~ ERROR cannot move out of + //~| move occurs here Foo::Foo1(num1, //~ NOTE attempting to move value to here num2) => (), //~ NOTE and here Foo::Foo2(num) => (), //~ NOTE and here @@ -37,6 +38,7 @@ impl Drop for S { fn move_in_match() { match (S {f: "foo".to_string(), g: "bar".to_string()}) { S { //~ ERROR cannot move out of type `S`, which defines the `Drop` trait + //~| can not move out of here f: _s, //~ NOTE attempting to move value to here g: _t //~ NOTE and here } => {} @@ -53,6 +55,7 @@ fn free<T>(_: T) {} fn blah2() { let a = &A { a: box 1 }; match a.a { //~ ERROR cannot move out of + //~| move occurs here n => { //~ NOTE attempting to move value to here free(n) } diff --git a/src/test/compile-fail/borrowck/borrowck-move-out-of-vec-tail.rs b/src/test/compile-fail/borrowck/borrowck-move-out-of-vec-tail.rs index d9a2f89a9e2..2f1c69d0d7d 100644 --- a/src/test/compile-fail/borrowck/borrowck-move-out-of-vec-tail.rs +++ b/src/test/compile-fail/borrowck/borrowck-move-out-of-vec-tail.rs @@ -27,10 +27,12 @@ pub fn main() { match x { [_, tail..] => { match tail { - [Foo { string: a }, //~ ERROR cannot move out of borrowed content + [Foo { string: a }, + //~^ ERROR cannot move out of borrowed content + //~| move occurs here + //~| attempting to move value to here Foo { string: b }] => { - //~^^ NOTE attempting to move value to here - //~^^ NOTE and here + //~^ NOTE and here } _ => { unreachable!(); diff --git a/src/test/compile-fail/borrowck/borrowck-vec-pattern-nesting.rs b/src/test/compile-fail/borrowck/borrowck-vec-pattern-nesting.rs index 1a21b03a457..1c63b458e62 100644 --- a/src/test/compile-fail/borrowck/borrowck-vec-pattern-nesting.rs +++ b/src/test/compile-fail/borrowck/borrowck-vec-pattern-nesting.rs @@ -19,6 +19,7 @@ fn a() { [box ref _a, _, _] => { //~^ borrow of `vec[..]` occurs here vec[0] = box 4; //~ ERROR cannot assign + //~^ assignment to `vec[..]` occurs here } } } @@ -30,6 +31,7 @@ fn b() { [_b..] => { //~^ borrow of `vec[..]` occurs here vec[0] = box 4; //~ ERROR cannot assign + //~^ assignment to `vec[..]` occurs here } } } @@ -39,8 +41,9 @@ fn c() { let vec: &mut [Box<isize>] = &mut vec; match vec { [_a, //~ ERROR cannot move out - _b..] => { //~^ NOTE attempting to move value to here - + //~| move occurs here + //~| attempting to move value to here + _b..] => { // Note: `_a` is *moved* here, but `b` is borrowing, // hence illegal. // @@ -51,6 +54,7 @@ fn c() { } let a = vec[0]; //~ ERROR cannot move out //~^ NOTE attempting to move value to here + //~| can not move out of here } fn d() { @@ -58,11 +62,13 @@ fn d() { let vec: &mut [Box<isize>] = &mut vec; match vec { [_a.., //~ ERROR cannot move out + //~^ move occurs here _b] => {} //~ NOTE attempting to move value to here _ => {} } let a = vec[0]; //~ ERROR cannot move out //~^ NOTE attempting to move value to here + //~| can not move out of here } fn e() { @@ -70,13 +76,15 @@ fn e() { let vec: &mut [Box<isize>] = &mut vec; match vec { [_a, _b, _c] => {} //~ ERROR cannot move out - //~^ NOTE attempting to move value to here - //~^^ NOTE and here - //~^^^ NOTE and here + //~| move occurs here + //~| NOTE attempting to move value to here + //~| NOTE and here + //~| NOTE and here _ => {} } let a = vec[0]; //~ ERROR cannot move out //~^ NOTE attempting to move value to here + //~| can not move out of here } fn main() {} diff --git a/src/test/compile-fail/const-pattern-irrefutable.rs b/src/test/compile-fail/const-pattern-irrefutable.rs index 0be1e974e7d..392f391fb51 100644 --- a/src/test/compile-fail/const-pattern-irrefutable.rs +++ b/src/test/compile-fail/const-pattern-irrefutable.rs @@ -13,16 +13,16 @@ mod foo { pub const d: u8 = 2; } -use foo::b as c; //~ NOTE constant imported here -use foo::d; //~ NOTE constant imported here +use foo::b as c; //~ NOTE is imported here +use foo::d; //~ NOTE is imported here -const a: u8 = 2; //~ NOTE constant defined here +const a: u8 = 2; //~ NOTE is defined here fn main() { - let a = 4; //~ ERROR variable bindings cannot - //~^ NOTE there already is a constant in scope - let c = 4; //~ ERROR variable bindings cannot - //~^ NOTE there already is a constant in scope - let d = 4; //~ ERROR variable bindings cannot - //~^ NOTE there already is a constant in scope + let a = 4; //~ ERROR let variables cannot + //~^ NOTE cannot be named the same as a const variable + let c = 4; //~ ERROR let variables cannot + //~^ NOTE cannot be named the same as a const variable + let d = 4; //~ ERROR let variables cannot + //~^ NOTE cannot be named the same as a const variable } diff --git a/src/test/compile-fail/enum-in-scope.rs b/src/test/compile-fail/enum-in-scope.rs index 7be06ec7de8..6dffd1999d7 100644 --- a/src/test/compile-fail/enum-in-scope.rs +++ b/src/test/compile-fail/enum-in-scope.rs @@ -11,5 +11,5 @@ struct hello(isize); fn main() { - let hello = 0; //~ERROR declaration of `hello` shadows + let hello = 0; //~ERROR cannot be named the same } diff --git a/src/test/compile-fail/issue-19498.rs b/src/test/compile-fail/issue-19498.rs index 87b79b5cd67..2e2115b7110 100644 --- a/src/test/compile-fail/issue-19498.rs +++ b/src/test/compile-fail/issue-19498.rs @@ -11,11 +11,13 @@ use self::A; //~ NOTE previous import of `A` here use self::B; //~ NOTE previous import of `B` here mod A {} //~ ERROR a module named `A` has already been imported in this module +//~| `A` was already imported pub mod B {} //~ ERROR a module named `B` has already been imported in this module - +//~| `B` was already imported mod C { use C::D; //~ NOTE previous import of `D` here mod D {} //~ ERROR a module named `D` has already been imported in this module + //~| `D` was already imported } fn main() {} diff --git a/src/test/compile-fail/issue-23716.rs b/src/test/compile-fail/issue-23716.rs index 31604e2fdd3..b0d36610b7a 100644 --- a/src/test/compile-fail/issue-23716.rs +++ b/src/test/compile-fail/issue-23716.rs @@ -13,6 +13,7 @@ static foo: i32 = 0; fn bar(foo: i32) {} //~^ ERROR static variables cannot be referenced in a pattern, use a `const` instead +//~| static variable used in pattern mod submod { pub static answer: i32 = 42; @@ -23,6 +24,6 @@ use self::submod::answer; fn question(answer: i32) {} //~^ ERROR static variables cannot be referenced in a pattern, use a `const` instead - +//~| static variable used in pattern fn main() { } diff --git a/src/test/compile-fail/issue-24081.rs b/src/test/compile-fail/issue-24081.rs index 94fb3008289..188716c5e93 100644 --- a/src/test/compile-fail/issue-24081.rs +++ b/src/test/compile-fail/issue-24081.rs @@ -15,9 +15,14 @@ use std::ops::Div; //~ NOTE previous import use std::ops::Rem; //~ NOTE previous import type Add = bool; //~ ERROR a trait named `Add` has already been imported in this module +//~| was already imported struct Sub { x: f32 } //~ ERROR a trait named `Sub` has already been imported in this module +//~| was already imported enum Mul { A, B } //~ ERROR a trait named `Mul` has already been imported in this module +//~| was already imported mod Div { } //~ ERROR a trait named `Div` has already been imported in this module +//~| was already imported trait Rem { } //~ ERROR a trait named `Rem` has already been imported in this module +//~| was already imported fn main() {} diff --git a/src/test/compile-fail/issue-27033.rs b/src/test/compile-fail/issue-27033.rs index a729cf95a7b..b0904dfeaa7 100644 --- a/src/test/compile-fail/issue-27033.rs +++ b/src/test/compile-fail/issue-27033.rs @@ -10,11 +10,11 @@ fn main() { match Some(1) { - None @ _ => {} //~ ERROR declaration of `None` shadows an enum variant + None @ _ => {} //~ ERROR cannot be named the same }; const C: u8 = 1; match 1 { - C @ 2 => { //~ ERROR variable bindings cannot shadow constants + C @ 2 => { //~ ERROR cannot be named the same println!("{}", C); } _ => {} diff --git a/src/test/compile-fail/issue-3907.rs b/src/test/compile-fail/issue-3907.rs index 1dbf211b269..c99ff1813e0 100644 --- a/src/test/compile-fail/issue-3907.rs +++ b/src/test/compile-fail/issue-3907.rs @@ -11,14 +11,14 @@ // aux-build:issue_3907.rs extern crate issue_3907; -type Foo = issue_3907::Foo; //~ NOTE: type defined here +type Foo = issue_3907::Foo; //~ NOTE: type aliases cannot be used for traits struct S { name: isize } impl Foo for S { //~ ERROR: `Foo` is not a trait - //~^ NOTE: `type` aliases cannot be used for traits + //~| `Foo` is not a trait fn bar() { } } diff --git a/src/test/compile-fail/issue-5035.rs b/src/test/compile-fail/issue-5035.rs index dabeb503841..a186a399a11 100644 --- a/src/test/compile-fail/issue-5035.rs +++ b/src/test/compile-fail/issue-5035.rs @@ -9,7 +9,8 @@ // except according to those terms. trait I {} -type K = I; //~ NOTE: type defined here +type K = I; +//~^ NOTE: aliases cannot be used for traits impl K for isize {} //~ ERROR: `K` is not a trait -//~^ NOTE: `type` aliases cannot be used for traits +//~| is not a trait fn main() {} diff --git a/src/test/compile-fail/moves-based-on-type-block-bad.rs b/src/test/compile-fail/moves-based-on-type-block-bad.rs index a1e876594c2..1fd69e2dbfe 100644 --- a/src/test/compile-fail/moves-based-on-type-block-bad.rs +++ b/src/test/compile-fail/moves-based-on-type-block-bad.rs @@ -32,6 +32,7 @@ fn main() { loop { f(&s, |hellothere| { match hellothere.x { //~ ERROR cannot move out + //~| move occurs here box E::Foo(_) => {} box E::Bar(x) => println!("{}", x.to_string()), //~ NOTE attempting to move value to here box E::Baz => {} diff --git a/src/test/compile-fail/mut-suggestion.rs b/src/test/compile-fail/mut-suggestion.rs index efd796e1195..242ad7aee8d 100644 --- a/src/test/compile-fail/mut-suggestion.rs +++ b/src/test/compile-fail/mut-suggestion.rs @@ -17,14 +17,16 @@ impl S { } fn func(arg: S) { - //~^ HELP use `mut` as shown - //~| SUGGESTION fn func(mut arg: S) { - arg.mutate(); //~ ERROR cannot borrow immutable argument + //~^ here to make mutable + arg.mutate(); + //~^ ERROR cannot borrow immutable argument + //~| cannot borrow mutably } fn main() { let local = S; - //~^ HELP use `mut` as shown - //~| SUGGESTION let mut local = S; - local.mutate(); //~ ERROR cannot borrow immutable local variable + //~^ here to make mutable + local.mutate(); + //~^ ERROR cannot borrow immutable local variable + //~| cannot borrow mutably } diff --git a/src/test/compile-fail/name-clash-nullary.rs b/src/test/compile-fail/name-clash-nullary.rs index 1250318a729..662bb7bfe57 100644 --- a/src/test/compile-fail/name-clash-nullary.rs +++ b/src/test/compile-fail/name-clash-nullary.rs @@ -8,7 +8,7 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// error-pattern:declaration of `None` shadows +// error-pattern:cannot be named the same use std::option::*; fn main() { diff --git a/src/test/compile-fail/pat-shadow-in-nested-binding.rs b/src/test/compile-fail/pat-shadow-in-nested-binding.rs index 526e4c16187..4a8513e10d7 100644 --- a/src/test/compile-fail/pat-shadow-in-nested-binding.rs +++ b/src/test/compile-fail/pat-shadow-in-nested-binding.rs @@ -11,5 +11,5 @@ struct foo(usize); fn main() { - let (foo, _) = (2, 3); //~ ERROR declaration of `foo` shadows + let (foo, _) = (2, 3); //~ ERROR `foo` cannot be named the same as } diff --git a/src/test/compile-fail/resolve-conflict-item-vs-import.rs b/src/test/compile-fail/resolve-conflict-item-vs-import.rs index dbd1ecf44fd..5a068ce4214 100644 --- a/src/test/compile-fail/resolve-conflict-item-vs-import.rs +++ b/src/test/compile-fail/resolve-conflict-item-vs-import.rs @@ -13,6 +13,6 @@ use std::mem::transmute; fn transmute() {} //~^ ERROR a value named `transmute` has already been imported in this module - +//~| was already imported fn main() { } |
