Skip to content

Commit

Permalink
Rollup merge of rust-lang#78118 - spastorino:inline-const-followups, …
Browse files Browse the repository at this point in the history
…r=petrochenkov

Inline const followups

r? @petrochenkov

Follow ups of rust-lang#77124
  • Loading branch information
JohnTitor committed Oct 21, 2020
2 parents 83f126b + dcd2d91 commit de24210
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
2 changes: 0 additions & 2 deletions compiler/rustc_hir_pretty/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down
6 changes: 5 additions & 1 deletion compiler/rustc_parse/src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 `+=`.
Expand Down
12 changes: 12 additions & 0 deletions src/test/ui/inline-const/const-expr-macro.rs
Original file line number Diff line number Diff line change
@@ -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);
}

0 comments on commit de24210

Please sign in to comment.