Skip to content

Commit

Permalink
update unused_braces wording
Browse files Browse the repository at this point in the history
  • Loading branch information
lcnr committed Mar 31, 2020
1 parent bcf35b1 commit bab327c
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 21 deletions.
23 changes: 11 additions & 12 deletions src/librustc_lint/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,11 +327,11 @@ enum UnusedDelimsCtx {
AssignedValue,
IfCond,
WhileCond,
ForHeadExpr,
MatchHeadExpr,
ForIterExpr,
MatchScrutineeExpr,
ReturnValue,
BlockRetValue,
LetHeadExpr,
LetScrutineeExpr,
ArrayLenExpr,
AnonConst,
}
Expand All @@ -344,11 +344,11 @@ impl From<UnusedDelimsCtx> for &'static str {
UnusedDelimsCtx::AssignedValue => "assigned value",
UnusedDelimsCtx::IfCond => "`if` condition",
UnusedDelimsCtx::WhileCond => "`while` condition",
UnusedDelimsCtx::ForHeadExpr => "`for` head expression",
UnusedDelimsCtx::MatchHeadExpr => "`match` head expression",
UnusedDelimsCtx::ForIterExpr => "`for` iterator expression",
UnusedDelimsCtx::MatchScrutineeExpr => "`match` scrutinee expression",
UnusedDelimsCtx::ReturnValue => "`return` value",
UnusedDelimsCtx::BlockRetValue => "block return value",
UnusedDelimsCtx::LetHeadExpr => "`let` head expression",
UnusedDelimsCtx::LetScrutineeExpr => "`let` scrutinee expression",
UnusedDelimsCtx::ArrayLenExpr | UnusedDelimsCtx::AnonConst => "const expression",
}
}
Expand Down Expand Up @@ -399,7 +399,6 @@ trait UnusedDelimLint {
self.emit_unused_delims(cx, value.span, &expr_text, ctx.into(), keep_space);
}

