Skip to content

Commit bc72ce6

Browse files
committed
let_chains: Add test cases to pprust-expr-roundtrip.
1 parent 851066f commit bc72ce6

File tree

1 file changed

+32
-23
lines changed

1 file changed

+32
-23
lines changed

src/test/run-pass-fulldeps/pprust-expr-roundtrip.rs

+32-23
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ fn iter_exprs(depth: usize, f: &mut dyn FnMut(P<Expr>)) {
6868

6969
let mut g = |e| f(expr(e));
7070

71-
for kind in 0 .. 16 {
71+
for kind in 0..=19 {
7272
match kind {
7373
0 => iter_exprs(depth - 1, &mut |e| g(ExprKind::Box(e))),
7474
1 => iter_exprs(depth - 1, &mut |e| g(ExprKind::Call(e, vec![]))),
@@ -79,25 +79,26 @@ fn iter_exprs(depth: usize, f: &mut dyn FnMut(P<Expr>)) {
7979
iter_exprs(depth - 1, &mut |e| g(ExprKind::MethodCall(
8080
seg.clone(), vec![make_x(), e])));
8181
},
82-
3 => {
83-
let op = Spanned { span: DUMMY_SP, node: BinOpKind::Add };
84-
iter_exprs(depth - 1, &mut |e| g(ExprKind::Binary(op, e, make_x())));
85-
iter_exprs(depth - 1, &mut |e| g(ExprKind::Binary(op, make_x(), e)));
86-
},
87-
4 => {
88-
let op = Spanned { span: DUMMY_SP, node: BinOpKind::Mul };
89-
iter_exprs(depth - 1, &mut |e| g(ExprKind::Binary(op, e, make_x())));
90-
iter_exprs(depth - 1, &mut |e| g(ExprKind::Binary(op, make_x(), e)));
91-
},
92-
5 => {
93-
let op = Spanned { span: DUMMY_SP, node: BinOpKind::Shl };
82+
3..=8 => {
83+
let op = Spanned {
84+
span: DUMMY_SP,
85+
node: match kind {
86+
3 => BinOpKind::Add,
87+
4 => BinOpKind::Mul,
88+
5 => BinOpKind::Shl,
89+
6 => BinOpKind::And,
90+
7 => BinOpKind::Or,
91+
8 => BinOpKind::Lt,
92+
_ => unreachable!(),
93+
}
94+
};
9495
iter_exprs(depth - 1, &mut |e| g(ExprKind::Binary(op, e, make_x())));
9596
iter_exprs(depth - 1, &mut |e| g(ExprKind::Binary(op, make_x(), e)));
9697
},
97-
6 => {
98+
9 => {
9899
iter_exprs(depth - 1, &mut |e| g(ExprKind::Unary(UnOp::Deref, e)));
99100
},
100-
7 => {
101+
10 => {
101102
let block = P(Block {
102103
stmts: Vec::new(),
103104
id: DUMMY_NODE_ID,
@@ -106,7 +107,7 @@ fn iter_exprs(depth: usize, f: &mut dyn FnMut(P<Expr>)) {
106107
});
107108
iter_exprs(depth - 1, &mut |e| g(ExprKind::If(e, block.clone(), None)));
108109
},
109-
8 => {
110+
11 => {
110111
let decl = P(FnDecl {
111112
inputs: vec![],
112113
output: FunctionRetTy::Default(DUMMY_SP),
@@ -120,33 +121,41 @@ fn iter_exprs(depth: usize, f: &mut dyn FnMut(P<Expr>)) {
120121
e,
121122
DUMMY_SP)));
122123
},
123-
9 => {
124+
12 => {
124125
iter_exprs(depth - 1, &mut |e| g(ExprKind::Assign(e, make_x())));
125126
iter_exprs(depth - 1, &mut |e| g(ExprKind::Assign(make_x(), e)));
126127
},
127-
10 => {
128+
13 => {
128129
iter_exprs(depth - 1, &mut |e| g(ExprKind::Field(e, Ident::from_str("f"))));
129130
},
130-
11 => {
131+
14 => {
131132
iter_exprs(depth - 1, &mut |e| g(ExprKind::Range(
132133
Some(e), Some(make_x()), RangeLimits::HalfOpen)));
133134
iter_exprs(depth - 1, &mut |e| g(ExprKind::Range(
134135
Some(make_x()), Some(e), RangeLimits::HalfOpen)));
135136
},
136-
12 => {
137+
15 => {
137138
iter_exprs(depth - 1, &mut |e| g(ExprKind::AddrOf(Mutability::Immutable, e)));
138139
},
139-
13 => {
140+
16 => {
140141
g(ExprKind::Ret(None));
141142
iter_exprs(depth - 1, &mut |e| g(ExprKind::Ret(Some(e))));
142143
},
143-
14 => {
144+
17 => {
144145
let path = Path::from_ident(Ident::from_str("S"));
145146
g(ExprKind::Struct(path, vec![], Some(make_x())));
146147
},
147-
15 => {
148+
18 => {
148149
iter_exprs(depth - 1, &mut |e| g(ExprKind::Try(e)));
149150
},
151+
19 => {
152+
let ps = vec![P(Pat {
153+
id: DUMMY_NODE_ID,
154+
node: PatKind::Wild,
155+
span: DUMMY_SP,
156+
})];
157+
iter_exprs(depth - 1, &mut |e| g(ExprKind::Let(ps.clone(), e)))
158+
},
150159
_ => panic!("bad counter value in iter_exprs"),
151160
}
152161
}

0 commit comments

Comments
 (0)