Skip to content
This repository was archived by the owner on Nov 24, 2023. It is now read-only.

Commit a71ff8a

Browse files
committed
Merge #53
53: Add test for ambiguous `<` r=oli-obk a=killercup Inspired by https://twitter.com/b0rk/status/954366146505052160
2 parents 69fa896 + 5ad590b commit a71ff8a

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fn main() {
2+
let x = 5i64;
3+
4+
if (x as u32) < 4 {
5+
println!("yay");
6+
}
7+
}

tests/fixtures/lt-generic-comp.json

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
{
2+
"message": "`<` is interpreted as a start of generic arguments for `u32`, not a comparison",
3+
"code": null,
4+
"level": "error",
5+
"spans": [
6+
{
7+
"file_name": "./tests/fixtures/lt-generic-comp.rs",
8+
"byte_start": 49,
9+
"byte_end": 50,
10+
"line_start": 4,
11+
"line_end": 4,
12+
"column_start": 19,
13+
"column_end": 20,
14+
"is_primary": false,
15+
"text": [
16+
{
17+
"text": " if x as u32 < 4 {",
18+
"highlight_start": 19,
19+
"highlight_end": 20
20+
}
21+
],
22+
"label": "interpreted as generic arguments",
23+
"suggested_replacement": null,
24+
"expansion": null
25+
},
26+
{
27+
"file_name": "./tests/fixtures/lt-generic-comp.rs",
28+
"byte_start": 47,
29+
"byte_end": 48,
30+
"line_start": 4,
31+
"line_end": 4,
32+
"column_start": 17,
33+
"column_end": 18,
34+
"is_primary": true,
35+
"text": [
36+
{
37+
"text": " if x as u32 < 4 {",
38+
"highlight_start": 17,
39+
"highlight_end": 18
40+
}
41+
],
42+
"label": "not interpreted as comparison",
43+
"suggested_replacement": null,
44+
"expansion": null
45+
}
46+
],
47+
"children": [
48+
{
49+
"message": "try comparing the casted value",
50+
"code": null,
51+
"level": "help",
52+
"spans": [
53+
{
54+
"file_name": "./tests/fixtures/lt-generic-comp.rs",
55+
"byte_start": 38,
56+
"byte_end": 46,
57+
"line_start": 4,
58+
"line_end": 4,
59+
"column_start": 8,
60+
"column_end": 16,
61+
"is_primary": true,
62+
"text": [
63+
{
64+
"text": " if x as u32 < 4 {",
65+
"highlight_start": 8,
66+
"highlight_end": 16
67+
}
68+
],
69+
"label": null,
70+
"suggested_replacement": "(x as u32)",
71+
"expansion": null
72+
}
73+
],
74+
"children": [],
75+
"rendered": null
76+
}
77+
],
78+
"rendered": "error: `<` is interpreted as a start of generic arguments for `u32`, not a comparison\n --> ./tests/fixtures/lt-generic-comp.rs:4:17\n |\n4 | if x as u32 < 4 {\n | -------- ^ - interpreted as generic arguments\n | | |\n | | not interpreted as comparison\n | help: try comparing the casted value: `(x as u32)`\n\n"
79+
}
80+
{
81+
"message": "aborting due to previous error",
82+
"code": null,
83+
"level": "error",
84+
"spans": [],
85+
"children": [],
86+
"rendered": "error: aborting due to previous error\n\n"
87+
}

tests/fixtures/lt-generic-comp.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fn main() {
2+
let x = 5i64;
3+
4+
if x as u32 < 4 {
5+
println!("yay");
6+
}
7+
}

0 commit comments

Comments
 (0)