Skip to content

Commit e4e1242

Browse files
committed
Print fn type parameters for TyFnDef.
1 parent ffa0860 commit e4e1242

File tree

3 files changed

+46
-14
lines changed

3 files changed

+46
-14
lines changed

src/librustc/util/ppaux.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -822,10 +822,19 @@ impl<'tcx> fmt::Display for ty::TypeVariants<'tcx> {
822822
}
823823

824824
try!(write!(f, "{}", bare_fn.sig.0));
825-
826-
write!(f, " {{{}}}", ty::tls::with(|tcx| {
827-
tcx.item_path_str(def_id)
828-
}))
825+
try!(ty::tls::with(|tcx| {
826+
write!(f, " {{{}", tcx.item_path_str(def_id))
827+
}));
828+
829+
let tps = substs.types.get_slice(subst::FnSpace);
830+
if tps.len() >= 1 {
831+
try!(write!(f, "::<{}", tps[0]));
832+
for &ty in &tps[1..] {
833+
try!(write!(f, ", {}", ty));
834+
}
835+
try!(write!(f, ">"));
836+
}
837+
write!(f, "}}")
829838
}
830839
TyFnPtr(ref bare_fn) => {
831840
if bare_fn.unsafety == hir::Unsafety::Unsafe {

src/test/compile-fail/fn-item-type.rs

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,44 @@
1111
// Test that the types of distinct fn items are not compatible by
1212
// default. See also `run-pass/fn-item-type-*.rs`.
1313

14-
fn foo(x: isize) -> isize { x * 2 }
15-
fn bar(x: isize) -> isize { x * 4 }
14+
fn foo<T>(x: isize) -> isize { x * 2 }
15+
fn bar<T>(x: isize) -> isize { x * 4 }
1616

1717
fn eq<T>(x: T, y: T) { }
1818

19+
trait Foo { fn foo() { /* this is a default fn */ } }
20+
impl<T> Foo for T { /* `foo` is still default here */ }
21+
1922
fn main() {
20-
let f = if true { foo } else { bar };
23+
let f = if true { foo::<u8> } else { bar::<u8> };
2124
//~^ ERROR if and else have incompatible types
22-
//~| expected `fn(isize) -> isize {foo}`
23-
//~| found `fn(isize) -> isize {bar}`
25+
//~| expected `fn(isize) -> isize {foo::<u8>}`
26+
//~| found `fn(isize) -> isize {bar::<u8>}`
2427
//~| expected fn item,
2528
//~| found a different fn item
2629

27-
eq(foo, bar);
30+
eq(foo::<u8>, bar::<u8>);
2831
//~^ ERROR mismatched types
29-
//~| expected `fn(isize) -> isize {foo}`
30-
//~| found `fn(isize) -> isize {bar}`
32+
//~| expected `fn(isize) -> isize {foo::<u8>}`
33+
//~| found `fn(isize) -> isize {bar::<u8>}`
3134
//~| expected fn item
3235
//~| found a different fn item
36+
37+
eq(foo::<u8>, foo::<i8>);
38+
//~^ ERROR mismatched types
39+
//~| expected `fn(isize) -> isize {foo::<u8>}`
40+
//~| found `fn(isize) -> isize {foo::<i8>}`
41+
42+
eq(bar::<String>, bar::<Vec<u8>>);
43+
//~^ ERROR mismatched types
44+
//~| expected `fn(isize) -> isize {bar::<collections::string::String>}`
45+
//~| found `fn(isize) -> isize {bar::<collections::vec::Vec<u8>>}`
46+
//~| expected struct `collections::string::String`
47+
//~| found struct `collections::vec::Vec`
48+
49+
// Make sure we distinguish between trait methods correctly.
50+
eq(<u8 as Foo>::foo, <u16 as Foo>::foo);
51+
//~^ ERROR mismatched types
52+
//~| expected `fn() {Foo::foo}`
53+
//~| found `fn() {Foo::foo}`
3354
}

src/test/pretty/issue-4264.pp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,10 @@
8686
pub fn use_id() {
8787
let _ =
8888
((id::<[i32; (3 as usize)]> as
89-
fn([i32; 3]) -> [i32; 3] {id})(([(1 as i32), (2 as i32),
90-
(3 as i32)] as [i32; 3])) as
89+
fn([i32; 3]) -> [i32; 3] {id::<[i32; 3]>})(([(1 as i32),
90+
(2 as i32),
91+
(3 as i32)] as
92+
[i32; 3])) as
9193
[i32; 3]);
9294
}
9395
fn main() { }

0 commit comments

Comments
 (0)