2019-06-17 00:38:26 -05:00
|
|
|
// Here we test that `lowering` behaves correctly wrt. `let $pats = $expr` expressions.
|
2019-05-11 08:06:36 -05:00
|
|
|
//
|
|
|
|
// We want to make sure that `let` is banned in situations other than:
|
|
|
|
//
|
|
|
|
// expr =
|
|
|
|
// | ...
|
|
|
|
// | "if" expr_with_let block {"else" block}?
|
|
|
|
// | {label ":"}? while" expr_with_let block
|
|
|
|
// ;
|
|
|
|
//
|
|
|
|
// expr_with_let =
|
|
|
|
// | "let" top_pats "=" expr
|
|
|
|
// | expr_with_let "&&" expr_with_let
|
|
|
|
// | "(" expr_with_let ")"
|
|
|
|
// | expr
|
|
|
|
// ;
|
|
|
|
//
|
|
|
|
// To that end, we check some positions which is not part of the language above.
|
|
|
|
|
2022-08-20 13:40:08 -05:00
|
|
|
#![feature(let_chains)] // Avoid inflating `.stderr` with overzealous gates in this test.
|
|
|
|
|
2019-05-11 08:06:36 -05:00
|
|
|
#![allow(irrefutable_let_patterns)]
|
|
|
|
|
|
|
|
use std::ops::Range;
|
|
|
|
|
|
|
|
fn main() {}
|
|
|
|
|
2022-03-31 16:33:05 -05:00
|
|
|
fn _if() {
|
|
|
|
if (let 0 = 1) {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
2022-07-08 05:25:50 -05:00
|
|
|
//~| ERROR expected expression, found `let` statement
|
2022-03-31 16:33:05 -05:00
|
|
|
|
|
|
|
if (((let 0 = 1))) {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
2022-07-08 05:25:50 -05:00
|
|
|
//~| ERROR expected expression, found `let` statement
|
2022-03-31 16:33:05 -05:00
|
|
|
|
|
|
|
if (let 0 = 1) && true {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
2022-07-08 05:25:50 -05:00
|
|
|
//~| ERROR expected expression, found `let` statement
|
2022-03-31 16:33:05 -05:00
|
|
|
|
|
|
|
if true && (let 0 = 1) {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
2022-07-08 05:25:50 -05:00
|
|
|
//~| ERROR expected expression, found `let` statement
|
2022-03-31 16:33:05 -05:00
|
|
|
|
|
|
|
if (let 0 = 1) && (let 0 = 1) {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR `let` expressions are not supported here
|
2022-07-08 05:25:50 -05:00
|
|
|
//~| ERROR expected expression, found `let` statement
|
|
|
|
//~| ERROR expected expression, found `let` statement
|
2022-03-31 16:33:05 -05:00
|
|
|
|
|
|
|
if let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR `let` expressions are not supported here
|
2022-07-08 05:25:50 -05:00
|
|
|
//~| ERROR expected expression, found `let` statement
|
2022-07-31 20:13:16 -05:00
|
|
|
//~| ERROR expected expression, found `let` statement
|
|
|
|
//~| ERROR expected expression, found `let` statement
|
2022-03-31 16:33:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn _while() {
|
|
|
|
while (let 0 = 1) {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
2022-07-08 05:25:50 -05:00
|
|
|
//~| ERROR expected expression, found `let` statement
|
2022-03-31 16:33:05 -05:00
|
|
|
|
|
|
|
while (((let 0 = 1))) {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
2022-07-08 05:25:50 -05:00
|
|
|
//~| ERROR expected expression, found `let` statement
|
2022-03-31 16:33:05 -05:00
|
|
|
|
|
|
|
while (let 0 = 1) && true {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
2022-07-08 05:25:50 -05:00
|
|
|
//~| ERROR expected expression, found `let` statement
|
2022-03-31 16:33:05 -05:00
|
|
|
|
|
|
|
while true && (let 0 = 1) {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
2022-07-08 05:25:50 -05:00
|
|
|
//~| ERROR expected expression, found `let` statement
|
2022-03-31 16:33:05 -05:00
|
|
|
|
|
|
|
while (let 0 = 1) && (let 0 = 1) {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR `let` expressions are not supported here
|
2022-07-08 05:25:50 -05:00
|
|
|
//~| ERROR expected expression, found `let` statement
|
|
|
|
//~| ERROR expected expression, found `let` statement
|
2022-03-31 16:33:05 -05:00
|
|
|
|
|
|
|
while let 0 = 1 && let 1 = 2 && (let 2 = 3 && let 3 = 4 && let 4 = 5) {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR `let` expressions are not supported here
|
2022-07-08 05:25:50 -05:00
|
|
|
//~| ERROR expected expression, found `let` statement
|
2022-07-31 20:13:16 -05:00
|
|
|
//~| ERROR expected expression, found `let` statement
|
|
|
|
//~| ERROR expected expression, found `let` statement
|
2022-03-31 16:33:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn _macros() {
|
|
|
|
macro_rules! use_expr {
|
|
|
|
($e:expr) => {
|
|
|
|
if $e {}
|
|
|
|
while $e {}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
use_expr!((let 0 = 1 && 0 == 0));
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR `let` expressions are not supported here
|
2022-06-25 06:08:38 -05:00
|
|
|
//~| ERROR expected expression, found `let` statement
|
2022-03-31 16:33:05 -05:00
|
|
|
use_expr!((let 0 = 1));
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR `let` expressions are not supported here
|
2022-06-25 06:08:38 -05:00
|
|
|
//~| ERROR expected expression, found `let` statement
|
2022-03-31 16:33:05 -05:00
|
|
|
}
|
|
|
|
|
2019-05-11 08:06:36 -05:00
|
|
|
fn nested_within_if_expr() {
|
2022-07-08 05:25:50 -05:00
|
|
|
if &let 0 = 0 {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR mismatched types
|
|
|
|
//~| ERROR expected expression, found `let` statement
|
2019-05-11 08:06:36 -05:00
|
|
|
|
2022-07-08 05:25:50 -05:00
|
|
|
if !let 0 = 0 {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR expected expression, found `let` statement
|
|
|
|
if *let 0 = 0 {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR type `bool` cannot be dereferenced
|
|
|
|
//~| ERROR expected expression, found `let` statement
|
|
|
|
if -let 0 = 0 {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR cannot apply unary operator `-` to type `bool`
|
|
|
|
//~| ERROR expected expression, found `let` statement
|
2019-05-11 08:06:36 -05:00
|
|
|
|
|
|
|
fn _check_try_binds_tighter() -> Result<(), ()> {
|
|
|
|
if let 0 = 0? {}
|
2020-09-02 02:40:56 -05:00
|
|
|
//~^ ERROR the `?` operator can only be applied to values that implement `Try`
|
2019-05-11 08:06:36 -05:00
|
|
|
Ok(())
|
|
|
|
}
|
2022-07-08 05:25:50 -05:00
|
|
|
if (let 0 = 0)? {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR the `?` operator can only be applied to values that implement `Try`
|
2019-06-17 00:38:26 -05:00
|
|
|
//~| ERROR the `?` operator can only be used in a function that returns `Result`
|
2022-07-08 05:25:50 -05:00
|
|
|
//~| ERROR expected expression, found `let` statement
|
2019-05-11 08:06:36 -05:00
|
|
|
|
2022-07-08 05:25:50 -05:00
|
|
|
if true || let 0 = 0 {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR expected expression, found `let` statement
|
|
|
|
if (true || let 0 = 0) {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR expected expression, found `let` statement
|
|
|
|
if true && (true || let 0 = 0) {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR expected expression, found `let` statement
|
|
|
|
if true || (true && let 0 = 0) {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
2022-07-31 20:13:16 -05:00
|
|
|
//~| ERROR expected expression, found `let` statement
|
2019-05-11 08:06:36 -05:00
|
|
|
|
|
|
|
let mut x = true;
|
2022-07-08 05:25:50 -05:00
|
|
|
if x = let 0 = 0 {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR mismatched types
|
|
|
|
//~| ERROR expected expression, found `let` statement
|
2019-05-11 08:06:36 -05:00
|
|
|
|
2022-07-08 05:25:50 -05:00
|
|
|
if true..(let 0 = 0) {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR mismatched types
|
|
|
|
//~| ERROR expected expression, found `let` statement
|
|
|
|
if ..(let 0 = 0) {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR mismatched types
|
|
|
|
//~| ERROR expected expression, found `let` statement
|
|
|
|
if (let 0 = 0).. {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR mismatched types
|
|
|
|
//~| ERROR expected expression, found `let` statement
|
2019-05-11 08:06:36 -05:00
|
|
|
|
|
|
|
// Binds as `(let ... = true)..true &&/|| false`.
|
|
|
|
if let Range { start: _, end: _ } = true..true && false {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
2019-06-17 00:38:26 -05:00
|
|
|
//~| ERROR mismatched types
|
|
|
|
//~| ERROR mismatched types
|
2019-05-11 08:06:36 -05:00
|
|
|
if let Range { start: _, end: _ } = true..true || false {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
2019-06-17 00:38:26 -05:00
|
|
|
//~| ERROR mismatched types
|
|
|
|
//~| ERROR mismatched types
|
2019-05-11 08:06:36 -05:00
|
|
|
|
|
|
|
// Binds as `(let Range { start: F, end } = F)..(|| true)`.
|
|
|
|
const F: fn() -> bool = || true;
|
|
|
|
if let Range { start: F, end } = F..|| true {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
2019-06-17 00:38:26 -05:00
|
|
|
//~| ERROR mismatched types
|
|
|
|
//~| ERROR mismatched types
|
|
|
|
//~| ERROR mismatched types
|
2019-05-11 08:06:36 -05:00
|
|
|
|
|
|
|
// Binds as `(let Range { start: true, end } = t)..(&&false)`.
|
|
|
|
let t = &&true;
|
|
|
|
if let Range { start: true, end } = t..&&false {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
2019-06-17 00:38:26 -05:00
|
|
|
//~| ERROR mismatched types
|
|
|
|
//~| ERROR mismatched types
|
|
|
|
//~| ERROR mismatched types
|
2019-05-11 08:06:36 -05:00
|
|
|
|
2022-06-25 06:08:38 -05:00
|
|
|
if let true = let true = true {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
2022-07-08 05:25:50 -05:00
|
|
|
//~| ERROR expected expression, found `let` statement
|
2019-05-11 08:06:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn nested_within_while_expr() {
|
2022-07-08 05:25:50 -05:00
|
|
|
while &let 0 = 0 {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR mismatched types
|
|
|
|
//~| ERROR expected expression, found `let` statement
|
2019-05-11 08:06:36 -05:00
|
|
|
|
2022-07-08 05:25:50 -05:00
|
|
|
while !let 0 = 0 {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR expected expression, found `let` statement
|
|
|
|
while *let 0 = 0 {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR type `bool` cannot be dereferenced
|
|
|
|
//~| ERROR expected expression, found `let` statement
|
|
|
|
while -let 0 = 0 {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR cannot apply unary operator `-` to type `bool`
|
|
|
|
//~| ERROR expected expression, found `let` statement
|
2019-05-11 08:06:36 -05:00
|
|
|
|
|
|
|
fn _check_try_binds_tighter() -> Result<(), ()> {
|
|
|
|
while let 0 = 0? {}
|
2020-09-02 02:40:56 -05:00
|
|
|
//~^ ERROR the `?` operator can only be applied to values that implement `Try`
|
2019-05-11 08:06:36 -05:00
|
|
|
Ok(())
|
|
|
|
}
|
2022-07-08 05:25:50 -05:00
|
|
|
while (let 0 = 0)? {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR the `?` operator can only be applied to values that implement `Try`
|
2019-06-17 00:38:26 -05:00
|
|
|
//~| ERROR the `?` operator can only be used in a function that returns `Result`
|
2022-07-08 05:25:50 -05:00
|
|
|
//~| ERROR expected expression, found `let` statement
|
2019-05-11 08:06:36 -05:00
|
|
|
|
2022-07-08 05:25:50 -05:00
|
|
|
while true || let 0 = 0 {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR expected expression, found `let` statement
|
|
|
|
while (true || let 0 = 0) {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR expected expression, found `let` statement
|
|
|
|
while true && (true || let 0 = 0) {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR expected expression, found `let` statement
|
|
|
|
while true || (true && let 0 = 0) {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
2022-07-31 20:13:16 -05:00
|
|
|
//~| ERROR expected expression, found `let` statement
|
2019-05-11 08:06:36 -05:00
|
|
|
|
|
|
|
let mut x = true;
|
2022-07-08 05:25:50 -05:00
|
|
|
while x = let 0 = 0 {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR mismatched types
|
|
|
|
//~| ERROR expected expression, found `let` statement
|
2019-05-11 08:06:36 -05:00
|
|
|
|
2022-07-08 05:25:50 -05:00
|
|
|
while true..(let 0 = 0) {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR mismatched types
|
|
|
|
//~| ERROR expected expression, found `let` statement
|
|
|
|
while ..(let 0 = 0) {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR mismatched types
|
|
|
|
//~| ERROR expected expression, found `let` statement
|
|
|
|
while (let 0 = 0).. {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR mismatched types
|
|
|
|
//~| ERROR expected expression, found `let` statement
|
2019-05-11 08:06:36 -05:00
|
|
|
|
|
|
|
// Binds as `(let ... = true)..true &&/|| false`.
|
|
|
|
while let Range { start: _, end: _ } = true..true && false {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
2019-06-17 00:38:26 -05:00
|
|
|
//~| ERROR mismatched types
|
|
|
|
//~| ERROR mismatched types
|
2019-05-11 08:06:36 -05:00
|
|
|
while let Range { start: _, end: _ } = true..true || false {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
2019-06-17 00:38:26 -05:00
|
|
|
//~| ERROR mismatched types
|
|
|
|
//~| ERROR mismatched types
|
2019-05-11 08:06:36 -05:00
|
|
|
|
|
|
|
// Binds as `(let Range { start: F, end } = F)..(|| true)`.
|
|
|
|
const F: fn() -> bool = || true;
|
|
|
|
while let Range { start: F, end } = F..|| true {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
2019-06-17 00:38:26 -05:00
|
|
|
//~| ERROR mismatched types
|
|
|
|
//~| ERROR mismatched types
|
|
|
|
//~| ERROR mismatched types
|
2019-05-11 08:06:36 -05:00
|
|
|
|
|
|
|
// Binds as `(let Range { start: true, end } = t)..(&&false)`.
|
|
|
|
let t = &&true;
|
|
|
|
while let Range { start: true, end } = t..&&false {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
2019-06-17 00:38:26 -05:00
|
|
|
//~| ERROR mismatched types
|
|
|
|
//~| ERROR mismatched types
|
|
|
|
//~| ERROR mismatched types
|
2019-05-11 08:06:36 -05:00
|
|
|
|
2022-06-25 06:08:38 -05:00
|
|
|
while let true = let true = true {}
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
2022-07-08 05:25:50 -05:00
|
|
|
//~| ERROR expected expression, found `let` statement
|
2019-05-11 08:06:36 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn not_error_because_clarified_intent() {
|
|
|
|
if let Range { start: _, end: _ } = (true..true || false) { }
|
|
|
|
|
|
|
|
if let Range { start: _, end: _ } = (true..true && false) { }
|
|
|
|
|
|
|
|
while let Range { start: _, end: _ } = (true..true || false) { }
|
|
|
|
|
|
|
|
while let Range { start: _, end: _ } = (true..true && false) { }
|
|
|
|
}
|
|
|
|
|
|
|
|
fn outside_if_and_while_expr() {
|
2022-06-25 06:08:38 -05:00
|
|
|
&let 0 = 0;
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR expected expression, found `let` statement
|
2019-05-11 08:06:36 -05:00
|
|
|
|
2022-06-25 06:08:38 -05:00
|
|
|
!let 0 = 0;
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR expected expression, found `let` statement
|
|
|
|
*let 0 = 0;
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR type `bool` cannot be dereferenced
|
|
|
|
//~| ERROR expected expression, found `let` statement
|
|
|
|
-let 0 = 0;
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR cannot apply unary operator `-` to type `bool`
|
|
|
|
//~| ERROR expected expression, found `let` statement
|
2019-05-11 08:06:36 -05:00
|
|
|
|
|
|
|
fn _check_try_binds_tighter() -> Result<(), ()> {
|
|
|
|
let 0 = 0?;
|
2020-09-02 02:40:56 -05:00
|
|
|
//~^ ERROR the `?` operator can only be applied to values that implement `Try`
|
2019-05-11 08:06:36 -05:00
|
|
|
Ok(())
|
|
|
|
}
|
2022-06-25 06:08:38 -05:00
|
|
|
(let 0 = 0)?;
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR the `?` operator can only be used in a function that returns `Result`
|
2020-09-02 02:40:56 -05:00
|
|
|
//~| ERROR the `?` operator can only be applied to values that implement `Try`
|
2022-06-25 06:08:38 -05:00
|
|
|
//~| ERROR expected expression, found `let` statement
|
2019-05-11 08:06:36 -05:00
|
|
|
|
2022-06-25 06:08:38 -05:00
|
|
|
true || let 0 = 0;
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR expected expression, found `let` statement
|
|
|
|
(true || let 0 = 0);
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR expected expression, found `let` statement
|
|
|
|
true && (true || let 0 = 0);
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR expected expression, found `let` statement
|
2019-05-11 08:06:36 -05:00
|
|
|
|
|
|
|
let mut x = true;
|
2022-06-25 06:08:38 -05:00
|
|
|
x = let 0 = 0;
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR expected expression, found `let` statement
|
2019-05-11 08:06:36 -05:00
|
|
|
|
2022-06-25 06:08:38 -05:00
|
|
|
true..(let 0 = 0);
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR expected expression, found `let` statement
|
|
|
|
..(let 0 = 0);
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR expected expression, found `let` statement
|
|
|
|
(let 0 = 0)..;
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR expected expression, found `let` statement
|
2019-05-11 08:06:36 -05:00
|
|
|
|
|
|
|
(let Range { start: _, end: _ } = true..true || false);
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
2019-06-17 00:38:26 -05:00
|
|
|
//~| ERROR mismatched types
|
2022-06-25 06:08:38 -05:00
|
|
|
//~| ERROR expected expression, found `let` statement
|
2019-05-11 08:06:36 -05:00
|
|
|
|
|
|
|
(let true = let true = true);
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
2022-06-25 06:08:38 -05:00
|
|
|
//~| ERROR expected expression, found `let` statement
|
|
|
|
//~| ERROR expected expression, found `let` statement
|
|
|
|
|
|
|
|
{
|
|
|
|
#[cfg(FALSE)]
|
|
|
|
let x = true && let y = 1;
|
|
|
|
//~^ ERROR expected expression, found `let` statement
|
|
|
|
}
|
|
|
|
|
|
|
|
#[cfg(FALSE)]
|
|
|
|
{
|
|
|
|
[1, 2, 3][let _ = ()]
|
|
|
|
//~^ ERROR expected expression, found `let` statement
|
|
|
|
}
|
2019-05-11 08:06:36 -05:00
|
|
|
|
|
|
|
// Check function tail position.
|
|
|
|
&let 0 = 0
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
2019-06-17 00:38:26 -05:00
|
|
|
//~| ERROR mismatched types
|
2022-06-25 06:08:38 -05:00
|
|
|
//~| ERROR expected expression, found `let` statement
|
2019-05-11 08:06:36 -05:00
|
|
|
}
|
2019-05-20 23:50:53 -05:00
|
|
|
|
|
|
|
// Let's make sure that `let` inside const generic arguments are considered.
|
|
|
|
fn inside_const_generic_arguments() {
|
|
|
|
struct A<const B: bool>;
|
|
|
|
impl<const B: bool> A<{B}> { const O: u32 = 5; }
|
|
|
|
|
|
|
|
if let A::<{
|
2022-07-08 05:25:50 -05:00
|
|
|
true && let 1 = 1
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
2022-07-31 20:13:16 -05:00
|
|
|
//~| ERROR expected expression, found `let` statement
|
2019-05-20 23:50:53 -05:00
|
|
|
}>::O = 5 {}
|
|
|
|
|
|
|
|
while let A::<{
|
2022-07-08 05:25:50 -05:00
|
|
|
true && let 1 = 1
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
2022-07-31 20:13:16 -05:00
|
|
|
//~| ERROR expected expression, found `let` statement
|
2019-05-20 23:50:53 -05:00
|
|
|
}>::O = 5 {}
|
|
|
|
|
|
|
|
if A::<{
|
2022-07-08 05:25:50 -05:00
|
|
|
true && let 1 = 1
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
2022-07-31 20:13:16 -05:00
|
|
|
//~| ERROR expected expression, found `let` statement
|
2019-05-20 23:50:53 -05:00
|
|
|
}>::O == 5 {}
|
|
|
|
|
|
|
|
// In the cases above we have `ExprKind::Block` to help us out.
|
|
|
|
// Below however, we would not have a block and so an implementation might go
|
|
|
|
// from visiting expressions to types without banning `let` expressions down the tree.
|
|
|
|
// This tests ensures that we are not caught by surprise should the parser
|
|
|
|
// admit non-IDENT expressions in const generic arguments.
|
|
|
|
|
|
|
|
if A::<
|
2020-10-03 13:30:32 -05:00
|
|
|
true && let 1 = 1
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
2022-07-31 20:13:16 -05:00
|
|
|
//~| ERROR expressions must be enclosed in braces
|
|
|
|
//~| ERROR expected expression, found `let` statement
|
2019-05-20 23:50:53 -05:00
|
|
|
>::O == 5 {}
|
|
|
|
}
|
2022-03-31 16:33:05 -05:00
|
|
|
|
|
|
|
fn with_parenthesis() {
|
|
|
|
let opt = Some(Some(1i32));
|
|
|
|
|
|
|
|
if (let Some(a) = opt && true) {
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
2022-07-08 05:25:50 -05:00
|
|
|
//~| ERROR expected expression, found `let` statement
|
2022-03-31 16:33:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (let Some(a) = opt) && true {
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
2022-07-08 05:25:50 -05:00
|
|
|
//~| ERROR expected expression, found `let` statement
|
2022-03-31 16:33:05 -05:00
|
|
|
}
|
|
|
|
if (let Some(a) = opt) && (let Some(b) = a) {
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR `let` expressions are not supported here
|
2022-07-08 05:25:50 -05:00
|
|
|
//~| ERROR expected expression, found `let` statement
|
|
|
|
//~| ERROR expected expression, found `let` statement
|
2022-03-31 16:33:05 -05:00
|
|
|
}
|
|
|
|
if let Some(a) = opt && (true && true) {
|
|
|
|
}
|
|
|
|
|
|
|
|
if (let Some(a) = opt && (let Some(b) = a)) && b == 1 {
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR `let` expressions are not supported here
|
2022-07-08 05:25:50 -05:00
|
|
|
//~| ERROR expected expression, found `let` statement
|
|
|
|
//~| ERROR expected expression, found `let` statement
|
2022-03-31 16:33:05 -05:00
|
|
|
}
|
|
|
|
if (let Some(a) = opt && (let Some(b) = a)) && true {
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
|
|
|
//~| ERROR `let` expressions are not supported here
|
2022-07-08 05:25:50 -05:00
|
|
|
//~| ERROR expected expression, found `let` statement
|
|
|
|
//~| ERROR expected expression, found `let` statement
|
2022-03-31 16:33:05 -05:00
|
|
|
}
|
|
|
|
if (let Some(a) = opt && (true)) && true {
|
|
|
|
//~^ ERROR `let` expressions are not supported here
|
2022-07-08 05:25:50 -05:00
|
|
|
//~| ERROR expected expression, found `let` statement
|
2022-03-31 16:33:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
if (true && (true)) && let Some(a) = opt {
|
|
|
|
}
|
|
|
|
if (true) && let Some(a) = opt {
|
|
|
|
}
|
|
|
|
if true && let Some(a) = opt {
|
|
|
|
}
|
|
|
|
|
|
|
|
let fun = || true;
|
|
|
|
if let true = (true && fun()) && (true) {
|
|
|
|
}
|
2022-06-25 06:08:38 -05:00
|
|
|
|
|
|
|
#[cfg(FALSE)]
|
|
|
|
let x = (true && let y = 1);
|
|
|
|
//~^ ERROR expected expression, found `let` statement
|
|
|
|
|
|
|
|
#[cfg(FALSE)]
|
|
|
|
{
|
|
|
|
([1, 2, 3][let _ = ()])
|
|
|
|
//~^ ERROR expected expression, found `let` statement
|
|
|
|
}
|
2022-03-31 16:33:05 -05:00
|
|
|
}
|