Skip to content

Use a proper error for unnecessary priv usage in struct fields. #13931

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

Closed
flaper87 opened this issue May 4, 2014 · 4 comments
Closed

Use a proper error for unnecessary priv usage in struct fields. #13931

flaper87 opened this issue May 4, 2014 · 4 comments
Labels
A-parser Area: The lexing & parsing of Rust source code to an AST A-visibility Area: Visibility / privacy E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.

Comments

@flaper87
Copy link
Contributor

flaper87 commented May 4, 2014

This code throws a reserved keyword error instead of warning about the unnecessary visibility.

struct Test {
   priv a: int
}

fn main(){}
test.rs:2:4: 2:8 error: `priv` is a reserved keyword
test.rs:2    priv a: int
             ^~~~

I think we should handle this case and print a proper error message.

@huonw
Copy link
Member

huonw commented May 4, 2014

priv is no longer a visibility at all, i.e. writing this is similar to writing struct Test { do a: int } as far as the compiler can tell. (It's now just a historical thing that priv ever meant anything.)

However, it seems like an ok idea to explicitly check for the priv reserved word for a little while (just to help people upgrade their code).

@aochagavia
Copy link
Contributor

I would like to do this, but I really don't know where to begin... I don't know anything about the parser, but I know that it is possible to make lints. Would that be useful for this case? Can anybody mentor?

@nrc
Copy link
Member

nrc commented May 5, 2014

@aochagavia I think there is nothing to do here since it is not a bug, sorry. If you find another similar bug you would like to have a go at, please ping me and I can mentor you (or maybe recommend someone else if its outside my area).

@nrc nrc closed this as completed May 5, 2014
@flaper87
Copy link
Contributor Author

flaper87 commented May 5, 2014

FWIW, I think it's worth providing a better error in this case since things like struct Test { pub t: int } are allowed. I know pirv is gone but still a nicer upgrade path for users would be nice. Not big deal, I guess.

flip1995 pushed a commit to flip1995/rust that referenced this issue Apr 3, 2025
Closes rust-lang#13066 (tests that are ignored with no reason message).

changelog: Add `ignore_without_reason` lint
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-parser Area: The lexing & parsing of Rust source code to an AST A-visibility Area: Visibility / privacy E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue.
Projects
None yet
Development

No branches or pull requests

4 participants