Skip to content

Commit dc613c6

Browse files
committed
Fix test
1 parent afcf9b2 commit dc613c6

File tree

1 file changed

+25
-22
lines changed

1 file changed

+25
-22
lines changed

src/test/ui-fulldeps/pprust-expr-roundtrip.rs

+25-22
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,15 @@ use syntax::print::pprust;
3232
use syntax::ptr::P;
3333

3434

35-
fn parse_expr(ps: &ParseSess, src: &str) -> P<Expr> {
35+
fn parse_expr(ps: &ParseSess, src: &str) -> Option<P<Expr>> {
3636
let src_as_string = src.to_string();
3737

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()
4244
}
4345

4446

@@ -209,22 +211,23 @@ fn run() {
209211
let printed = pprust::expr_to_string(&e);
210212
println!("printed: {}", printed);
211213

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+
}
229232
});
230233
}

0 commit comments

Comments
 (0)