Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upResolve: stop requiring `use` and `extern crate` declarations to precede statements in blocks #31144
Conversation
rust-highfive
assigned
alexcrichton
Jan 23, 2016
This comment has been minimized.
This comment has been minimized.
|
(rust_highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
|
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? |
This comment has been minimized.
This comment has been minimized.
|
@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. |
This comment has been minimized.
This comment has been minimized.
|
r? @nrc |
rust-highfive
assigned
nrc
and unassigned
alexcrichton
Jan 24, 2016
This comment has been minimized.
This comment has been minimized.
|
I feel like this would allow something like fn foo() {}
fn bar() {
foo();
use qux::foo;
foo();
}which would presumably be calling |
This comment has been minimized.
This comment has been minimized.
|
@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. |
This comment has been minimized.
This comment has been minimized.
|
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. |
This comment has been minimized.
This comment has been minimized.
|
+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. |
This comment has been minimized.
This comment has been minimized.
|
clippy now has an |
nrc
added
I-nominated
T-lang
and removed
I-nominated
labels
Jan 25, 2016
This comment has been minimized.
This comment has been minimized.
|
@bors: r+ |
This comment has been minimized.
This comment has been minimized.
|
|
jseyfried commentedJan 23, 2016
We no longer require
useandextern crateitems to precede other items in modules thanks to RFC #385, but we still requireuseandextern crateitems 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.