/// emits a lint
fn emit_unused_delims(
&self,
cx: &EarlyContext<'_>,
Expand Down Expand Up @@ -471,12 +470,12 @@ trait UnusedDelimLint {
}

ForLoop(_, ref cond, ref block, ..) => {
(cond, UnusedDelimsCtx::ForHeadExpr, true, None, Some(block.span.lo()))
(cond, UnusedDelimsCtx::ForIterExpr, true, None, Some(block.span.lo()))
}

Match(ref head, _) => {
let left = e.span.lo() + rustc_span::BytePos(5);
(head, UnusedDelimsCtx::MatchHeadExpr, true, Some(left), None)
(head, UnusedDelimsCtx::MatchScrutineeExpr, true, Some(left), None)
}

Ret(Some(ref value)) => {
Expand Down Expand Up @@ -597,7 +596,7 @@ impl UnusedDelimLint for UnusedParens {
self.check_unused_delims_expr(
cx,
expr,
UnusedDelimsCtx::LetHeadExpr,
UnusedDelimsCtx::LetScrutineeExpr,
followed_by_block,
None,
None,
Expand Down Expand Up @@ -732,7 +731,7 @@ impl EarlyLintPass for UnusedParens {
declare_lint! {
pub(super) UNUSED_BRACES,
Warn,
"suggests removing `{` and `}` in case they are not necessary"
"unnecessary braces around an expression"
}

declare_lint_pass!(UnusedBraces => [UNUSED_BRACES]);
Expand Down Expand Up @@ -804,7 +803,7 @@ impl UnusedDelimLint for UnusedBraces {
self.check_unused_delims_expr(
cx,
expr,
UnusedDelimsCtx::LetHeadExpr,
UnusedDelimsCtx::LetScrutineeExpr,
followed_by_block,
None,
None,
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/lint/lint-unnecessary-parens.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,11 @@ fn main() {
if (true) {} //~ ERROR unnecessary parentheses around `if` condition
while (true) {} //~ ERROR unnecessary parentheses around `while` condition
//~^ WARN denote infinite loops with
match (true) { //~ ERROR unnecessary parentheses around `match` head expression
match (true) { //~ ERROR unnecessary parentheses around `match` scrutinee expression
_ => {}
}
if let 1 = (1) {} //~ ERROR unnecessary parentheses around `let` head expression
while let 1 = (2) {} //~ ERROR unnecessary parentheses around `let` head expression
if let 1 = (1) {} //~ ERROR unnecessary parentheses around `let` scrutinee expression
while let 1 = (2) {} //~ ERROR unnecessary parentheses around `let` scrutinee expression
let v = X { y: false };
// struct lits needs parens, so these shouldn't warn.
if (v == X { y: true }) {}
Expand Down
6 changes: 3 additions & 3 deletions src/test/ui/lint/lint-unnecessary-parens.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -72,19 +72,19 @@ LL | while (true) {}
|
= note: `#[warn(while_true)]` on by default

error: unnecessary parentheses around `match` head expression
error: unnecessary parentheses around `match` scrutinee expression
--> $DIR/lint-unnecessary-parens.rs:51:11
|
LL | match (true) {
| ^^^^^^ help: remove these parentheses

error: unnecessary parentheses around `let` head expression
error: unnecessary parentheses around `let` scrutinee expression
--> $DIR/lint-unnecessary-parens.rs:54:16
|
LL | if let 1 = (1) {}
| ^^^ help: remove these parentheses

error: unnecessary parentheses around `let` head expression
error: unnecessary parentheses around `let` scrutinee expression
--> $DIR/lint-unnecessary-parens.rs:55:19
|
LL | while let 1 = (2) {}
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/lint/unused_braces.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ note: the lint level is defined here
LL | #![warn(unused_braces, unused_parens)]
| ^^^^^^^^^^^^^

warning: unnecessary braces around `let` head expression
warning: unnecessary braces around `let` scrutinee expression
--> $DIR/unused_braces.rs:11:16
|
LL | if let 7 = { 7 } {
Expand Down
4 changes: 2 additions & 2 deletions src/test/ui/lint/unused_parens_remove_json_suggestion.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ LL | while(true && false) {
| ^^^^^^^^^^^^^^^ help: remove these parentheses

"}
{"message":"unnecessary parentheses around `for` head expression","code":{"code":"unused_parens","explanation":null},"level":"error","spans":[{"file_name":"$DIR/unused_parens_remove_json_suggestion.rs","byte_start":987,"byte_end":995,"line_start":44,"line_end":44,"column_start":18,"column_end":26,"is_primary":true,"text":[{"text":" for _ in (0 .. 3){
{"message":"unnecessary parentheses around `for` iterator expression","code":{"code":"unused_parens","explanation":null},"level":"error","spans":[{"file_name":"$DIR/unused_parens_remove_json_suggestion.rs","byte_start":987,"byte_end":995,"line_start":44,"line_end":44,"column_start":18,"column_end":26,"is_primary":true,"text":[{"text":" for _ in (0 .. 3){
--> $DIR/unused_parens_remove_json_suggestion.rs:44:18
|
LL | for _ in (0 .. 3){
| ^^^^^^^^ help: remove these parentheses

"}
{"message":"unnecessary parentheses around `for` head expression","code":{"code":"unused_parens","explanation":null},"level":"error","spans":[{"file_name":"$DIR/unused_parens_remove_json_suggestion.rs","byte_start":1088,"byte_end":1096,"line_start":49,"line_end":49,"column_start":14,"column_end":22,"is_primary":true,"text":[{"text":" for _ in (0 .. 3) {
{"message":"unnecessary parentheses around `for` iterator expression","code":{"code":"unused_parens","explanation":null},"level":"error","spans":[{"file_name":"$DIR/unused_parens_remove_json_suggestion.rs","byte_start":1088,"byte_end":1096,"line_start":49,"line_end":49,"column_start":14,"column_end":22,"is_primary":true,"text":[{"text":" for _ in (0 .. 3) {
--> $DIR/unused_parens_remove_json_suggestion.rs:49:14
|
LL | for _ in (0 .. 3) {
Expand Down

0 comments on commit bab327c

Please sign in to comment.