Print fn type parameters for TyFnDef.

This commit is contained in:
Eduard Burtescu 2016-02-16 18:37:32 +02:00
parent ffa0860467
commit e4e1242769
3 changed files with 45 additions and 13 deletions

View file

@ -11,23 +11,44 @@
// Test that the types of distinct fn items are not compatible by
// default. See also `run-pass/fn-item-type-*.rs`.
fn foo(x: isize) -> isize { x * 2 }
fn bar(x: isize) -> isize { x * 4 }
fn foo<T>(x: isize) -> isize { x * 2 }
fn bar<T>(x: isize) -> isize { x * 4 }
fn eq<T>(x: T, y: T) { }
trait Foo { fn foo() { /* this is a default fn */ } }
impl<T> Foo for T { /* `foo` is still default here */ }
fn main() {
let f = if true { foo } else { bar };
let f = if true { foo::<u8> } else { bar::<u8> };
//~^ ERROR if and else have incompatible types
//~| expected `fn(isize) -> isize {foo}`
//~| found `fn(isize) -> isize {bar}`
//~| expected `fn(isize) -> isize {foo::<u8>}`
//~| found `fn(isize) -> isize {bar::<u8>}`
//~| expected fn item,
//~| found a different fn item
eq(foo, bar);
eq(foo::<u8>, bar::<u8>);
//~^ ERROR mismatched types
//~| expected `fn(isize) -> isize {foo}`
//~| found `fn(isize) -> isize {bar}`
//~| expected `fn(isize) -> isize {foo::<u8>}`
//~| found `fn(isize) -> isize {bar::<u8>}`
//~| expected fn item
//~| found a different fn item
eq(foo::<u8>, foo::<i8>);
//~^ ERROR mismatched types
//~| expected `fn(isize) -> isize {foo::<u8>}`
//~| found `fn(isize) -> isize {foo::<i8>}`
eq(bar::<String>, bar::<Vec<u8>>);
//~^ ERROR mismatched types
//~| expected `fn(isize) -> isize {bar::<collections::string::String>}`
//~| found `fn(isize) -> isize {bar::<collections::vec::Vec<u8>>}`
//~| expected struct `collections::string::String`
//~| found struct `collections::vec::Vec`
// Make sure we distinguish between trait methods correctly.
eq(<u8 as Foo>::foo, <u16 as Foo>::foo);
//~^ ERROR mismatched types
//~| expected `fn() {Foo::foo}`
//~| found `fn() {Foo::foo}`
}

View file

@ -86,8 +86,10 @@ pub fn id<T>(x: T) -> T { (x as T) }
pub fn use_id() {
let _ =
((id::<[i32; (3 as usize)]> as
fn([i32; 3]) -> [i32; 3] {id})(([(1 as i32), (2 as i32),
(3 as i32)] as [i32; 3])) as
fn([i32; 3]) -> [i32; 3] {id::<[i32; 3]>})(([(1 as i32),
(2 as i32),
(3 as i32)] as
[i32; 3])) as
[i32; 3]);
}
fn main() { }