File tree Expand file tree Collapse file tree 3 files changed +61
-4
lines changed
compiler/rustc_ast/src/util Expand file tree Collapse file tree 3 files changed +61
-4
lines changed Original file line number Diff line number Diff line change 22
33// Predicates on exprs and stmts that the pretty-printer and parser use
44
5- use crate :: ast;
5+ use crate :: { ast, token :: Delimiter } ;
66
77/// Does this expression require a semicolon to be treated
88/// as a statement? The negation of this: 'can this expression
@@ -59,8 +59,12 @@ pub fn expr_trailing_brace(mut expr: &ast::Expr) -> Option<&ast::Expr> {
5959 | While ( ..)
6060 | ConstBlock ( _) => break Some ( expr) ,
6161
62- // FIXME: These can end in `}`, but changing these would break stable code.
63- InlineAsm ( _) | OffsetOf ( _, _) | MacCall ( _) | IncludedBytes ( _) | FormatArgs ( _) => {
62+ MacCall ( mac) => {
63+ break ( mac. args . delim == Delimiter :: Brace ) . then_some ( expr) ;
64+ }
65+
66+ InlineAsm ( _) | OffsetOf ( _, _) | IncludedBytes ( _) | FormatArgs ( _) => {
67+ // These should have been denied pre-expansion.
6468 break None ;
6569 }
6670
Original file line number Diff line number Diff line change @@ -161,4 +161,31 @@ fn q() {
161161 } ;
162162}
163163
164+ fn r ( ) {
165+ use std:: arch:: asm;
166+
167+ let ok = asm ! ( " nop " ) else { return ; } ;
168+
169+ let bad = asm ! { " nop " } else { return ; } ;
170+ //~^ ERROR right curly brace `}` before `else` in a `let...else` statement not allowed
171+ }
172+
173+ fn s ( ) {
174+ macro_rules! a {
175+ ( ) => { { } }
176+ }
177+
178+ macro_rules! b {
179+ ( 1 ) => {
180+ let x = a!( ) else { return ; } ;
181+ } ;
182+ ( 2 ) => {
183+ let x = a! { } else { return ; } ;
184+ //~^ ERROR right curly brace `}` before `else` in a `let...else` statement not allowed
185+ } ;
186+ }
187+
188+ b ! ( 1 ) ; b ! ( 2 ) ;
189+ }
190+
164191fn main ( ) { }
Original file line number Diff line number Diff line change @@ -228,5 +228,31 @@ LL | x
228228LL ~ }) else {
229229 |
230230
231- error: aborting due to 17 previous errors
231+ error: right curly brace `}` before `else` in a `let...else` statement not allowed
232+ --> $DIR/bad-let-else-statement.rs:169:28
233+ |
234+ LL | let bad = asm! {" nop "} else { return; };
235+ | ^
236+ |
237+ help: wrap the expression in parentheses
238+ |
239+ LL | let bad = (asm! {" nop "}) else { return; };
240+ | + +
241+
242+ error: right curly brace `}` before `else` in a `let...else` statement not allowed
243+ --> $DIR/bad-let-else-statement.rs:183:25
244+ |
245+ LL | let x = a! {} else { return; };
246+ | ^
247+ ...
248+ LL | b!(1); b!(2);
249+ | ----- in this macro invocation
250+ |
251+ = note: this error originates in the macro `b` (in Nightly builds, run with -Z macro-backtrace for more info)
252+ help: wrap the expression in parentheses
253+ |
254+ LL | let x = (a! {}) else { return; };
255+ | + +
256+
257+ error: aborting due to 19 previous errors
232258
You can’t perform that action at this time.
0 commit comments