Highlight parts of fn in type errors

When a type error arises between two fn items, fn pointers or tuples,
highlight only the differing parts of each.
This commit is contained in:
Esteban Küber 2019-11-23 16:01:20 -08:00
parent f11759d38c
commit d92355c1db
16 changed files with 238 additions and 45 deletions

View file

@ -22,8 +22,8 @@ error[E0308]: method not compatible with trait
LL | fn wrong_bound1<'b,'c,'d:'a+'c>(self, b: Inv<'b>, c: Inv<'c>, d: Inv<'d>) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ lifetime mismatch
|
= note: expected fn pointer `fn(&'a isize, Inv<'c>, Inv<'c>, Inv<'d>)`
found fn pointer `fn(&'a isize, Inv<'_>, Inv<'c>, Inv<'d>)`
= note: expected fn pointer `fn(&'a isize, Inv<'c>, Inv<'c>, Inv<'_>)`
found fn pointer `fn(&'a isize, Inv<'_>, Inv<'c>, Inv<'_>)`
note: the lifetime `'c` as defined on the method body at 27:24...
--> $DIR/regions-bound-missing-bound-in-impl.rs:27:24
|

View file

@ -28,8 +28,8 @@ error[E0308]: mismatched types
LL | let x: unsafe extern "C" fn(f: isize, x: u8) = foo;
| ^^^ expected non-variadic fn, found variadic function
|
= note: expected fn pointer `unsafe extern "C" fn(isize, u8)`
found fn item `unsafe extern "C" fn(isize, u8, ...) {foo}`
= note: expected fn pointer `unsafe extern "C" fn(_, _)`
found fn item `unsafe extern "C" fn(_, _, ...) {foo}`
error[E0308]: mismatched types
--> $DIR/variadic-ffi-1.rs:20:54
@ -37,8 +37,8 @@ error[E0308]: mismatched types
LL | let y: extern "C" fn(f: isize, x: u8, ...) = bar;
| ^^^ expected variadic fn, found non-variadic function
|
= note: expected fn pointer `extern "C" fn(isize, u8, ...)`
found fn item `extern "C" fn(isize, u8) {bar}`
= note: expected fn pointer `extern "C" fn(_, _, ...)`
found fn item `extern "C" fn(_, _) {bar}`
error[E0617]: can't pass `f32` to variadic function
--> $DIR/variadic-ffi-1.rs:22:19

View file

@ -21,8 +21,8 @@ error[E0308]: mismatched types
LL | let _ = Checked::<{generic_arg::<u32>}>;
| ^^^^^^^^^^^^^^^^^^ expected `usize`, found `u32`
|
= note: expected fn pointer `fn(usize) -> bool`
found fn item `fn(u32) -> bool {generic_arg::<u32>}`
= note: expected fn pointer `fn(usize) -> _`
found fn item `fn(u32) -> _ {generic_arg::<u32>}`
error[E0282]: type annotations needed
--> $DIR/fn-const-param-infer.rs:22:23

View file

@ -12,8 +12,8 @@ impl<T> Foo for T { /* `foo` is still default here */ }
fn main() {
eq(foo::<u8>, bar::<u8>);
//~^ ERROR mismatched types
//~| expected fn item `fn(isize) -> isize {foo::<u8>}`
//~| found fn item `fn(isize) -> isize {bar::<u8>}`
//~| expected fn item `fn(_) -> _ {foo::<u8>}`
//~| found fn item `fn(_) -> _ {bar::<u8>}`
//~| expected fn item, found a different fn item
eq(foo::<u8>, foo::<i8>);
@ -22,8 +22,8 @@ fn main() {
eq(bar::<String>, bar::<Vec<u8>>);
//~^ ERROR mismatched types
//~| expected fn item `fn(isize) -> isize {bar::<std::string::String>}`
//~| found fn item `fn(isize) -> isize {bar::<std::vec::Vec<u8>>}`
//~| expected fn item `fn(_) -> _ {bar::<std::string::String>}`
//~| found fn item `fn(_) -> _ {bar::<std::vec::Vec<u8>>}`
//~| expected struct `std::string::String`, found struct `std::vec::Vec`
// Make sure we distinguish between trait methods correctly.

View file

@ -4,8 +4,8 @@ error[E0308]: mismatched types
LL | eq(foo::<u8>, bar::<u8>);
| ^^^^^^^^^ expected fn item, found a different fn item
|
= note: expected fn item `fn(isize) -> isize {foo::<u8>}`
found fn item `fn(isize) -> isize {bar::<u8>}`
= note: expected fn item `fn(_) -> _ {foo::<u8>}`
found fn item `fn(_) -> _ {bar::<u8>}`
error[E0308]: mismatched types
--> $DIR/fn-item-type.rs:19:19
@ -13,8 +13,8 @@ error[E0308]: mismatched types
LL | eq(foo::<u8>, foo::<i8>);
| ^^^^^^^^^ expected `u8`, found `i8`
|
= note: expected fn item `fn(isize) -> isize {foo::<u8>}`
found fn item `fn(isize) -> isize {foo::<i8>}`
= note: expected fn item `fn(_) -> _ {foo::<u8>}`
found fn item `fn(_) -> _ {foo::<i8>}`
error[E0308]: mismatched types
--> $DIR/fn-item-type.rs:23:23
@ -22,8 +22,8 @@ error[E0308]: mismatched types
LL | eq(bar::<String>, bar::<Vec<u8>>);
| ^^^^^^^^^^^^^^ expected struct `std::string::String`, found struct `std::vec::Vec`
|
= note: expected fn item `fn(isize) -> isize {bar::<std::string::String>}`
found fn item `fn(isize) -> isize {bar::<std::vec::Vec<u8>>}`
= note: expected fn item `fn(_) -> _ {bar::<std::string::String>}`
found fn item `fn(_) -> _ {bar::<std::vec::Vec<u8>>}`
error[E0308]: mismatched types
--> $DIR/fn-item-type.rs:30:26

View file

@ -4,8 +4,8 @@ error[E0053]: method `call_once` has an incompatible type for trait
LL | fn call_once(self, _args: ()) {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected "rust-call" fn, found "Rust" fn
|
= note: expected fn pointer `extern "rust-call" fn(Debuger<T>, ())`
found fn pointer `fn(Debuger<T>, ())`
= note: expected fn pointer `extern "rust-call" fn(Debuger<_>, ())`
found fn pointer `fn(Debuger<_>, ())`
error: aborting due to previous error

View file

@ -31,8 +31,8 @@ LL | fn baz(_: (u8, u16));
LL | fn baz(_: (u16, u16)) {}
| ^^^^^^^^^^ expected `u8`, found `u16`
|
= note: expected fn pointer `fn((u8, u16))`
found fn pointer `fn((u16, u16))`
= note: expected fn pointer `fn((u8, _))`
found fn pointer `fn((u16, _))`
error[E0053]: method `qux` has an incompatible type for trait
--> $DIR/issue-35869.rs:17:17

View file

@ -9,8 +9,8 @@ LL | | Some(&mut self.0)
LL | | }
| |_____^ lifetime mismatch
|
= note: expected fn pointer `fn(&mut RepeatMut<'a, T>) -> std::option::Option<&mut T>`
found fn pointer `fn(&'a mut RepeatMut<'a, T>) -> std::option::Option<&mut T>`
= note: expected fn pointer `fn(&mut RepeatMut<'a, T>) -> std::option::Option<_>`
found fn pointer `fn(&'a mut RepeatMut<'a, T>) -> std::option::Option<_>`
note: the anonymous lifetime #1 defined on the method body at 6:5...
--> $DIR/issue-37884.rs:6:5
|

View file

@ -4,8 +4,8 @@ error[E0308]: start function has wrong type
LL | fn start(argc: isize, argv: *const *const u8, crate_map: *const u8) -> isize {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ incorrect number of function parameters
|
= note: expected fn pointer `fn(isize, *const *const u8) -> isize`
found fn pointer `fn(isize, *const *const u8, *const u8) -> isize`
= note: expected fn pointer `fn(isize, *const *const u8) -> _`
found fn pointer `fn(isize, *const *const u8, *const u8) -> _`
error: aborting due to previous error

View file

@ -6,8 +6,8 @@ LL | fn foo(x: Option<fn(i32)>) -> Option<unsafe fn(i32)> {
LL | x
| ^ expected unsafe fn, found normal fn
|
= note: expected enum `std::option::Option<unsafe fn(i32)>`
found enum `std::option::Option<fn(i32)>`
= note: expected enum `std::option::Option<unsafe fn(_)>`
found enum `std::option::Option<fn(_)>`
error: aborting due to previous error

View file

@ -7,8 +7,8 @@ trait Foo {
impl Foo for u32 {
fn len(&self) -> u32 { *self }
//~^ ERROR method `len` has an incompatible type for trait
//~| expected fn pointer `unsafe fn(&u32) -> u32`
//~| found fn pointer `fn(&u32) -> u32`
//~| expected fn pointer `unsafe fn(&u32) -> _`
//~| found fn pointer `fn(&u32) -> _`
}
fn main() { }

View file

@ -7,8 +7,8 @@ LL | unsafe fn len(&self) -> u32;
LL | fn len(&self) -> u32 { *self }
| ^^^^^^^^^^^^^^^^^^^^ expected unsafe fn, found normal fn
|
= note: expected fn pointer `unsafe fn(&u32) -> u32`
found fn pointer `fn(&u32) -> u32`
= note: expected fn pointer `unsafe fn(&u32) -> _`
found fn pointer `fn(&u32) -> _`
error: aborting due to previous error

View file

@ -22,8 +22,8 @@ error[E0053]: method `mul` has an incompatible type for trait
LL | fn mul(self, s: f64) -> f64 {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ expected `i32`, found `f64`
|
= note: expected fn pointer `fn(Vec3, f64) -> i32`
found fn pointer `fn(Vec3, f64) -> f64`
= note: expected fn pointer `fn(Vec3, _) -> i32`
found fn pointer `fn(Vec3, _) -> f64`
error[E0308]: mismatched types
--> $DIR/wrong-mul-method-signature.rs:63:45