Skip to content

Commit e02716e

Browse files
committed
Reexport static trait methods on traits in the same module.
1 parent ebdb0de commit e02716e

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

src/librustc/metadata/encoder.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -386,8 +386,10 @@ fn encode_reexported_static_methods(ecx: @EncodeContext,
386386
match ecx.tcx.trait_methods_cache.find(&exp.def_id) {
387387
Some(methods) => {
388388
match ecx.tcx.items.find(&exp.def_id.node) {
389-
Some(&ast_map::node_item(_, path)) => {
390-
if mod_path != *path {
389+
Some(&ast_map::node_item(item, path)) => {
390+
let interner = ecx.tcx.sess.parse_sess.interner;
391+
let original_name = ecx.tcx.sess.str_of(item.ident);
392+
if mod_path != *path || *exp.name != *original_name {
391393
for methods.each |&m| {
392394
if m.explicit_self == ast::sty_static {
393395
encode_reexported_static_method(ecx,

src/test/auxiliary/mod_trait_with_static_methods_lib.rs

+10
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,15 @@
99
// except according to those terms.
1010

1111
pub use sub_foo::Foo;
12+
pub use Baz = self::Bar;
13+
14+
pub trait Bar {
15+
pub fn bar() -> Self;
16+
}
17+
18+
impl Bar for int {
19+
pub fn bar() -> int { 84 }
20+
}
1221

1322
pub mod sub_foo {
1423
pub trait Foo {
@@ -18,4 +27,5 @@ pub mod sub_foo {
1827
impl Foo for int {
1928
pub fn foo() -> int { 42 }
2029
}
30+
2131
}

src/test/run-pass/trait_with_static_methods_cross_crate.rs

+2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
extern mod mod_trait_with_static_methods_lib;
1414

1515
use mod_trait_with_static_methods_lib::Foo;
16+
use mod_trait_with_static_methods_lib::Baz;
1617

1718
pub fn main() {
1819
assert_eq!(42, Foo::foo());
20+
assert_eq!(84, Baz::bar());
1921
}

0 commit comments

Comments
 (0)