-
Notifications
You must be signed in to change notification settings - Fork 1.7k
use statements anywhere but top of module #259
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
Comments
Meh, this is actually a pattern I've seen used often and it's okay IMO (esp. for test imports).
|
I feel that at least function-local should be allowed if at the top of the function. |
We probably should ignore I'm fine with And again, we can have multiple lints ranging from pedantic to lenient. |
Turns out |
Yeah, but there can be a lot of blocks within a function... |
@llogiq: what is the undesirable effect of a Is it possible to elaborate a bit why this is bad? Doing it could enhance self-containedness of functions. Not to say I don't empathize with your apprehension ... |
We'll focus on "module-level use statements should not come after other items" |
Hey, I wanted to work on this as a first issue, if this is still wanted and no one else is working on it; I'd be glad to. Please let me know the current status of this issue. |
Sure, feel free to claim the issue (see the CONTRIBUTING.md file) if you want to work on it! |
@rustbot claim |
running As i can notice the test run emits diagnostic labels like I apologize if this was a dumb question but it has really been bugging me. Any guidance will be much appreciated. Output:
|
I think this is a solution without a problem. @llogiq: what is the undesirable effect of a use inside e.g. a loop block? Is it possible to elaborate a bit why this is bad? Doing it could enhance self-containedness of functions. Not to say I don't empathize with your apprehension ... |
If imports come after their usage, that would be unintuitive. I believe that is only possible with module-level imports. |
Could the |
If this issue/lint is no longer required or seems a redundant add, I'm happy to drop this issue. But if not, any help as to why my test was doing that would be appreciated. Any maintainer reading this issue can pass the final verdict, Thanks again. |
As for your error, try adding proper error markers to the lines where you expect your lint to emit. So for example on line 6 (based on your stderr output), write That said, IMHO it does sound like the lint |
Thanks for the help @y21, The tests all passed and I've declared two lints, one pedantic that is opt-in and stricter which will ask for use statements to be at the absolute top while the other is a style which will ignore mod and extern crates as you mentioned.
I still struggled to figure out a solution for the cfg blocks as the author of this issue asked. I've tried multiple methods under
All other tests passed and behaved as expected. |
I'm aware.. The lint should be "module level use statements should precede all other items". The error says "all items" because it's still WIP, My apologies for that. I used ItemKind enum to do the basic work match item.kind {
ItemKind::Use(..) => {
if saw_non_use {
span_lint_and_note(
cx,
ITEMS_BEFORE_USE,
item.span,
"module level use statements should precede all other items",
None,
"consider moving this statement to the top of the module.",
);
}
},
_ => saw_non_use = true,
} |
Uh oh!
There was an error while loading. Please reload this page.
In an earlier version of sokoban-rs, the author included a
use
statement in the middle of a loop.Let's catch such stuff and propose putting it at the top of the file.
The text was updated successfully, but these errors were encountered: