From 171b7d62adc6f3c1a58322a8bf92deefd83a118c Mon Sep 17 00:00:00 2001 From: Gary Guo Date: Thu, 1 Dec 2022 17:54:50 +0000 Subject: [PATCH] Make inline const block `ExprWithBlock` --- compiler/rustc_ast/src/util/classify.rs | 1 + src/test/ui/inline-const/expr-with-block-err.rs | 6 ++++++ src/test/ui/inline-const/expr-with-block-err.stderr | 9 +++++++++ src/test/ui/inline-const/expr-with-block.rs | 10 ++++++++++ 4 files changed, 26 insertions(+) create mode 100644 src/test/ui/inline-const/expr-with-block-err.rs create mode 100644 src/test/ui/inline-const/expr-with-block-err.stderr create mode 100644 src/test/ui/inline-const/expr-with-block.rs diff --git a/compiler/rustc_ast/src/util/classify.rs b/compiler/rustc_ast/src/util/classify.rs index fbb4cf43a95..cdc244c1218 100644 --- a/compiler/rustc_ast/src/util/classify.rs +++ b/compiler/rustc_ast/src/util/classify.rs @@ -21,6 +21,7 @@ pub fn expr_requires_semi_to_be_stmt(e: &ast::Expr) -> bool { | ast::ExprKind::Loop(..) | ast::ExprKind::ForLoop(..) | ast::ExprKind::TryBlock(..) + | ast::ExprKind::ConstBlock(..) ) } diff --git a/src/test/ui/inline-const/expr-with-block-err.rs b/src/test/ui/inline-const/expr-with-block-err.rs new file mode 100644 index 00000000000..f7547742ddc --- /dev/null +++ b/src/test/ui/inline-const/expr-with-block-err.rs @@ -0,0 +1,6 @@ +#![feature(inline_const)] + +fn main() { + const { 2 } - const { 1 }; + //~^ ERROR mismatched types +} diff --git a/src/test/ui/inline-const/expr-with-block-err.stderr b/src/test/ui/inline-const/expr-with-block-err.stderr new file mode 100644 index 00000000000..6f7408f4e2a --- /dev/null +++ b/src/test/ui/inline-const/expr-with-block-err.stderr @@ -0,0 +1,9 @@ +error[E0308]: mismatched types + --> $DIR/expr-with-block-err.rs:4:13 + | +LL | const { 2 } - const { 1 }; + | ^ expected `()`, found integer + +error: aborting due to previous error + +For more information about this error, try `rustc --explain E0308`. diff --git a/src/test/ui/inline-const/expr-with-block.rs b/src/test/ui/inline-const/expr-with-block.rs new file mode 100644 index 00000000000..391872476fc --- /dev/null +++ b/src/test/ui/inline-const/expr-with-block.rs @@ -0,0 +1,10 @@ +// check-pass +#![feature(inline_const)] +fn main() { + match true { + true => const {} + false => () + } + const {} + () +}