Ha, you’re right, if I put the `extern crate` in main.rs and drop the `self::`, 
it works.
Anyway should I make an issue on github?




On Friday 5 September 2014 at 18:05, Erick Tryzelaar wrote:

> Woah, this is unexpected behavior. I've slimmed down this error to:
>  
> lib.rs (http://lib.rs):
> ```
> extern crate serialize;
>  
> struct Foo;
>  
> impl <D: ::serialize::Decoder<E>, E> ::serialize::Decodable<D, E> for Foo {
> fn decode(_d: &mut D) -> Result<Foo, E> {
> fail!()
> }
> }
> ```
>  
> main.rs (http://main.rs):
> ```
> mod lib;
> fn main() {}
> ```
>  
>  
> Which errors with:
>  
> ```
> lib.rs:5:10: 5:19 error: failed to resolve. Did you mean `self::serialize`?
> lib.rs:5 (http://lib.rs:5) impl <D: ::serialize::Decoder<E>, E> 
> ::serialize::Decodable<D, E> for Foo {
> ^~~~~~~~~
> lib.rs:5:10: 5:33 error: attempt to bound type parameter with a nonexistent 
> trait `serialize::Decoder`
> lib.rs:5 (http://lib.rs:5) impl <D: ::serialize::Decoder<E>, E> 
> ::serialize::Decodable<D, E> for Foo {
> ^~~~~~~~~~~~~~~~~~~~~~~
> lib.rs:5:38: 5:47 error: failed to resolve. Did you mean `self::serialize`?
> lib.rs:5 (http://lib.rs:5) impl <D: ::serialize::Decoder<E>, E> 
> ::serialize::Decodable<D, E> for Foo {
> ^~~~~~~~~
> lib.rs:5:38: 5:66 error: attempt to implement a nonexistent trait 
> `serialize::Decodable`
> lib.rs:5 (http://lib.rs:5) impl <D: ::serialize::Decoder<E>, E> 
> ::serialize::Decodable<D, E> for Foo {
> ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
> error: aborting due to 4 previous errors
> ```
>  
> However, if instead we use a relative path to `serialize::Decoder` and etc, 
> it works:
>  
> ```
> extern crate serialize;
>  
> struct Foo;
>  
> impl <D: serialize::Decoder<E>, E> serialize::Decodable<D, E> for Foo {
> fn decode(_d: &mut D) -> Result<Foo, E> {
> fail!()
> }
> }
> ```
>  
> It also works if we move the `extern crate serialize` into `main.rs 
> (http://main.rs)`. Since almost everyone puts the `extern crate` in the 
> lib.rs/main.rs (http://lib.rs/main.rs) of a project, we tend not to run into 
> this. I thought this used to work. Has anything recently changed in name 
> resolution that would have changed how how `extern crate` works with 
> submodules?
>  
>  
>  
> On Fri, Sep 5, 2014 at 8:41 AM, Oldřich Vetešník <oldrich.vetes...@gmail.com 
> (mailto:oldrich.vetes...@gmail.com)> wrote:
> > Hello all,
> >  
> > I’m having some trouble when using external crates in a module. For example 
> > the following code won’t compile.
> > But if I put everything in main.rs (http://main.rs) it will compile.
> > (Note: the code is also here 
> > https://gist.github.com/ollie/90e266f4cbfcad21501d if it gets mangled along 
> > the way.)
> >  
> > main.rs (http://main.rs):
> >  
> > use lib::decode_json_file;
> >  
> > mod lib;
> >  
> > fn main() {
> > decode_json_file();
> > }
> >  
> >  
> > lib.rs (http://lib.rs):
> >  
> > extern crate serialize;
> >  
> > use self::serialize::json;
> > // This has no effect:
> > // use self::serialize::{Decodable, Decoder};
> >  
> > #[deriving(Show, Decodable)]
> > struct Foo {
> > foo: u8,
> > }
> >  
> > pub fn decode_json_file() {
> > let raw_json = "{ \"foo\": 1 }";
> >  
> > let foo: Foo = json::decode(raw_json).unwrap();
> >  
> > println!("{}", foo);
> > }
> >  
> >  
> > When I run rustc main.rs (http://main.rs), it prints this:
> >  
> > lib.rs:7:18: 7:27 error: failed to resolve. Did you mean `self::serialize`?
> > lib.rs:7 (http://lib.rs:7) #[deriving(Show, Decodable)]
> > ^~~~~~~~~
> > note: in expansion of #[deriving]
> > lib.rs:7:1: 7:29 note: expansion site
> > lib.rs:7:18: 7:27 error: attempt to bound type parameter with a nonexistent 
> > trait `serialize::Decoder`
> > lib.rs:7 (http://lib.rs:7) #[deriving(Show, Decodable)]
> > ^~~~~~~~~
> > note: in expansion of #[deriving]
> > lib.rs:7:1: 7:29 note: expansion site
> > lib.rs:7:18: 7:27 error: failed to resolve. Did you mean `self::serialize`?
> > lib.rs:7 (http://lib.rs:7) #[deriving(Show, Decodable)]
> > ^~~~~~~~~
> > note: in expansion of #[deriving]
> > lib.rs:7:1: 7:29 note: expansion site
> > lib.rs:7:18: 7:27 error: attempt to implement a nonexistent trait 
> > `serialize::Decodable`
> > lib.rs:7 (http://lib.rs:7) #[deriving(Show, Decodable)]
> > ^~~~~~~~~
> > note: in expansion of #[deriving]
> > lib.rs:7:1: 7:29 note: expansion site
> > lib.rs:7:18: 7:27 error: failed to resolve. Did you mean 
> > `self::serialize::Decodable`?
> > lib.rs:7 (http://lib.rs:7) #[deriving(Show, Decodable)]
> > ^~~~~~~~~
> > note: in expansion of #[deriving]
> > lib.rs:7:1: 7:29 note: expansion site
> > lib.rs:7:18: 7:27 error: unresolved name `serialize::Decodable::decode`.
> > lib.rs:7 (http://lib.rs:7) #[deriving(Show, Decodable)]
> > ^~~~~~~~~
> > note: in expansion of #[deriving]
> > lib.rs:7:1: 7:29 note: expansion site
> > error: aborting due to 6 previous errors
> >  
> >  
> > Am I doing something wrong?
> >  
> > Thank you and have a nice day,
> > Ollie
> >  
> > _______________________________________________
> > Rust-dev mailing list
> > Rust-dev@mozilla.org (mailto:Rust-dev@mozilla.org)
> > https://mail.mozilla.org/listinfo/rust-dev
>  



_______________________________________________
Rust-dev mailing list
Rust-dev@mozilla.org
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to