Teach Diagnostics to highlight text

This commit is contained in:
Esteban Küber 2017-01-11 13:55:41 -08:00
parent bd8e9b0c82
commit fc774e629f
29 changed files with 242 additions and 67 deletions

View file

@ -8,7 +8,7 @@ error[E0053]: method `b` has an incompatible type for trait
| ^ expected type parameter, found a different type parameter
|
= note: expected type `fn(&E, F) -> F`
= note: found type `fn(&E, G) -> G`
found type `fn(&E, G) -> G`
error: aborting due to previous error

View file

@ -0,0 +1,30 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
trait Foo {
fn foo(x: u16); //~ NOTE type in trait
fn bar(&self); //~ NOTE type in trait
}
struct Bar;
impl Foo for Bar {
fn foo(x: i16) { }
//~^ ERROR method `foo` has an incompatible type for trait
//~| NOTE expected u16
fn bar(&mut self) { }
//~^ ERROR method `bar` has an incompatible type for trait
//~| NOTE types differ in mutability
//~| NOTE expected type `fn(&Bar)`
//~| NOTE found type `fn(&mut Bar)`
}
fn main() {
}

View file

@ -0,0 +1,23 @@
error[E0053]: method `foo` has an incompatible type for trait
--> $DIR/E0053.rs:19:15
|
12 | fn foo(x: u16); //~ NOTE type in trait
| --- type in trait
...
19 | fn foo(x: i16) { }
| ^^^ expected u16, found i16
error[E0053]: method `bar` has an incompatible type for trait
--> $DIR/E0053.rs:22:12
|
13 | fn bar(&self); //~ NOTE type in trait
| ----- type in trait
...
22 | fn bar(&mut self) { }
| ^^^^^^^^^ types differ in mutability
|
= note: expected type `fn(&Bar)`
found type `fn(&mut Bar)`
error: aborting due to 2 previous errors

View file

@ -0,0 +1,24 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
fn main() {
let x = (0, 2);
match x {
(0, ref y) | (y, 0) => {} //~ ERROR E0409
//~^ NOTE bound in different ways
//~| NOTE first binding
//~| ERROR E0308
//~| NOTE expected &{integer}, found integral variable
//~| NOTE expected type `&{integer}`
//~| NOTE found type `{integer}`
_ => ()
}
}

View file

@ -0,0 +1,19 @@
error[E0409]: variable `y` is bound with different mode in pattern #2 than in pattern #1
--> $DIR/E0409.rs:15:23
|
15 | (0, ref y) | (y, 0) => {} //~ ERROR E0409
| - ^ bound in different ways
| |
| first binding
error[E0308]: mismatched types
--> $DIR/E0409.rs:15:23
|
15 | (0, ref y) | (y, 0) => {} //~ ERROR E0409
| ^ expected &{integer}, found integral variable
|
= note: expected type `&{integer}`
found type `{integer}`
error: aborting due to previous error

View file

@ -0,0 +1,21 @@
// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
trait Trait { }
fn function(t: &mut Trait) {
t as *mut Trait
//~^ ERROR: mismatched types
//~| NOTE: expected type `()`
//~| NOTE: found type `*mut Trait`
//~| NOTE: expected (), found *-ptr
}
fn main() { }

View file

@ -0,0 +1,11 @@
error[E0308]: mismatched types
--> $DIR/issue-19109.rs:14:5
|
14 | t as *mut Trait
| ^^^^^^^^^^^^^^^ expected (), found *-ptr
|
= note: expected type `()`
found type `*mut Trait`
error: aborting due to previous error

View file

@ -5,7 +5,7 @@ error[E0308]: mismatched types
| ^^^^ expected type parameter, found bool
|
= note: expected type `bool` (type parameter)
= note: found type `bool` (bool)
found type `bool` (bool)
error: aborting due to previous error

View file

@ -5,7 +5,7 @@ error[E0308]: mismatched types
| ^^^^ expected struct `Foo`, found reference
|
= note: expected type `Foo`
= note: found type `&_`
found type `&_`
= help: did you mean `foo: &Foo`?
error[E0308]: mismatched types
@ -15,7 +15,7 @@ error[E0308]: mismatched types
| ^^^^ expected u32, found reference
|
= note: expected type `u32`
= note: found type `&_`
found type `&_`
error[E0308]: mismatched types
--> $DIR/issue-38371.rs:31:8
@ -24,7 +24,7 @@ error[E0308]: mismatched types
| ^^^^^ expected u32, found reference
|
= note: expected type `u32`
= note: found type `&_`
found type `&_`
error[E0529]: expected an array or slice, found `u32`
--> $DIR/issue-38371.rs:34:9

View file

@ -7,7 +7,7 @@ error[E0308]: mismatched types
| |_____^ ...ending here: expected u32, found ()
|
= note: expected type `u32`
= note: found type `()`
found type `()`
error: aborting due to previous error

View file

