Skip to content

extern mod inside of module doesn't work as expected #4677

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
jbclements opened this issue Jan 29, 2013 · 2 comments
Closed

extern mod inside of module doesn't work as expected #4677

jbclements opened this issue Jan 29, 2013 · 2 comments

Comments

@jbclements
Copy link
Contributor

It doesn't seem possible to use 'extern mod' inside of a module.

in file cratey.rs:

#[ link(name = "cratey",
        vers = "0.1",
        uuid = "418CE8FB-DE11-4FEF-BC71-E3F36047696F") ];

#[ crate_type = "lib" ];

pub fn add1 (x : int) -> int { x + 1 }

In the same directory, crateuser.rs:

pub mod mymod {
  extern mod cratey;
  use cratey::add1;
  fn main() { add1(3); }
}

compilation of the crate works fine, but linking against it causes an error:

machine> rustc cratey.rs
Running /Users/clements/rust/build/x86_64-apple-darwin/stage2/bin/rustc:
warning: no debug symbols in executable (-arch x86_64)
machine> rustc -L . crateuser.rs
Running /Users/clements/rust/build/x86_64-apple-darwin/stage2/bin/rustc:
crateuser.rs:6:4: 6:17 error: unresolved name
crateuser.rs:6 use cratey::add1;
                   ^~~~~~~~~~~~~
crateuser.rs:6:4: 6:17 error: failed to resolve import: cratey::add1
crateuser.rs:6 use cratey::add1;
                   ^~~~~~~~~~~~~
error: failed to resolve imports
error: aborting due to 3 previous errors

Removing the "mod mymod" wrapper allows the thing to compile fine. Apologies if this is the way it's supposed to work; casual stand-up-and-shout suggests to me that it should be possible to put an extern mod inside a module.

@graydon
Copy link
Contributor

graydon commented Jan 30, 2013

Use self::cratey::add1 ?

@jbclements
Copy link
Contributor Author

I see... 'use' paths are relative to the crate root, and not to the current module. I've added a note (not yet pushed) to the documentation about this; hopefully this will prevent others from making this mistake.

Thanks!

Closing this issue.

flip1995 pushed a commit to flip1995/rust that referenced this issue Oct 9, 2020
…, r=matthiaskrgr

Fix a FP in `explicit_counter_loop`

Fixes rust-lang#4677 and rust-lang#6074

Fix a false positive in `explicit_counter_loop` where the loop counter is used after incremented, adjust the test so that counters are incremented at the end of the loop and add the test for this false positive.

---

changelog: Fix a false positive in `explicit_counter_loop` where the loop counter is used after incremented
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants