1
Fork 0

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

@ -822,10 +822,19 @@ impl<'tcx> fmt::Display for ty::TypeVariants<'tcx> {
}
try!(write!(f, "{}", bare_fn.sig.0));
try!(ty::tls::with(|tcx| {
write!(f, " {{{}", tcx.item_path_str(def_id))
}));
write!(f, " {{{}}}", ty::tls::with(|tcx| {
tcx.item_path_str(def_id)
}))
let tps = substs.types.get_slice(subst::FnSpace);
if tps.len() >= 1 {
try!(write!(f, "::<{}", tps[0]));
for &ty in &tps[1..] {
try!(write!(f, ", {}", ty));
}
try!(write!(f, ">"));
}
write!(f, "}}")
}
TyFnPtr(ref bare_fn) => {
if bare_fn.unsafety == hir::Unsafety::Unsafe {

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() { }