Skip to content

Static methods are not resolved under the trait name cross-crate #4097

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
brson opened this issue Dec 2, 2012 · 1 comment
Closed

Static methods are not resolved under the trait name cross-crate #4097

brson opened this issue Dec 2, 2012 · 1 comment
Labels
A-trait-system Area: Trait system
Milestone

Comments

@brson
Copy link
Contributor

brson commented Dec 2, 2012

In this test num::Num2::from_int2 can't be resolved. If all defined in the same crate then it's fine.

static_fn_num_aux.rs

pub mod num {
    pub trait Num2 {
        static pure fn from_int2(n: int) -> self;
    }
}

pub mod float {
    impl float: num::Num2 {
        static pure fn from_int2(n: int) -> float { return n as float;  }
    }
}

static-fn-num.rs

// aux-build:static_fn_num_aux.rs

extern mod mycore(name ="static_fn_num_aux");

use mycore::num;

fn main() {
    let _1:float = num::Num2::from_int2(1i);
}
/home/brian/dev/rust/src/test/run-pass/static-fn-num.rs:35:19: 35:39 error: not a module: Num2
/home/brian/dev/rust/src/test/run-pass/static-fn-num.rs:35     let _1:float = num::Num2::from_int2(1i);
                                                                              ^~~~~~~~~~~~~~~~~~~~
/home/brian/dev/rust/src/test/run-pass/static-fn-num.rs:35:19: 35:39 error: use of undeclared module `num::Num2`
/home/brian/dev/rust/src/test/run-pass/static-fn-num.rs:35     let _1:float = num::Num2::from_int2(1i);
                                                                              ^~~~~~~~~~~~~~~~~~~~
/home/brian/dev/rust/src/test/run-pass/static-fn-num.rs:35:19: 35:39 error: unresolved name: num::Num2::from_int2
/home/brian/dev/rust/src/test/run-pass/static-fn-num.rs:35     let _1:float = num::Num2::from_int2(1i);
                                                                              ^~~~~~~~~~~~~~~~~~~~
error: aborting due to 3 previous errors

@brendanzab
Copy link
Member

Yes, this is a bit of a pain.

foo.rs

#[link(name = "foo",
       vers = "0.1")];
#[crate_type = "lib"];

pub trait Foo {
    static pub fn foo() -> self;
}

pub impl int: Foo {
    static pub fn foo() -> int { 42 }
}

bar.rs

extern mod foo;
use foo::Foo;

fn main() {
    assert 42 == Foo::foo();
}

error

$ rustc foo.rs 
warning: no debug symbols in executable (-arch x86_64)

$ rustc bar.rs -L .
bar.rs:5:17: 5:25 error: unresolved name
bar.rs:5     assert 42 == Foo::foo();
                          ^~~~~~~~
bar.rs:5:17: 5:25 error: use of undeclared module `Foo`
bar.rs:5     assert 42 == Foo::foo();
                          ^~~~~~~~
bar.rs:5:17: 5:25 error: unresolved name: Foo::foo
bar.rs:5     assert 42 == Foo::foo();
                          ^~~~~~~~
error: aborting due to 3 previous errors

@brson brson closed this as completed in 7ca9436 Dec 13, 2012
RalfJung pushed a commit to RalfJung/rust that referenced this issue Dec 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-trait-system Area: Trait system
Projects
None yet
Development

No branches or pull requests

2 participants