From 9dd0bb6fbc4d14bf5d6bc930b79a6989bbfca8f8 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 19 Oct 2020 16:26:13 -0300 Subject: [PATCH 1/3] Do not print braces again print_anon_const already does it --- compiler/rustc_hir_pretty/src/lib.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index 4686b4989ae52..1cd4ddad5783a 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -1138,9 +1138,7 @@ impl<'a> State<'a> { fn print_expr_anon_const(&mut self, anon_const: &hir::AnonConst) { self.ibox(INDENT_UNIT); self.s.word_space("const"); - self.s.word("{"); self.print_anon_const(anon_const); - self.s.word("}"); self.end() } From d641cb82c1e69f1a864b1b04c9bb1ae97686024d Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 19 Oct 2020 16:57:04 -0300 Subject: [PATCH 2/3] Allow NtBlock to parse on check inline const next token --- compiler/rustc_parse/src/parser/mod.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_parse/src/parser/mod.rs b/compiler/rustc_parse/src/parser/mod.rs index 7970ad36456d1..5a3789d1aaed1 100644 --- a/compiler/rustc_parse/src/parser/mod.rs +++ b/compiler/rustc_parse/src/parser/mod.rs @@ -548,7 +548,11 @@ impl<'a> Parser<'a> { fn check_inline_const(&mut self) -> bool { self.check_keyword(kw::Const) - && self.look_ahead(1, |t| t == &token::OpenDelim(DelimToken::Brace)) + && self.look_ahead(1, |t| match t.kind { + token::Interpolated(ref nt) => matches!(**nt, token::NtBlock(..)), + token::OpenDelim(DelimToken::Brace) => true, + _ => false, + }) } /// Checks to see if the next token is either `+` or `+=`. From dcd2d91a647c101c7226e594ecae23bc5fb3bb69 Mon Sep 17 00:00:00 2001 From: Santiago Pastorino Date: Mon, 19 Oct 2020 18:55:43 -0300 Subject: [PATCH 3/3] Add inline const macro test --- src/test/ui/inline-const/const-expr-macro.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 src/test/ui/inline-const/const-expr-macro.rs diff --git a/src/test/ui/inline-const/const-expr-macro.rs b/src/test/ui/inline-const/const-expr-macro.rs new file mode 100644 index 0000000000000..66b58571751ce --- /dev/null +++ b/src/test/ui/inline-const/const-expr-macro.rs @@ -0,0 +1,12 @@ +// run-pass + +#![allow(incomplete_features)] +#![feature(inline_const)] +macro_rules! do_const_block{ + ($val:block) => { const $val } +} + +fn main() { + let s = do_const_block!({ 22 }); + assert_eq!(s, 22); +}