Skip to content

Commit 8e0d8b6

Browse files
committed
Prefer language operator instead of the English terminology
1 parent 12d2124 commit 8e0d8b6

File tree

6 files changed

+35
-32
lines changed

6 files changed

+35
-32
lines changed

compiler/rustc_lint/messages.ftl

+1-1
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ lint_path_statement_drop = path statement drops value
455455
456456
lint_path_statement_no_effect = path statement with no effect
457457
458-
lint_precedence_unary = unary minus has lower precedence than method call
458+
lint_precedence_unary = unary operator `{$op}` has lower precedence than method call
459459
.suggestion = consider adding parentheses to clarify your intent
460460
461461
lint_precedence_unwary = operator precedence can trip the unwary

compiler/rustc_lint/src/lints.rs

+1
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,7 @@ pub struct ExpectationNote {
622622
pub enum PrecedenceDiag {
623623
#[diag(lint_precedence_unary)]
624624
Unary {
625+
op: &'static str,
625626
#[subdiagnostic]
626627
suggestion: PrecedenceUnarySuggestion,
627628
},

compiler/rustc_lint/src/precedence.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,8 @@ impl EarlyLintPass for Precedence {
6767
);
6868
}
6969

70-
if let ExprKind::Unary(UnOp::Neg, operand) = &expr.kind
70+
if let ExprKind::Unary(unop, operand) = &expr.kind
71+
&& matches!(unop, UnOp::Neg)
7172
&& let ExprKind::MethodCall(..) = operand.kind
7273
{
7374
let mut arg = operand;
@@ -80,6 +81,7 @@ impl EarlyLintPass for Precedence {
8081
&& !arg.span.from_expansion()
8182
{
8283
cx.emit_spanned_lint(AMBIGUOUS_PRECEDENCE, expr.span, PrecedenceDiag::Unary {
84+
op: UnOp::to_string(*unop),
8385
suggestion: PrecedenceUnarySuggestion {
8486
start_span: operand.span.shrink_to_lo(),
8587
end_span: operand.span.shrink_to_hi(),

tests/ui/lint/precedence.fixed

+10-10
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,25 @@ fn main() {
1919
let _ = (1 + 2) << (3 + 1);
2020
//~^ WARN operator precedence can trip the unwary
2121
let _ = -(1i32.abs());
22-
//~^ WARN unary minus has lower precedence than method call
22+
//~^ WARN unary operator `-` has lower precedence than method call
2323
let _ = -(1f32.abs());
24-
//~^ WARN unary minus has lower precedence than method call
24+
//~^ WARN unary operator `-` has lower precedence than method call
2525
let _ = -(1f64.asin());
26-
//~^ WARN unary minus has lower precedence than method call
26+
//~^ WARN unary operator `-` has lower precedence than method call
2727
let _ = -(1f64.asinh());
28-
//~^ WARN unary minus has lower precedence than method call
28+
//~^ WARN unary operator `-` has lower precedence than method call
2929
let _ = -(1f64.tan());
30-
//~^ WARN unary minus has lower precedence than method call
30+
//~^ WARN unary operator `-` has lower precedence than method call
3131
let _ = -(1f64.tanh());
32-
//~^ WARN unary minus has lower precedence than method call
32+
//~^ WARN unary operator `-` has lower precedence than method call
3333
let _ = -(1.0_f64.cos().cos());
34-
//~^ WARN unary minus has lower precedence than method call
34+
//~^ WARN unary operator `-` has lower precedence than method call
3535
let _ = -(1.0_f64.cos().sin());
36-
//~^ WARN unary minus has lower precedence than method call
36+
//~^ WARN unary operator `-` has lower precedence than method call
3737
let _ = -(1.0_f64.sin().cos());
38-
//~^ WARN unary minus has lower precedence than method call
38+
//~^ WARN unary operator `-` has lower precedence than method call
3939
let _ = -(1f64.sin().sin());
40-
//~^ WARN unary minus has lower precedence than method call
40+
//~^ WARN unary operator `-` has lower precedence than method call
4141

4242
// These should not trigger an error
4343
let _ = (-1i32).abs();

tests/ui/lint/precedence.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,25 @@ fn main() {
1919
let _ = 1 + 2 << 3 + 1;
2020
//~^ WARN operator precedence can trip the unwary
2121
let _ = -1i32.abs();
22-
//~^ WARN unary minus has lower precedence than method call
22+
//~^ WARN unary operator `-` has lower precedence than method call
2323
let _ = -1f32.abs();
24-
//~^ WARN unary minus has lower precedence than method call
24+
//~^ WARN unary operator `-` has lower precedence than method call
2525
let _ = -1f64.asin();
26-
//~^ WARN unary minus has lower precedence than method call
26+
//~^ WARN unary operator `-` has lower precedence than method call
2727
let _ = -1f64.asinh();
28-
//~^ WARN unary minus has lower precedence than method call
28+
//~^ WARN unary operator `-` has lower precedence than method call
2929
let _ = -1f64.tan();
30-
//~^ WARN unary minus has lower precedence than method call
30+
//~^ WARN unary operator `-` has lower precedence than method call
3131
let _ = -1f64.tanh();
32-
//~^ WARN unary minus has lower precedence than method call
32+
//~^ WARN unary operator `-` has lower precedence than method call
3333
let _ = -1.0_f64.cos().cos();
34-
//~^ WARN unary minus has lower precedence than method call
34+
//~^ WARN unary operator `-` has lower precedence than method call
3535
let _ = -1.0_f64.cos().sin();
36-
//~^ WARN unary minus has lower precedence than method call
36+
//~^ WARN unary operator `-` has lower precedence than method call
3737
let _ = -1.0_f64.sin().cos();
38-
//~^ WARN unary minus has lower precedence than method call
38+
//~^ WARN unary operator `-` has lower precedence than method call
3939
let _ = -1f64.sin().sin();
40-
//~^ WARN unary minus has lower precedence than method call
40+
//~^ WARN unary operator `-` has lower precedence than method call
4141

4242
// These should not trigger an error
4343
let _ = (-1i32).abs();

tests/ui/lint/precedence.stderr

+10-10
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ help: consider adding parentheses to clarify your intent
8787
LL | let _ = (1 + 2) << (3 + 1);
8888
| + + + +
8989

90-
warning: unary minus has lower precedence than method call
90+
warning: unary operator `-` has lower precedence than method call
9191
--> $DIR/precedence.rs:21:13
9292
|
9393
LL | let _ = -1i32.abs();
@@ -98,7 +98,7 @@ help: consider adding parentheses to clarify your intent
9898
LL | let _ = -(1i32.abs());
9999
| + +
100100

101-
warning: unary minus has lower precedence than method call
101+
warning: unary operator `-` has lower precedence than method call
102102
--> $DIR/precedence.rs:23:13
103103
|
104104
LL | let _ = -1f32.abs();
@@ -109,7 +109,7 @@ help: consider adding parentheses to clarify your intent
109109
LL | let _ = -(1f32.abs());
110110
| + +
111111

112-
warning: unary minus has lower precedence than method call
112+
warning: unary operator `-` has lower precedence than method call
113113
--> $DIR/precedence.rs:25:13
114114
|
115115
LL | let _ = -1f64.asin();
@@ -120,7 +120,7 @@ help: consider adding parentheses to clarify your intent
120120
LL | let _ = -(1f64.asin());
121121
| + +
122122

123-
warning: unary minus has lower precedence than method call
123+
warning: unary operator `-` has lower precedence than method call
124124
--> $DIR/precedence.rs:27:13
125125
|
126126
LL | let _ = -1f64.asinh();
@@ -131,7 +131,7 @@ help: consider adding parentheses to clarify your intent
131131
LL | let _ = -(1f64.asinh());
132132
| + +
133133

134-
warning: unary minus has lower precedence than method call
134+
warning: unary operator `-` has lower precedence than method call
135135
--> $DIR/precedence.rs:29:13
136136
|
137137
LL | let _ = -1f64.tan();
@@ -142,7 +142,7 @@ help: consider adding parentheses to clarify your intent
142142
LL | let _ = -(1f64.tan());
143143
| + +
144144

145-
warning: unary minus has lower precedence than method call
145+
warning: unary operator `-` has lower precedence than method call
146146
--> $DIR/precedence.rs:31:13
147147
|
148148
LL | let _ = -1f64.tanh();
@@ -153,7 +153,7 @@ help: consider adding parentheses to clarify your intent
153153
LL | let _ = -(1f64.tanh());
154154
| + +
155155

156-
warning: unary minus has lower precedence than method call
156+
warning: unary operator `-` has lower precedence than method call
157157
--> $DIR/precedence.rs:33:13
158158
|
159159
LL | let _ = -1.0_f64.cos().cos();
@@ -164,7 +164,7 @@ help: consider adding parentheses to clarify your intent
164164
LL | let _ = -(1.0_f64.cos().cos());
165165
| + +
166166

167-
warning: unary minus has lower precedence than method call
167+
warning: unary operator `-` has lower precedence than method call
168168
--> $DIR/precedence.rs:35:13
169169
|
170170
LL | let _ = -1.0_f64.cos().sin();
@@ -175,7 +175,7 @@ help: consider adding parentheses to clarify your intent
175175
LL | let _ = -(1.0_f64.cos().sin());
176176
| + +
177177

178-
warning: unary minus has lower precedence than method call
178+
warning: unary operator `-` has lower precedence than method call
179179
--> $DIR/precedence.rs:37:13
180180
|
181181
LL | let _ = -1.0_f64.sin().cos();
@@ -186,7 +186,7 @@ help: consider adding parentheses to clarify your intent
186186
LL | let _ = -(1.0_f64.sin().cos());
187187
| + +
188188

189-
warning: unary minus has lower precedence than method call
189+
warning: unary operator `-` has lower precedence than method call
190190
--> $DIR/precedence.rs:39:13
191191
|
192192
LL | let _ = -1f64.sin().sin();

0 commit comments

Comments
 (0)