From 2ec3a0b60833736a3c0d805768885b4392c36100 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Fri, 10 Feb 2012 21:28:44 -0800 Subject: [PATCH] correct fully qualified type names to include the crate; add tests fixes #1745 --- src/comp/metadata/csearch.rs | 3 ++- src/comp/middle/ast_map.rs | 2 +- .../compile-fail/fully-qualified-type-name1.rs | 7 +++++++ .../compile-fail/fully-qualified-type-name2.rs | 17 +++++++++++++++++ 4 files changed, 27 insertions(+), 2 deletions(-) create mode 100644 src/test/compile-fail/fully-qualified-type-name1.rs create mode 100644 src/test/compile-fail/fully-qualified-type-name2.rs diff --git a/src/comp/metadata/csearch.rs b/src/comp/metadata/csearch.rs index 1ac86faed0d2..6cd78d0b5c44 100644 --- a/src/comp/metadata/csearch.rs +++ b/src/comp/metadata/csearch.rs @@ -60,7 +60,8 @@ fn resolve_path(cstore: cstore::cstore, cnum: ast::crate_num, fn get_item_path(tcx: ty::ctxt, def: ast::def_id) -> ast_map::path { let cstore = tcx.sess.cstore; let cdata = cstore::get_crate_data(cstore, def.crate); - ret decoder::get_item_path(cdata, def.node); + let path = decoder::get_item_path(cdata, def.node); + [ast_map::path_mod(cdata.name)] + path } fn get_enum_variants(tcx: ty::ctxt, def: ast::def_id) -> [ty::variant_info] { diff --git a/src/comp/middle/ast_map.rs b/src/comp/middle/ast_map.rs index 1504f5f738e0..01ad8a3df670 100644 --- a/src/comp/middle/ast_map.rs +++ b/src/comp/middle/ast_map.rs @@ -17,7 +17,7 @@ fn path_to_str_with_sep(p: path, sep: str) -> str { } fn path_to_str(p: path) -> str { - path_to_str_with_sep(p, "::") + "::" + path_to_str_with_sep(p, "::") } enum ast_node { diff --git a/src/test/compile-fail/fully-qualified-type-name1.rs b/src/test/compile-fail/fully-qualified-type-name1.rs new file mode 100644 index 000000000000..9a197de565b6 --- /dev/null +++ b/src/test/compile-fail/fully-qualified-type-name1.rs @@ -0,0 +1,7 @@ +// Test that we use fully-qualified type names in error messages. + +fn main() { + let x: option; + x = 5; + //!^ ERROR mismatched types: expected `::core::option::t` +} diff --git a/src/test/compile-fail/fully-qualified-type-name2.rs b/src/test/compile-fail/fully-qualified-type-name2.rs new file mode 100644 index 000000000000..4b40875ebd18 --- /dev/null +++ b/src/test/compile-fail/fully-qualified-type-name2.rs @@ -0,0 +1,17 @@ +// Test that we use fully-qualified type names in error messages. + +mod x { + enum foo { } +} + +mod y { + enum foo { } +} + +fn bar(x: x::foo) -> y::foo { + ret x; + //!^ ERROR mismatched types: expected `::y::foo` but found `::x::foo` +} + +fn main() { +}