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 upConsider turning "visibility has no effect inside functions" into a lint #31776
Comments
This comment has been minimized.
This comment has been minimized.
|
Yeah, this restriction is pretty artificial, it isn't required for anything else. |
sfackler
added
A-lint
A-diagnostics
labels
Feb 19, 2016
This comment has been minimized.
This comment has been minimized.
|
I'm not sure a RFC is needed a small that little. cc @pnkfelix |
This comment has been minimized.
This comment has been minimized.
Moreover, the "visibility has no effect inside functions or block expressions" statement is not correct, Example 1: Rustdoc. Rustdoc wraps code snippets in Example 2: Inherent methods.
Example 3: Pulling a function local type out of function through a public impl
Example 4: Field of a function local type
Example 5: Any other private-in-public scenario in function local modules
|
This comment has been minimized.
This comment has been minimized.
|
I agree, that the examples above are contrived, but they are still possible. |
pnkfelix
added
the
T-lang
label
Feb 23, 2016
This comment has been minimized.
This comment has been minimized.
|
triage: I-nominated (I suspect this is a P-medium issue.) I suspect we can do this without an RFC (though I could imagine some of the details about interaction with private-in-public checking may lead to unanticipated results that could justify one...) |
rust-highfive
added
the
I-nominated
label
Feb 23, 2016
This comment has been minimized.
This comment has been minimized.
|
This example makes me think that a lint would be wrong: pub trait Tr {
type A;
}
pub struct S;
fn f() {
struct Z;
impl ::Tr for ::S {
type A = Z; // Private-in-public error unless `struct Z` is pub
}
}
fn main() {}After all, in this case you have to use |
This comment has been minimized.
This comment has been minimized.
|
Discussed in @rust-lang/lang meeting and conclusion was that we should just drop this restriction and not replace it with a lint, due to aforementioned examples. triage: P-medium |
sgrif commentedFeb 19, 2016
The current code results in a hard error:
This can be painful when writing macros that generate structs or inherent methods, which would otherwise need to be public (particularly when writing tests for those macros). This doesn't seem like something which should need to be an error, and could instead be a lint (which is
denyby default). I'm unsure if this would need a full RFC or not, and was told that it'd be best to open an issue to start.