Closed
Description
(commented-keywords below are copied over from original bug report.)
foo.rs
#[link(name = "foo",
vers = "0.1")];
#[crate_type = "lib"];
pub use sub_foo::Foo;
mod sub_foo {
pub trait Foo {
/*static*/ /*pub*/ fn foo() -> Self;
}
/*pub*/ impl Foo for int {
/*static*/ /*pub*/ fn foo() -> int { 42 }
}
}
bar.rs
extern mod foo;
use foo::Foo;
fn main() {
assert!(42 == Foo::foo());
}
$ rustc --out-dir . src/foo.rs
warning: no debug symbols in executable (-arch x86_64)
$ rustc --out-dir . src/bar.rs -L .
src/bar.rs:5:17: 5:25 error: unresolved name
src/bar.rs:5 assert 42 == Foo::foo();
^~~~~~~~
src/bar.rs:5:17: 5:25 error: use of undeclared module `Foo`
src/bar.rs:5 assert 42 == Foo::foo();
^~~~~~~~
src/bar.rs:5:17: 5:25 error: unresolved name: Foo::foo
src/bar.rs:5 assert 42 == Foo::foo();
^~~~~~~~
error: aborting due to 3 previous errors
Metadata
Metadata
Assignees
Labels
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
brendanzab commentedon Dec 16, 2012
I just tested and it's also a problem for public modules as well. ie:
foo.rs
brson commentedon Mar 15, 2013
I'm hitting this too trying to update
Path
to proper constructor conventions. It's reexported from the prelude and after adding thenew
method nobody can construct one.Path
constructor to new conventions #5389pnkfelix commentedon Mar 25, 2013
Not critical for 0.6; de-milestoning
thomaslee commentedon May 5, 2013
Updated reproduction for rust incoming as of May 5th 2013: https://gist.github.com/thomaslee/5522568
Going to see if I can fix this ...
thomaslee commentedon May 6, 2013
Looks like
rustc::middle::resolve::resolve_path
tries to resolve Foo as a module becausepath
has more than one element in itsidents
member (specifically, the path isFoo::foo
& thepath.idents.len() > 1
check succeeds).I'll keep going down the rabbit hole tomorrow night -- I think the prime suspect atm is a parser bug.
thomaslee commentedon May 8, 2013
Alright, I haven't fully proven it yet, but it seems that after more investigation it looks like we may be skipping over some encoding work for the trait we're trying to expose via "pub use". Here's some debug output from building
bar.rs
as it relates toBar
(a known "good" trait):And the output relating to
Foo
(known to be broken) for the same build:We never see the explicit items that we saw decoded for our "good" trait. I'm still figuring out the metadata encoding/decoding stuff, but I have a strong suspicion this is at least related to the original gremlin.
thomaslee commentedon May 8, 2013
Looking closer at the code, I suspect the "reexported item: Foo" we're seeing in the log output may relate to sub_foo rather than our "pub use".
thomaslee commentedon May 8, 2013
Okay, lots of time lost on various rabbit holes, but I think I understand what's happening here now:
Basically we compile foo.rs & see the following explicit symbols exposed by the
foo
crate (omitting irrelevant junk):pub use sub_foo::Foo
)Note that the "outer" module has no reference to the static method
Foo::foo
. When we say "use sub_foo::Foo" at the top level, the compiler goes to no additional effort to try & figure out if maybe we're trying touse
a trait (and thus somehow need to expose the trait's associated static methods in addition to the trait itself).Bar
on the other hand is declared at the top level: the metadata decoder pulls it in so the resolver findsBar::bar
in the right place. Note that e.g.use foo::sub_foo::Foo
works too for this reason: the metadata forfoo::sub_foo::Foo::foo
was generated whenfoo
was compiled.thomaslee commentedon May 10, 2013
Have what I believe is a working fix for this that exposes static trait methods by including them in the reexport table iff the reexported trait has a path that differs from the path of the module in which is being reexported from. Will put together a test or two & submit a pull request.
Include static methods on traits in reexports.
Test case for issue rust-lang#4202
auto merge of #6384 : thomaslee/rust/issue-4202, r=catamorphism
auto merge of #6432 : thomaslee/rust/issue-4202-02, r=catamorphism
pnkfelix commentedon May 23, 2013
confirmed fixed after updating original test case.
auto merge of #6880 : thomaslee/rust/issue-6745, r=catamorphism