Skip to content
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

extern crate foo with use self::foo doesn't work inside a function #27626

Closed
durka opened this issue Aug 10, 2015 · 9 comments
Closed

extern crate foo with use self::foo doesn't work inside a function #27626

durka opened this issue Aug 10, 2015 · 9 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Path resolution C-enhancement Category: An issue proposing an enhancement or a PR with one.

Comments

@durka
Copy link
Contributor

durka commented Aug 10, 2015

EDIT (@steveklabnik) see #27626 (comment)

This code fails and rustc doesn't tell you why:

fn main() {
    extern crate rand;
    use self::rand::Rng;
}

(playpen)

I think it should at least warn, assuming there is some reason why it can't do what it looks like it does.

@tomjakubowski
Copy link
Contributor

It's not true that it does nothing at all (playpen)

#![feature(rand)]

fn main() {
    extern crate rand;
    let rng = rand::chacha::ChaChaRng::new_unseeded();
}

@durka
Copy link
Contributor Author

durka commented Aug 10, 2015

Huh. Fascinating. And you can use trait methods that way without importing the trait, as long as you use UFCS, which I thought was supposed to be impossible. So, I count this as another confusion caused by use paths being different from all other paths.

@durka durka closed this as completed Aug 10, 2015
@durka durka reopened this Aug 10, 2015
@durka
Copy link
Contributor Author

durka commented Aug 10, 2015

Well, maybe I'll leave the issue open, in case there's any way to fix the diagnostic.

@steveklabnik
Copy link
Member

Given that nobody has commented in over a year, I'm going to give this one a close; a better diagnostic here would be nice, but since nobody else has run into it, and this is a very niche case, I don't think we need to track it. If you feel super strongly, we can re-open I guess, but I doubt this is going to be fixed.

@durka
Copy link
Contributor Author

durka commented Nov 30, 2016 via email

@steveklabnik
Copy link
Member

I am not sure if there is; let's re-open this one for that then, I guess.

@steveklabnik steveklabnik reopened this Nov 30, 2016
@steveklabnik steveklabnik changed the title extern crate not at module root does nothing at all extern crate + use in a function leads to nonsense "did you mean use self::self" Nov 30, 2016
@durka
Copy link
Contributor Author

durka commented Nov 30, 2016 via email

@steveklabnik steveklabnik removed the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 9, 2017
@Mark-Simulacrum Mark-Simulacrum changed the title extern crate + use in a function leads to nonsense "did you mean use self::self" extern crate foo with use self::foo doesn't work inside a function Jun 1, 2017
@Mark-Simulacrum Mark-Simulacrum added the A-resolve Area: Path resolution label Jun 1, 2017
@Mark-Simulacrum Mark-Simulacrum added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jul 22, 2017
@steveklabnik
Copy link
Member

steveklabnik commented Mar 16, 2019

Triage: this error message has gotten a bit weirder:

error[E0432]: unresolved import `self::rand`
 --> src\main.rs:3:15
  |
3 |     use self::rand::Rng;
  |               ^^^^ maybe a missing `extern crate rand;`?

warning: unused import: `self::rand::Rng`
 --> src\main.rs:3:9
  |
3 |     use self::rand::Rng;
  |         ^^^^^^^^^^^^^^^
  |
  = note: #[warn(unused_imports)] on by default

It seems like the import both works and doesn't work, simultaneously?

Given that extern crate is no longer needed in the 2018 edition, I doubt people are going to run into this bug.

@Mark-Simulacrum
Copy link
Member

I'm going to go ahead and close this; the error today in a project that just has rand in Cargo.toml seems mostly acceptable for this niche case, if the extern crate is moved to root scope then things just work, as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Path resolution C-enhancement Category: An issue proposing an enhancement or a PR with one.
Projects
None yet
Development

No branches or pull requests

5 participants