From e4e1242769d41c29f5814d6317f8497f285b3b15 Mon Sep 17 00:00:00 2001 From: Eduard Burtescu Date: Tue, 16 Feb 2016 18:37:32 +0200 Subject: [PATCH] Print fn type parameters for TyFnDef. --- src/librustc/util/ppaux.rs | 15 ++++++++--- src/test/compile-fail/fn-item-type.rs | 37 +++++++++++++++++++++------ src/test/pretty/issue-4264.pp | 6 +++-- 3 files changed, 45 insertions(+), 13 deletions(-) diff --git a/src/librustc/util/ppaux.rs b/src/librustc/util/ppaux.rs index 2b5674ed116a..8fd784cbde7a 100644 --- a/src/librustc/util/ppaux.rs +++ b/src/librustc/util/ppaux.rs @@ -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 { diff --git a/src/test/compile-fail/fn-item-type.rs b/src/test/compile-fail/fn-item-type.rs index 5015810ff477..775e22f0428b 100644 --- a/src/test/compile-fail/fn-item-type.rs +++ b/src/test/compile-fail/fn-item-type.rs @@ -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(x: isize) -> isize { x * 2 } +fn bar(x: isize) -> isize { x * 4 } fn eq(x: T, y: T) { } +trait Foo { fn foo() { /* this is a default fn */ } } +impl Foo for T { /* `foo` is still default here */ } + fn main() { - let f = if true { foo } else { bar }; + let f = if true { foo:: } else { bar:: }; //~^ ERROR if and else have incompatible types - //~| expected `fn(isize) -> isize {foo}` - //~| found `fn(isize) -> isize {bar}` + //~| expected `fn(isize) -> isize {foo::}` + //~| found `fn(isize) -> isize {bar::}` //~| expected fn item, //~| found a different fn item - eq(foo, bar); + eq(foo::, bar::); //~^ ERROR mismatched types - //~| expected `fn(isize) -> isize {foo}` - //~| found `fn(isize) -> isize {bar}` + //~| expected `fn(isize) -> isize {foo::}` + //~| found `fn(isize) -> isize {bar::}` //~| expected fn item //~| found a different fn item + + eq(foo::, foo::); + //~^ ERROR mismatched types + //~| expected `fn(isize) -> isize {foo::}` + //~| found `fn(isize) -> isize {foo::}` + + eq(bar::, bar::>); + //~^ ERROR mismatched types + //~| expected `fn(isize) -> isize {bar::}` + //~| found `fn(isize) -> isize {bar::>}` + //~| expected struct `collections::string::String` + //~| found struct `collections::vec::Vec` + + // Make sure we distinguish between trait methods correctly. + eq(::foo, ::foo); + //~^ ERROR mismatched types + //~| expected `fn() {Foo::foo}` + //~| found `fn() {Foo::foo}` } diff --git a/src/test/pretty/issue-4264.pp b/src/test/pretty/issue-4264.pp index 835f7fc96c63..0347631aeb33 100644 --- a/src/test/pretty/issue-4264.pp +++ b/src/test/pretty/issue-4264.pp @@ -86,8 +86,10 @@ pub fn id(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() { }