@ -0,0 +1,48 @@
// Copyright 2012 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
#![feature(fn_traits, unboxed_closures)]
use std::ops::FnMut;
struct S {
x: isize,
y: isize,
}
impl FnMut<(isize,)> for S {
extern "rust-call" fn call_mut(&mut self, (z,): (isize,)) -> isize {
self.x * self.y * z
}
}
impl FnOnce<(isize,)> for S {
type Output = isize;
extern "rust-call" fn call_once(mut self, (z,): (isize,)) -> isize {
self.call_mut((z,))
}
}
fn main() {
let mut s = S {
x: 3,
y: 3,
};
let ans = s("what"); //~ ERROR mismatched types
//~^ NOTE expected isize, found reference
//~| NOTE expected type
//~| NOTE found type
let ans = s();
//~^ ERROR this function takes 1 parameter but 0 parameters were supplied
//~| NOTE expected 1 parameter
let ans = s("burma", "shave");
//~^ ERROR this function takes 1 parameter but 2 parameters were supplied
//~| NOTE expected 1 parameter
}

View file

@ -0,0 +1,23 @@
error[E0308]: mismatched types
--> $DIR/overloaded-calls-bad.rs:38:17
|
38 | let ans = s("what"); //~ ERROR mismatched types
| ^^^^^^ expected isize, found reference
|
= note: expected type `isize`
found type `&'static str`
error[E0057]: this function takes 1 parameter but 0 parameters were supplied
--> $DIR/overloaded-calls-bad.rs:42:15
|
42 | let ans = s();
| ^^^ expected 1 parameter
error[E0057]: this function takes 1 parameter but 2 parameters were supplied
--> $DIR/overloaded-calls-bad.rs:45:17
|
45 | let ans = s("burma", "shave");
| ^^^^^^^^^^^^^^^^ expected 1 parameter
error: aborting due to 3 previous errors

View file

@ -0,0 +1,30 @@
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
trait Foo {
fn dummy(&self) { }
}
fn a(_x: Box<Foo+Send>) {
}
fn c(x: Box<Foo+Sync+Send>) {
a(x);
}
fn d(x: Box<Foo>) {
a(x); //~ ERROR mismatched types [E0308]
//~| NOTE expected type `Box<Foo + std::marker::Send + 'static>`
//~| NOTE found type `Box<Foo + 'static>`
//~| NOTE expected trait `Foo + std::marker::Send`, found trait `Foo`
}
fn main() { }

View file

@ -0,0 +1,11 @@
error[E0308]: mismatched types
--> $DIR/trait-bounds-cant-coerce.rs:24:7
|
24 | a(x); //~ ERROR mismatched types [E0308]
| ^ expected trait `Foo + std::marker::Send`, found trait `Foo`
|
= note: expected type `Box<Foo + std::marker::Send + 'static>`
found type `Box<Foo + 'static>`
error: aborting due to previous error

View file

@ -17,7 +17,7 @@ error[E0053]: method `bar` has an incompatible type for trait
| ^^^^ types differ in mutability
|
= note: expected type `fn(&mut Bar, &mut Bar)`
= note: found type `fn(&mut Bar, &Bar)`
found type `fn(&mut Bar, &Bar)`
error: aborting due to 2 previous errors

View file

@ -35,7 +35,7 @@ error[E0308]: mismatched types
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected (), found enum `std::result::Result`
|
= note: expected type `()`
= note: found type `std::result::Result<bool, std::io::Error>`
found type `std::result::Result<bool, std::io::Error>`
= help: here are some functions which might fulfill your needs:
- .unwrap()
- .unwrap_err()

View file

@ -5,7 +5,7 @@ error[E0308]: mismatched types
| ^^^^^^^^^^^^^ expected usize, found struct `std::string::String`
|
= note: expected type `usize`
= note: found type `std::string::String`
found type `std::string::String`
= help: here are some functions which might fulfill your needs:
- .capacity()
- .len()
@ -17,7 +17,7 @@ error[E0308]: mismatched types
| ^^^^^^^^^^^^^ expected &str, found struct `std::string::String`
|
= note: expected type `&str`
= note: found type `std::string::String`
found type `std::string::String`
= help: here are some functions which might fulfill your needs:
- .as_str()
- .trim()
@ -31,7 +31,7 @@ error[E0308]: mismatched types
| ^^ types differ in mutability
|
= note: expected type `&mut std::string::String`
= note: found type `&std::string::String`
found type `&std::string::String`
error[E0308]: mismatched types
--> $DIR/coerce-suggestions.rs:36:11
@ -40,7 +40,7 @@ error[E0308]: mismatched types
| ^^ types differ in mutability
|
= note: expected type `&mut i32`
= note: found type `&std::string::String`
found type `&std::string::String`
error[E0308]: mismatched types
--> $DIR/coerce-suggestions.rs:42:9
@ -49,7 +49,7 @@ error[E0308]: mismatched types
| ^^^^^ cyclic type of infinite size
|
= note: expected type `_`
= note: found type `Box<_>`
found type `Box<_>`
error: aborting due to 5 previous errors

View file

@ -5,7 +5,7 @@ error[E0308]: mismatched method receiver
| ^^^^^^^^^ expected Self, found struct `SomeType`
|
= note: expected type `&Self`
= note: found type `&SomeType`
found type `&SomeType`
error: aborting due to previous error

View file

@ -5,7 +5,7 @@ error[E0308]: mismatched types
| ^^^^^^^^^^ expected (), found closure
|
= note: expected type `()`
= note: found type `[closure@$DIR/move-closure.rs:15:17: 15:27]`
found type `[closure@$DIR/move-closure.rs:15:17: 15:27]`
error: aborting due to previous error