Error when using cross-crate static methods exported from a private module via pub use #4202
Description
Activity
I just tested and it's also a problem for public modules as well. ie:
foo.rs#[link(name = "foo", vers = "0.1")]; #[crate_type = "lib"]; pub use sub_foo::Foo; pub mod sub_foo { // <- added `pub` to this line and got the same error when compiling bar.rs pub trait Foo { static pub fn foo() -> self; } pub impl int: Foo { static pub fn foo() -> int { 42 } } }I'm hitting this too trying to update
Pathto proper constructor conventions. It's reexported from the prelude and after adding thenewmethod nobody can construct one.Not critical for 0.6; de-milestoning
Updated reproduction for rust incoming as of May 5th 2013: https://gist.github.com/thomaslee/5522568
Going to see if I can fix this ...
Looks like
rustc::middle::resolve::resolve_pathtries to resolve Foo as a module becausepathhas more than one element in itsidentsmember (specifically, the path isFoo::foo& thepath.idents.len() > 1check succeeds).I'll keep going down the rabbit hole tomorrow night -- I think the prime suspect atm is a parser bug.
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.rsas it relates toBar(a known "good" trait):rust: ~"(each_path) yielding reexported item: Bar" rust: ~"(building reduced graph for external crate) found path entry: Bar (dl_def(def_trait({crate: 2, node: 6})))" rust: ~"(building reduced graph for external crate) building type Bar" rust: ~"(building reduced graph for external crate) ... adding trait method \'bar\'" ... rust: ~"(each_path) yielding explicit item: Bar" rust: ~"(building reduced graph for external crate) found path entry: Baz (dl_def(def_trait({crate: 2, node: 6})))" rust: ~"(building reduced graph for external crate) building type Bar" rust: ~"(building reduced graph for external crate) ... adding trait method \'bar\'" uust: ~"(each_path) yielding explicit item: Bar::bar" rust: ~"(building reduced graph for external crate) found path entry: Bar::bar (dl_def(def_static_method({crate: 2, node: 5}, Some({crate: 2, node: 6}), impure_fn)))"And the output relating to
Foo(known to be broken) for the same build:rust: ~"(each_path) yielding reexported item: Foo" rust: ~"(building reduced graph for external crate) found path entry: Foo (dl_def(def_trait({crate: 2, node: 23})))" rust: ~"(building reduced graph for external crate) building type Foo" rust: ~"(building reduced graph for external crate) ... adding trait method \'foo\'" ...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.
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".
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
foocrate (omitting irrelevant junk):- Foo (
pub use sub_foo::Foo) - Bar
- Bar::bar
- sub_foo::Foo
- sub_foo::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 tousea trait (and thus somehow need to expose the trait's associated static methods in addition to the trait itself).Baron the other hand is declared at the top level: the metadata decoder pulls it in so the resolver findsBar::barin the right place. Note that e.g.use foo::sub_foo::Fooworks too for this reason: the metadata forfoo::sub_foo::Foo::foowas generated whenfoowas compiled.- Foo (
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.
- added a commit that references this issue
on May 10, 2013 - added a commit that references this issue
on May 11, 2013 - added a commit that references this issue
on May 11, 2013 - added a commit that references this issue
on May 20, 2013 confirmed fixed after updating original test case.
- added a commit that references this issue
on Jun 1, 2013
(commented-keywords below are copied over from original bug report.)
foo.rsbar.rs