Skip to content

Commit 07f37c8

Browse files
committed
let_chains: Account for const generics in validation tests.
1 parent a80aa34 commit 07f37c8

File tree

2 files changed

+123
-54
lines changed

2 files changed

+123
-54
lines changed

src/test/ui/rfc-2497-if-let-chains/disallowed-positions.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
//
1818
// To that end, we check some positions which is not part of the language above.
1919

20+
#![feature(const_generics)] //~ WARN the feature `const_generics` is incomplete
21+
2022
#![allow(irrefutable_let_patterns)]
2123

2224
use std::ops::Range;
@@ -157,3 +159,31 @@ fn outside_if_and_while_expr() {
157159
&let 0 = 0
158160
//~^ ERROR `let` expressions are not supported here
159161
}
162+
163+
// Let's make sure that `let` inside const generic arguments are considered.
164+
fn inside_const_generic_arguments() {
165+
struct A<const B: bool>;
166+
impl<const B: bool> A<{B}> { const O: u32 = 5; }
167+
168+
if let A::<{
169+
true && let 1 = 1 //~ ERROR `let` expressions are not supported here
170+
}>::O = 5 {}
171+
172+
while let A::<{
173+
true && let 1 = 1 //~ ERROR `let` expressions are not supported here
174+
}>::O = 5 {}
175+
176+
if A::<{
177+
true && let 1 = 1 //~ ERROR `let` expressions are not supported here
178+
}>::O == 5 {}
179+
180+
// In the cases above we have `ExprKind::Block` to help us out.
181+
// Below however, we would not have a block and so an implementation might go
182+
// from visiting expressions to types without banning `let` expressions down the tree.
183+
// This tests ensures that we are not caught by surprise should the parser
184+
// admit non-IDENT expressions in const generic arguments.
185+
186+
if A::<
187+
true && let 1 = 1 //~ ERROR expected one of `,` or `>`, found `&&`
188+
>::O == 5 {}
189+
}

0 commit comments

Comments
 (0)