-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Resolve: stop requiring use
and extern crate
declarations to precede statements in blocks
#31144
Resolve: stop requiring use
and extern crate
declarations to precede statements in blocks
#31144
Conversation
(rust_highfive has picked a reviewer for you, use r? to override) |
I personally think that lifting the restriction in question could only result in worse code. Perhaps we should downgrade it to a warning-by-default lint? |
@nagisa If so, I think this example (for modules, also applies to enums) and this example (for structs) from the RFC motivate allowing If not, I think we should not permit any item to follow a statement (or at least make it a warning/lint). I would be OK with this, but I don't see any reason to only permit a certain class of item like we are doing now. |
r? @nrc cc @rust-lang/lang |
I feel like this would allow something like fn foo() {}
fn bar() {
foo();
use qux::foo;
foo();
} which would presumably be calling |
@huonw I agree that your example is problematic, but we currently allow fn foo() {}
fn bar() {
foo(); // Prints "foo!"
fn foo() { println!("foo!"); }
foo(); // Prints "foo!"
} which I think is problematic for exactly the same reason. |
I don't think something confusing existing already is a good justification for adding more confusing things. :) Don't get me wrong though: uniformity is a good reason. |
+1 to this PR, item scoping in blocks may already be surprising and needs to be explained well, and random exceptions don't make things easier to explain. |
clippy now has an |
@bors: r+ |
📌 Commit f05bc16 has been approved by |
…r=nrc We no longer require `use` and `extern crate` items to precede other items in modules thanks to [RFC #385](rust-lang/rfcs#385), but we still require `use` and `extern crate` items to precede statements in blocks (other items can appear anywhere in a block). I think that this is a needless distinction between imports and other items that contradicts the intent of the RFC.
We no longer require
use
andextern crate
items to precede other items in modules thanks to RFC #385, but we still requireuse
andextern crate
items to precede statements in blocks (other items can appear anywhere in a block).I think that this is a needless distinction between imports and other items that contradicts the intent of the RFC.