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

RFC: Forbid pub and priv in positions where they do not change the default behavior #5495

Closed
bstrie opened this issue Mar 22, 2013 · 11 comments
Assignees
Labels
A-frontend Area: Compiler frontend (errors, parsing and HIR) A-grammar Area: The grammar of Rust A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.

Comments

@bstrie
Copy link
Contributor

bstrie commented Mar 22, 2013

Right now structs are private-by-default and struct fields are public-by-default. And yet this is legal:

priv struct Foo {
    pub bar: int
}

fn main() {}

The pub and priv declarations there are meaningless. Allowing them in those positions will increase confusion over what the defaults actually are. I propose that this be forbidden.

@thestinger
Copy link
Contributor

I think this would make the rules much easier to understand, so definitely a +1 from me. It's just a removal of redundancy from the valid syntax and could even be considered a lint error/warning if backwards compatibility is a concern.

@ghost ghost assigned pcwalton Mar 25, 2013
@AndresOsinski
Copy link

I've hit this while trying out some code with multiple nested modules and it would be great to have this implemented.

@catamorphism
Copy link
Contributor

Nominating for milestone 2, backwards-compatible

@pnkfelix
Copy link
Member

As long as its a lint I can toggle, sounds fine to me.

@bstrie
Copy link
Contributor Author

bstrie commented Jul 16, 2013

@pnkfelix I don't think the plan is to make it a lint, rather to modify the grammar directly. IMO allowing the qualifiers in those positions is unwarranted.

@graydon
Copy link
Contributor

graydon commented Aug 8, 2013

inside #8385

@graydon
Copy link
Contributor

graydon commented Aug 8, 2013

close when landed.

@alexcrichton
Copy link
Member

Closed by e99eff1

@bstrie bstrie reopened this Aug 9, 2013
@bstrie
Copy link
Contributor Author

bstrie commented Aug 9, 2013

Reopening because I'm not certain that pub is now forbidden in all the proper places.

@bstrie
Copy link
Contributor Author

bstrie commented Aug 9, 2013

Test cases might also make sense here, to help us ensure that we have the rules properly implemented.

@alexcrichton
Copy link
Member

Here's the specific cases that I can think of which need to be fixed:

struct A { pub i: int } // public field in private struct is useless
struct A { priv i: int } // priv should not be allowed on struct fields at all
pub enum A { pub Variant } // variant is already public
enum A { priv Variant } // variant is already private

pub trait A { pub fn foo(); } // function is already public
trait A { pub fn foo(); } // no effect

These should all be verified with a test case if they're already disallowed because I don't think this exists in the test suite. There may be others as well.

alexcrichton added a commit to alexcrichton/rust that referenced this issue Aug 10, 2013
oli-obk pushed a commit to oli-obk/rust that referenced this issue May 2, 2020
Update the changelog update documentation

I just started working on updating the changelog. Hopefully the docs are a bit clearer now?

r? @flip1995

changelog: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-frontend Area: Compiler frontend (errors, parsing and HIR) A-grammar Area: The grammar of Rust A-lints Area: Lints (warnings about flaws in source code) such as unused_mut. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants