-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Add lint and tests for unnecessary parens around types #65112
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @zackmdavis (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
@jack-t Thanks! You can edit libcore/ and libstd/ as part of this PR. (It should be fine to remove those parens in |
(And, of course, if you find any cases that aren't fine to remove; that would be a bug in your lint change; I'll do my own audit of the |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Ping from triage |
Thanks for following up on this, @JohnCSimon -- I had a few papers to write this week, which really bogged me down. I'm hoping the commit I just added to this PR will get the lint right. The last version incorrectly warned that the parentheses in, e.g., I've gone through all the variants in Separately, I found that this syntax is pretty much undocumented:
|
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
r? @varkor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, this looks good! Just a few stylistic comments, and then it's good to go! Also, if you could squash the tidy commit into one of the others, that would help keep the commit history cleaner.
src/librustc_lint/unused.rs
Outdated
fn check_ty(&mut self, cx: &EarlyContext<'_>, ty: &ast::Ty) { | ||
if let &ast::TyKind::Paren(ref r) = &ty.kind { | ||
match &r.kind { | ||
&ast::TyKind::TraitObject(..) => {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
&ast::TyKind::TraitObject(..) => {}, | |
&ast::TyKind::TraitObject(..) => {} |
src/librustc_lint/unused.rs
Outdated
if let &ast::TyKind::Paren(ref r) = &ty.kind { | ||
match &r.kind { | ||
&ast::TyKind::TraitObject(..) => {}, | ||
&ast::TyKind::ImplTrait(_, ref bounds) if bounds.len() > 1 => {}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
&ast::TyKind::ImplTrait(_, ref bounds) if bounds.len() > 1 => {}, | |
&ast::TyKind::ImplTrait(_, ref bounds) if bounds.len() > 1 => {} |
src/librustc_lint/unused.rs
Outdated
}; | ||
|
||
Self::remove_outer_parens(cx, ty.span, &pattern_text, "type", (false, false)); | ||
}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
}, | |
} |
283f591
to
08ca236
Compare
Thanks, @varkor! The last commit in this PR is a squashed version of the previous commits, plus changes to address the changes you suggested above. Let me know if there's anything else I need to do! Jack |
📌 Commit 08ca236 has been approved by |
Add lint and tests for unnecessary parens around types This is my first contribution to the Rust project, so I apologize if I'm not doing things the right way. The PR fixes rust-lang#64169. It adds a lint and tests for unnecessary parentheses around types. I've run `tidy` and `rustfmt` — I'm not totally sure it worked right, though — and I've tried to follow the instructions linked in the readme. I tried to think through all the variants of `ast::TyKind` to find exceptions to this lint, and I could only find the one mentioned in the original issue, which concerns types with `dyn`. I'm not a Rust expert, thought, so I may well be missing something. There's also a problem with getting this to build. The new lint catches several things in the, e.g., `core`. Because `x.py` seems to build with an equivalent of `-Werror`, what would have been warnings cause the build to break. I got it to build and the tests to pass with `--warnings warn` on my `x.py build` and `x.py test` commands.
Add lint and tests for unnecessary parens around types This is my first contribution to the Rust project, so I apologize if I'm not doing things the right way. The PR fixes rust-lang#64169. It adds a lint and tests for unnecessary parentheses around types. I've run `tidy` and `rustfmt` — I'm not totally sure it worked right, though — and I've tried to follow the instructions linked in the readme. I tried to think through all the variants of `ast::TyKind` to find exceptions to this lint, and I could only find the one mentioned in the original issue, which concerns types with `dyn`. I'm not a Rust expert, thought, so I may well be missing something. There's also a problem with getting this to build. The new lint catches several things in the, e.g., `core`. Because `x.py` seems to build with an equivalent of `-Werror`, what would have been warnings cause the build to break. I got it to build and the tests to pass with `--warnings warn` on my `x.py build` and `x.py test` commands.
Add lint and tests for unnecessary parens around types This is my first contribution to the Rust project, so I apologize if I'm not doing things the right way. The PR fixes rust-lang#64169. It adds a lint and tests for unnecessary parentheses around types. I've run `tidy` and `rustfmt` — I'm not totally sure it worked right, though — and I've tried to follow the instructions linked in the readme. I tried to think through all the variants of `ast::TyKind` to find exceptions to this lint, and I could only find the one mentioned in the original issue, which concerns types with `dyn`. I'm not a Rust expert, thought, so I may well be missing something. There's also a problem with getting this to build. The new lint catches several things in the, e.g., `core`. Because `x.py` seems to build with an equivalent of `-Werror`, what would have been warnings cause the build to break. I got it to build and the tests to pass with `--warnings warn` on my `x.py build` and `x.py test` commands.
Rollup of 14 pull requests Successful merges: - #65112 (Add lint and tests for unnecessary parens around types) - #65459 (Fix `-Zunpretty=mir-cfg` to render multiple items) - #65471 (Add long error explanation for E0578) - #65857 (rustdoc: Resolve module-level doc references more locally) - #65914 (Use structured suggestion for unnecessary bounds in type aliases) - #65945 (Optimize long-linker-command-line test) - #65946 (Make `promote_consts` emit the errors when required promotion fails) - #65960 (doc: reword iter module example and mention other methods) - #65963 (update submodules to rust-lang) - #65972 (Fix libunwind build: Define __LITTLE_ENDIAN__ for LE targets) - #65977 (Fix incorrect diagnostics for expected type in E0271 with an associated type) - #65995 (Add error code E0743 for "C-variadic has been used on a non-foreign function") - #65997 (Fix outdated rustdoc of Once::init_locking function) - #66005 (vxWorks: remove code related unix socket) Failed merges: r? @ghost
Add lint and tests for unnecessary parens around types This is my first contribution to the Rust project, so I apologize if I'm not doing things the right way. The PR fixes rust-lang#64169. It adds a lint and tests for unnecessary parentheses around types. I've run `tidy` and `rustfmt` — I'm not totally sure it worked right, though — and I've tried to follow the instructions linked in the readme. I tried to think through all the variants of `ast::TyKind` to find exceptions to this lint, and I could only find the one mentioned in the original issue, which concerns types with `dyn`. I'm not a Rust expert, thought, so I may well be missing something. There's also a problem with getting this to build. The new lint catches several things in the, e.g., `core`. Because `x.py` seems to build with an equivalent of `-Werror`, what would have been warnings cause the build to break. I got it to build and the tests to pass with `--warnings warn` on my `x.py build` and `x.py test` commands.
Rollup of 16 pull requests Successful merges: - #65112 (Add lint and tests for unnecessary parens around types) - #65470 (Don't hide ICEs from previous incremental compiles) - #65471 (Add long error explanation for E0578) - #65857 (rustdoc: Resolve module-level doc references more locally) - #65902 (Make ItemContext available for better diagnositcs) - #65914 (Use structured suggestion for unnecessary bounds in type aliases) - #65946 (Make `promote_consts` emit the errors when required promotion fails) - #65960 (doc: reword iter module example and mention other methods) - #65963 (update submodules to rust-lang) - #65972 (Fix libunwind build: Define __LITTLE_ENDIAN__ for LE targets) - #65977 (Fix incorrect diagnostics for expected type in E0271 with an associated type) - #65995 (Add error code E0743 for "C-variadic has been used on a non-foreign function") - #65997 (Fix outdated rustdoc of Once::init_locking function) - #66002 (Stabilize float_to_from_bytes feature) - #66005 (vxWorks: remove code related unix socket) - #66018 (Revert PR 64324: dylibs export generics again (for now)) Failed merges: r? @ghost
This is my first contribution to the Rust project, so I apologize if I'm not doing things the right way.
The PR fixes #64169. It adds a lint and tests for unnecessary parentheses around types. I've run
tidy
andrustfmt
— I'm not totally sure it worked right, though — and I've tried to follow the instructions linked in the readme.I tried to think through all the variants of
ast::TyKind
to find exceptions to this lint, and I could only find the one mentioned in the original issue, which concerns types withdyn
. I'm not a Rust expert, thought, so I may well be missing something.There's also a problem with getting this to build. The new lint catches several things in the, e.g.,
core
. Becausex.py
seems to build with an equivalent of-Werror
, what would have been warnings cause the build to break. I got it to build and the tests to pass with--warnings warn
on myx.py build
andx.py test
commands.