@@ -32,13 +32,15 @@ use syntax::print::pprust;
32
32
use syntax:: ptr:: P ;
33
33
34
34
35
- fn parse_expr ( ps : & ParseSess , src : & str ) -> P < Expr > {
35
+ fn parse_expr ( ps : & ParseSess , src : & str ) -> Option < P < Expr > > {
36
36
let src_as_string = src. to_string ( ) ;
37
37
38
- let mut p = parse:: new_parser_from_source_str ( ps,
39
- FileName :: Custom ( src_as_string. clone ( ) ) ,
40
- src_as_string) ;
41
- p. parse_expr ( ) . unwrap ( )
38
+ let mut p = parse:: new_parser_from_source_str (
39
+ ps,
40
+ FileName :: Custom ( src_as_string. clone ( ) ) ,
41
+ src_as_string,
42
+ ) ;
43
+ p. parse_expr ( ) . map_err ( |mut e| e. cancel ( ) ) . ok ( )
42
44
}
43
45
44
46
@@ -209,22 +211,23 @@ fn run() {
209
211
let printed = pprust:: expr_to_string ( & e) ;
210
212
println ! ( "printed: {}" , printed) ;
211
213
212
- let mut parsed = parse_expr ( & ps, & printed) ;
213
-
214
- // We want to know if `parsed` is structurally identical to `e`, ignoring trivial
215
- // differences like placement of `Paren`s or the exact ranges of node spans.
216
- // Unfortunately, there is no easy way to make this comparison. Instead, we add `Paren`s
217
- // everywhere we can, then pretty-print. This should give an unambiguous representation of
218
- // each `Expr`, and it bypasses nearly all of the parenthesization logic, so we aren't
219
- // relying on the correctness of the very thing we're testing.
220
- RemoveParens . visit_expr ( & mut e) ;
221
- AddParens . visit_expr ( & mut e) ;
222
- let text1 = pprust:: expr_to_string ( & e) ;
223
- RemoveParens . visit_expr ( & mut parsed) ;
224
- AddParens . visit_expr ( & mut parsed) ;
225
- let text2 = pprust:: expr_to_string ( & parsed) ;
226
- assert ! ( text1 == text2,
227
- "exprs are not equal:\n e = {:?}\n parsed = {:?}" ,
228
- text1, text2) ;
214
+ // Ignore expressions with chained comparisons that fail to parse
215
+ if let Some ( mut parsed) = parse_expr ( & ps, & printed) {
216
+ // We want to know if `parsed` is structurally identical to `e`, ignoring trivial
217
+ // differences like placement of `Paren`s or the exact ranges of node spans.
218
+ // Unfortunately, there is no easy way to make this comparison. Instead, we add `Paren`s
219
+ // everywhere we can, then pretty-print. This should give an unambiguous representation
220
+ // of each `Expr`, and it bypasses nearly all of the parenthesization logic, so we
221
+ // aren't relying on the correctness of the very thing we're testing.
222
+ RemoveParens . visit_expr ( & mut e) ;
223
+ AddParens . visit_expr ( & mut e) ;
224
+ let text1 = pprust:: expr_to_string ( & e) ;
225
+ RemoveParens . visit_expr ( & mut parsed) ;
226
+ AddParens . visit_expr ( & mut parsed) ;
227
+ let text2 = pprust:: expr_to_string ( & parsed) ;
228
+ assert ! ( text1 == text2,
229
+ "exprs are not equal:\n e = {:?}\n parsed = {:?}" ,
230
+ text1, text2) ;
231
+ }
229
232
} ) ;
230
233
}
0 commit comments