You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Auto merge of rust-lang#11249 - GuillaumeGomez:ui-tests-annotations, r=Centri3,llogiq
Add error annotations in UI tests
As discussed on [zulip](https://rust-lang.zulipchat.com/#narrow/stream/257328-clippy/topic/Improve.20UI.20error.20checks), this PR adds missing error annotations in UI tests.
I used this script to generate them:
<details>
```python
import os
def handle_err(line, stderr, elems, kind, i):
msg = line.split("{}: ".format(kind), 1)[1]
i += 1
try:
line_nb = int(stderr[i].split(":")[1])
except Exception:
return i
in_macro = False
note_found = False
help_found = False
elem = {"kind": kind, "msg": msg, "line": line_nb, "notes": [], "helps": []}
while i < len(stderr):
if len(stderr[i]) == 0:
break
elif stderr[i].startswith("note:"):
note_found = True # error checker doesn't like multi-note apparently.
elif stderr[i].startswith(" = note:"):
if not note_found and not help_found and "this error originates in the macro" not in stderr[i]:
elem["notes"].append(stderr[i].split(" = note:", 1)[1].strip())
note_found = True # error checker doesn't like multi-note apparently.
elif stderr[i].startswith(" = help:") or stderr[i].startswith("help:"):
help_found = True
# elif stderr[i].startswith("help:"):
# if not help_found:
# elem["helps"].append(stderr[i].split("help:", 1)[1].strip())
# help_found = True # error checker doesn't like multi-help apparently.
elif "in this macro invocation" in stderr[i]:
in_macro = True
i += 1
if not in_macro:
elems.append(elem)
return i
def show_kind(kind):
if kind == "error":
return "ERROR"
elif kind == "warning":
return "WARNING"
elif kind == "note":
return "NOTE"
return "HELP"
def generate_code_err(indent, elem, up):
content = "{}//~{} {}: {}".format(indent, up, show_kind(elem["kind"]), elem["msg"])
if up == "^":
up = "|"
for note in elem["notes"]:
content += "\n{}//~{} {}: {}".format(indent, up, show_kind("note"), note)
for help_msg in elem["helps"]:
content += "\n{}//~{} {}: {}".format(indent, up, show_kind("help"), help_msg)
return content, up
def update_content(p, content):
TO_IGNORE = [
"needless_bool/simple.rs", # rust-lang/rust-clippy#11248
"crashes/ice-7868.rs", # Has errors but in another file.
"trivially_copy_pass_by_ref.rs", # the `N` in the stderr needs to be replaced by the number
"tests/ui/large_types_passed_by_value.rs", # the `N` in the stderr needs to be replaced by the number
]
for to_ignore in TO_IGNORE:
if p.endswith(to_ignore):
return
try:
with open(p.replace(".rs", ".stderr"), "r", encoding="utf8") as f:
stderr = f.read().split('\n')
except Exception:
return
print("Updating `{}`".format(p))
i = 0
elems = []
while i < len(stderr):
line = stderr[i]
if line.startswith("error: ") and not line.startswith("error: aborting due to"):
i = handle_err(line, stderr, elems, "error", i)
elif line.startswith("warning: ") and not line.endswith("warning emitted") and line.endswith("warnings emitted"):
i = handle_err(line, stderr, elems, "warning", i)
i += 1
elems.sort(key=lambda e: e["line"], reverse=True)
i = 0
while i < len(elems):
elem = elems[i]
indent = ""
c = 0
line = content[elem["line"] - 1]
while c < len(line) and line[c] == ' ':
indent += " "
c += 1
new_content, up = generate_code_err(indent, elem, "^")
i += 1
while i < len(elems) and elems[i]["line"] == elem["line"]:
elem = elems[i]
ret = generate_code_err(indent, elem, up)
new_content += "\n" + ret[0]
up = ret[1]
i += 1
content.insert(elem["line"], new_content)
with open(p, "w", encoding="utf8") as f:
f.write("\n".join(content))
def check_if_contains_ui_test(p):
if not p.endswith(".rs"):
return
with open(p, "r", encoding="utf8") as f:
x = f.read()
if "//~" not in x and "`@run-rustfix"` not in x and "`@aux-build"` not in x:
update_content(p, x.split("\n"))
for path, subdirs, files in os.walk("tests/ui"):
for name in files:
check_if_contains_ui_test(os.path.join(path, name))
```
</details>
Then ran `cargo uibless`.
changelog: none
Copy file name to clipboardexpand all lines: tests/ui/absurd-extreme-comparisons.stderr
+17-17
Original file line number
Diff line number
Diff line change
@@ -8,135 +8,135 @@ LL | u <= 0;
8
8
= note: `-D clippy::absurd-extreme-comparisons` implied by `-D warnings`
9
9
10
10
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
11
-
--> $DIR/absurd-extreme-comparisons.rs:15:5
11
+
--> $DIR/absurd-extreme-comparisons.rs:16:5
12
12
|
13
13
LL | u <= Z;
14
14
| ^^^^^^
15
15
|
16
16
= help: because `Z` is the minimum value for this type, the case where the two sides are not equal never occurs, consider using `u == Z` instead
17
17
18
18
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
19
-
--> $DIR/absurd-extreme-comparisons.rs:16:5
19
+
--> $DIR/absurd-extreme-comparisons.rs:18:5
20
20
|
21
21
LL | u < Z;
22
22
| ^^^^^
23
23
|
24
24
= help: because `Z` is the minimum value for this type, this comparison is always false
25
25
26
26
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
27
-
--> $DIR/absurd-extreme-comparisons.rs:17:5
27
+
--> $DIR/absurd-extreme-comparisons.rs:20:5
28
28
|
29
29
LL | Z >= u;
30
30
| ^^^^^^
31
31
|
32
32
= help: because `Z` is the minimum value for this type, the case where the two sides are not equal never occurs, consider using `Z == u` instead
33
33
34
34
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
35
-
--> $DIR/absurd-extreme-comparisons.rs:18:5
35
+
--> $DIR/absurd-extreme-comparisons.rs:22:5
36
36
|
37
37
LL | Z > u;
38
38
| ^^^^^
39
39
|
40
40
= help: because `Z` is the minimum value for this type, this comparison is always false
41
41
42
42
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
43
-
--> $DIR/absurd-extreme-comparisons.rs:19:5
43
+
--> $DIR/absurd-extreme-comparisons.rs:24:5
44
44
|
45
45
LL | u > u32::MAX;
46
46
| ^^^^^^^^^^^^
47
47
|
48
48
= help: because `u32::MAX` is the maximum value for this type, this comparison is always false
49
49
50
50
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
51
-
--> $DIR/absurd-extreme-comparisons.rs:20:5
51
+
--> $DIR/absurd-extreme-comparisons.rs:26:5
52
52
|
53
53
LL | u >= u32::MAX;
54
54
| ^^^^^^^^^^^^^
55
55
|
56
56
= help: because `u32::MAX` is the maximum value for this type, the case where the two sides are not equal never occurs, consider using `u == u32::MAX` instead
57
57
58
58
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
59
-
--> $DIR/absurd-extreme-comparisons.rs:21:5
59
+
--> $DIR/absurd-extreme-comparisons.rs:28:5
60
60
|
61
61
LL | u32::MAX < u;
62
62
| ^^^^^^^^^^^^
63
63
|
64
64
= help: because `u32::MAX` is the maximum value for this type, this comparison is always false
65
65
66
66
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
67
-
--> $DIR/absurd-extreme-comparisons.rs:22:5
67
+
--> $DIR/absurd-extreme-comparisons.rs:30:5
68
68
|
69
69
LL | u32::MAX <= u;
70
70
| ^^^^^^^^^^^^^
71
71
|
72
72
= help: because `u32::MAX` is the maximum value for this type, the case where the two sides are not equal never occurs, consider using `u32::MAX == u` instead
73
73
74
74
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
75
-
--> $DIR/absurd-extreme-comparisons.rs:23:5
75
+
--> $DIR/absurd-extreme-comparisons.rs:32:5
76
76
|
77
77
LL | 1-1 > u;
78
78
| ^^^^^^^
79
79
|
80
80
= help: because `1-1` is the minimum value for this type, this comparison is always false
81
81
82
82
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
83
-
--> $DIR/absurd-extreme-comparisons.rs:24:5
83
+
--> $DIR/absurd-extreme-comparisons.rs:34:5
84
84
|
85
85
LL | u >= !0;
86
86
| ^^^^^^^
87
87
|
88
88
= help: because `!0` is the maximum value for this type, the case where the two sides are not equal never occurs, consider using `u == !0` instead
89
89
90
90
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
91
-
--> $DIR/absurd-extreme-comparisons.rs:25:5
91
+
--> $DIR/absurd-extreme-comparisons.rs:36:5
92
92
|
93
93
LL | u <= 12 - 2*6;
94
94
| ^^^^^^^^^^^^^
95
95
|
96
96
= help: because `12 - 2*6` is the minimum value for this type, the case where the two sides are not equal never occurs, consider using `u == 12 - 2*6` instead
97
97
98
98
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
99
-
--> $DIR/absurd-extreme-comparisons.rs:27:5
99
+
--> $DIR/absurd-extreme-comparisons.rs:39:5
100
100
|
101
101
LL | i < -127 - 1;
102
102
| ^^^^^^^^^^^^
103
103
|
104
104
= help: because `-127 - 1` is the minimum value for this type, this comparison is always false
105
105
106
106
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
107
-
--> $DIR/absurd-extreme-comparisons.rs:28:5
107
+
--> $DIR/absurd-extreme-comparisons.rs:41:5
108
108
|
109
109
LL | i8::MAX >= i;
110
110
| ^^^^^^^^^^^^
111
111
|
112
112
= help: because `i8::MAX` is the maximum value for this type, this comparison is always true
113
113
114
114
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
115
-
--> $DIR/absurd-extreme-comparisons.rs:29:5
115
+
--> $DIR/absurd-extreme-comparisons.rs:43:5
116
116
|
117
117
LL | 3-7 < i32::MIN;
118
118
| ^^^^^^^^^^^^^^
119
119
|
120
120
= help: because `i32::MIN` is the minimum value for this type, this comparison is always false
121
121
122
122
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
123
-
--> $DIR/absurd-extreme-comparisons.rs:31:5
123
+
--> $DIR/absurd-extreme-comparisons.rs:46:5
124
124
|
125
125
LL | b >= true;
126
126
| ^^^^^^^^^
127
127
|
128
128
= help: because `true` is the maximum value for this type, the case where the two sides are not equal never occurs, consider using `b == true` instead
129
129
130
130
error: this comparison involving the minimum or maximum element for this type contains a case that is always true or always false
131
-
--> $DIR/absurd-extreme-comparisons.rs:32:5
131
+
--> $DIR/absurd-extreme-comparisons.rs:48:5
132
132
|
133
133
LL | false > b;
134
134
| ^^^^^^^^^
135
135
|
136
136
= help: because `false` is the minimum value for this type, this comparison is always false
137
137
138
138
error: <-comparison of unit values detected. This will always be false
0 commit comments