Skip to content
This repository was archived by the owner on Apr 8, 2024. It is now read-only.

Commit cf6094e

Browse files
committed
Always sort ParseError's expected field.
1 parent 5f6ced2 commit cf6094e

8 files changed

+213
-198
lines changed

src/bin/coverage.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,15 @@ fn report_file_result(
139139
"(missing location information; \
140140
set `RUSTFLAGS='--cfg procmacro2_semver_exempt'`)"
141141
);
142+
142143
}
143-
eprintln!("Expected: {:?}", error.expected);
144+
145+
// HACK(eddyb) this is inefficient - `expected` should be already
146+
// sorted for us, so this is a temporary workaround.
147+
let mut expected = error.expected.clone();
148+
expected.sort_by_cached_key(|x| format!("{:?}", x));
149+
150+
eprintln!("Expected: {:?}", expected);
144151
}
145152
(Err(Error::Lex(e)), _) => eprintln!("FAIL ({:?})", e),
146153
}

src/bin/snapshots.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,24 @@ use {
99
walkdir::WalkDir,
1010
};
1111

12-
fn to_debug_str(debug: &dyn Debug) -> String {
13-
format!("{:#?}", debug)
12+
fn parse_result_to_str<T: Debug>(
13+
mut result: Result<T, gll::parser::ParseError<proc_macro2::Span>>,
14+
) -> String {
15+
if let Err(error) = &mut result {
16+
// HACK(eddyb) this is inefficient - `expected` should be already
17+
// sorted for us, so this is a temporary workaround.
18+
error.expected.sort_by_cached_key(|x| format!("{:?}", x));
19+
}
20+
21+
format!("{:#?}", result)
1422
}
1523

1624
macro_rules! snapshot {
1725
($production:ident, $src:expr) => {{
1826
let tts = $src
1927
.parse::<proc_macro2::TokenStream>()
2028
.expect("tokenization");
21-
to_debug_str(&parse::$production::parse(tts))
29+
parse_result_to_str(parse::$production::parse(tts))
2230
}};
2331
}
2432

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
---
2-
created: "2019-06-02T15:47:34.962866Z"
3-
creator: insta@0.8.1
2+
created: "2019-08-24T22:44:34.221417271Z"
3+
creator: insta@0.7.4
44
source: src/bin/snapshots.rs
55
expression: forest
66
---
77
Err(
88
ParseError {
99
at: Span,
1010
expected: [
11+
[
12+
Ident(
13+
None,
14+
),
15+
],
1116
[
1217
Punct {
1318
ch: Some(
@@ -16,11 +21,6 @@ Err(
1621
joint: None,
1722
},
1823
],
19-
[
20-
Ident(
21-
None,
22-
),
23-
],
2424
],
2525
},
2626
)
Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
created: "2019-06-02T15:36:47.233172Z"
3-
creator: insta@0.8.1
2+
created: "2019-08-24T22:44:34.272568062Z"
3+
creator: insta@0.7.4
44
source: src/bin/snapshots.rs
55
expression: forest
66
---
@@ -9,48 +9,19 @@ Err(
99
at: Span,
1010
expected: [
1111
[
12-
Punct {
13-
ch: Some(
14-
'>',
15-
),
16-
joint: None,
17-
},
18-
],
19-
[
20-
Ident(
21-
Some(
22-
"_",
23-
),
12+
Delim(
13+
'(',
2414
),
2515
],
26-
[
27-
Punct {
28-
ch: Some(
29-
'!',
30-
),
31-
joint: None,
32-
},
33-
],
3416
[
3517
Delim(
3618
'(',
3719
),
3820
],
3921
[
40-
Punct {
41-
ch: Some(
42-
'*',
43-
),
44-
joint: None,
45-
},
46-
],
47-
[
48-
Punct {
49-
ch: Some(
50-
'&',
51-
),
52-
joint: None,
53-
},
22+
Delim(
23+
'(',
24+
),
5425
],
5526
[
5627
Delim(
@@ -63,14 +34,14 @@ Err(
6334
),
6435
],
6536
[
66-
Delim(
67-
'(',
37+
Ident(
38+
None,
6839
),
6940
],
7041
[
7142
Ident(
7243
Some(
73-
"impl",
44+
"_",
7445
),
7546
),
7647
],
@@ -84,35 +55,65 @@ Err(
8455
[
8556
Ident(
8657
Some(
87-
"typeof",
58+
"extern",
8859
),
8960
),
9061
],
9162
[
9263
Ident(
9364
Some(
94-
"unsafe",
65+
"fn",
9566
),
9667
),
9768
],
9869
[
9970
Ident(
10071
Some(
101-
"extern",
72+
"for",
10273
),
10374
),
10475
],
10576
[
10677
Ident(
10778
Some(
108-
"fn",
79+
"impl",
80+
),
81+
),
82+
],
83+
[
84+
Ident(
85+
Some(
86+
"typeof",
87+
),
88+
),
89+
],
90+
[
91+
Ident(
92+
Some(
93+
"unsafe",
10994
),
11095
),
11196
],
11297
[
11398
Punct {
11499
ch: Some(
115-
'<',
100+
'!',
101+
),
102+
joint: None,
103+
},
104+
],
105+
[
106+
Punct {
107+
ch: Some(
108+
'&',
109+
),
110+
joint: None,
111+
},
112+
],
113+
[
114+
Punct {
115+
ch: Some(
116+
'*',
116117
),
117118
joint: None,
118119
},
@@ -134,24 +135,28 @@ Err(
134135
},
135136
],
136137
[
137-
Delim(
138-
'(',
139-
),
138+
Punct {
139+
ch: Some(
140+
'<',
141+
),
142+
joint: None,
143+
},
140144
],
141145
[
142146
Punct {
143147
ch: Some(
144-
'?',
148+
'>',
145149
),
146150
joint: None,
147151
},
148152
],
149153
[
150-
Ident(
151-
Some(
152-
"for",
154+
Punct {
155+
ch: Some(
156+
'?',
153157
),
154-
),
158+
joint: None,
159+
},
155160
],
156161
[
157162
Punct {
@@ -166,11 +171,6 @@ Err(
166171
None,
167172
),
168173
],
169-
[
170-
Ident(
171-
None,
172-
),
173-
],
174174
],
175175
},
176176
)

0 commit comments

Comments
 (0)