-
Notifications
You must be signed in to change notification settings - Fork 13.3k
code suggestions for unused-mut, while-true, deprecated-attribute, and unused-parens lints #44942
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
d663003
fix comment typo, `CodeSuggestion` path in doc comment
zackmdavis f2c5acd
code suggestion for deprecated-attribute lint
zackmdavis 5c9f806
code suggestion for unused-parentheses lint
zackmdavis e3b4989
code suggestions for unused-mut, while-true lints; UI test
zackmdavis 8a14022
correct unused-parens lint suggestion to strip exact pair
zackmdavis File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
#![warn(unused_mut)] // UI tests pass `-A unused`—see Issue #43896 | ||
#![feature(no_debug)] | ||
|
||
#[no_debug] // should suggest removal of deprecated attribute | ||
fn main() { | ||
while true { // should suggest `loop` | ||
let mut a = (1); // should suggest no `mut`, no parens | ||
println!("{}", a); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
warning: unnecessary parentheses around assigned value | ||
--> $DIR/suggestions.rs:17:21 | ||
| | ||
17 | let mut a = (1); // should suggest no `mut`, no parens | ||
| ^^^ help: remove these parentheses | ||
| | ||
= note: #[warn(unused_parens)] on by default | ||
|
||
warning: use of deprecated attribute `no_debug`: the `#[no_debug]` attribute was an experimental feature that has been deprecated due to lack of demand. See https://github.com/rust-lang/rust/issues/29721 | ||
--> $DIR/suggestions.rs:14:1 | ||
| | ||
14 | #[no_debug] // should suggest removal of deprecated attribute | ||
| ^^^^^^^^^^^ help: remove this attribute | ||
| | ||
= note: #[warn(deprecated)] on by default | ||
|
||
warning: denote infinite loops with `loop { ... }` | ||
--> $DIR/suggestions.rs:16:5 | ||
| | ||
16 | while true { // should suggest `loop` | ||
| ^--------- | ||
| | | ||
| _____help: use `loop` | ||
| | | ||
17 | | let mut a = (1); // should suggest no `mut`, no parens | ||
18 | | println!("{}", a); | ||
19 | | } | ||
| |_____^ | ||
| | ||
= note: #[warn(while_true)] on by default | ||
|
||
warning: variable does not need to be mutable | ||
--> $DIR/suggestions.rs:17:13 | ||
| | ||
17 | let mut a = (1); // should suggest no `mut`, no parens | ||
| ---^^ | ||
| | | ||
| help: remove this `mut` | ||
| | ||
note: lint level defined here | ||
--> $DIR/suggestions.rs:11:9 | ||
| | ||
11 | #![warn(unused_mut)] // UI tests pass `-A unused`—see Issue #43896 | ||
| ^^^^^^^^^^ | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// Copyright 2017 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
// compile-flags: --error-format json | ||
|
||
// ignore-windows (see Issue #44968) | ||
|
||
// The output for humans should just highlight the whole span without showing | ||
// the suggested replacement, but we also want to test that suggested | ||
// replacement only removes one set of parentheses, rather than naïvely | ||
// stripping away any starting or ending parenthesis characters—hence this | ||
// test of the JSON error format. | ||
|
||
fn main() { | ||
// We want to suggest the properly-balanced expression `1 / (2 + 3)`, not | ||
// the malformed `1 / (2 + 3` | ||
let _a = (1 / (2 + 3)); | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"message":"unnecessary parentheses around assigned value","code":null,"level":"warning","spans":[{"file_name":"$DIR/unused_parens_json_suggestion.rs","byte_start":1014,"byte_end":1027,"line_start":24,"line_end":24,"column_start":14,"column_end":27,"is_primary":true,"text":[{"text":" let _a = (1 / (2 + 3));","highlight_start":14,"highlight_end":27}],"label":null,"suggested_replacement":null,"expansion":null}],"children":[{"message":"#[warn(unused_parens)] on by default","code":null,"level":"note","spans":[],"children":[],"rendered":null},{"message":"remove these parentheses","code":null,"level":"help","spans":[{"file_name":"$DIR/unused_parens_json_suggestion.rs","byte_start":1014,"byte_end":1027,"line_start":24,"line_end":24,"column_start":14,"column_end":27,"is_primary":true,"text":[{"text":" let _a = (1 / (2 + 3));","highlight_start":14,"highlight_end":27}],"label":null,"suggested_replacement":"1 / (2 + 3)","expansion":null}],"children":[],"rendered":" let _a = 1 / (2 + 3);"}],"rendered":null} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
@nikomatsakis do we care about unicode in rustc comments?