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

name resolution and warnings inconsistent #5564

Closed
metajack opened this issue Mar 26, 2013 · 2 comments
Closed

name resolution and warnings inconsistent #5564

metajack opened this issue Mar 26, 2013 · 2 comments

Comments

@metajack
Copy link
Contributor

When using use foo::{FooTypeA, FooTypeB}; and use foo; together, the compiler complains that use foo; is an unused import even when a call to something like foo::hello() exists. Removing use foo; gets rid of the warning and the crate compiles. However, the crate will fail to link (for example with --test) unless the use foo; is there.

It seems like the warning is a bug unless the intent is to have use foo::{FooTypeA, FooTypeB}; also bring in foo itself.

Here's a small crate that shows the example. This was originally found in rust-core-foundation.

https://gist.github.com/metajack/5249056

@alexcrichton
Copy link
Member

Looking at the code, that's a genuinely unused import when not compiling with --test.

I ran into this when removing unused imports in the compiler, and you can prefix the import with #[cfg(test)] so that the import is only resolved when testing. Other options I've seen are to have a mod test which is cfg'd off, or just put the use in the function itself.

@metajack
Copy link
Contributor Author

You're right. In this case I moved the use foo; inside the test function.

flip1995 pushed a commit to flip1995/rust that referenced this issue May 11, 2020
Allow `use super::*;` glob imports

changelog: Allow super::* glob imports

fixes rust-lang#5554
fixes rust-lang#5569

A first pass at rust-lang#5554 - this allows all `use super::*` to pass, which may or may not be desirable. The original issue was around allowing test modules to import their entire parent modules - I'm happy to modify this to do that instead, may just need some guidance on how to implement that (I played around a bit with #[cfg(test)] but from what I can gather, clippy itself isn't in test mode when running, even if the code in question is being checked for the test target).
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