File tree 2 files changed +59
-0
lines changed
2 files changed +59
-0
lines changed Original file line number Diff line number Diff line change @@ -1430,6 +1430,23 @@ impl<'a> Parser<'a> {
1430
1430
attrs. extend ( inner_attrs. iter ( ) . cloned ( ) ) ;
1431
1431
Some ( body)
1432
1432
}
1433
+ token:: Interpolated ( ref nt) => {
1434
+ match & nt. 0 {
1435
+ token:: NtBlock ( ..) => {
1436
+ * at_end = true ;
1437
+ let ( inner_attrs, body) = self . parse_inner_attrs_and_block ( ) ?;
1438
+ attrs. extend ( inner_attrs. iter ( ) . cloned ( ) ) ;
1439
+ Some ( body)
1440
+ }
1441
+ _ => {
1442
+ let token_str = self . this_token_to_string ( ) ;
1443
+ let mut err = self . fatal ( & format ! ( "expected `;` or `{{`, found `{}`" ,
1444
+ token_str) ) ;
1445
+ err. span_label ( self . span , "expected `;` or `{`" ) ;
1446
+ return Err ( err) ;
1447
+ }
1448
+ }
1449
+ }
1433
1450
_ => {
1434
1451
let token_str = self . this_token_to_string ( ) ;
1435
1452
let mut err = self . fatal ( & format ! ( "expected `;` or `{{`, found `{}`" ,
Original file line number Diff line number Diff line change
1
+ // Copyright 2012 The Rust Project Developers. See the COPYRIGHT
2
+ // file at the top-level directory of this distribution and at
3
+ // http://rust-lang.org/COPYRIGHT.
4
+ //
5
+ // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6
+ // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7
+ // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8
+ // option. This file may not be copied, modified, or distributed
9
+ // except according to those terms.
10
+ //
11
+ // run-pass
12
+ //
13
+ // Description - ensure Interpolated blocks can act as valid function bodies
14
+ // Covered cases: free functions, struct methods, and default trait functions
15
+
16
+ macro_rules! def_fn {
17
+ ( $body: block) => {
18
+ fn bar( ) $body
19
+ }
20
+ }
21
+
22
+ trait Foo {
23
+ def_fn ! ( { println!( "foo" ) ; } ) ;
24
+ }
25
+
26
+ struct Baz { }
27
+
28
+ impl Foo for Baz { }
29
+
30
+ struct Qux { }
31
+
32
+ impl Qux {
33
+ def_fn ! ( { println!( "qux" ) ; } ) ;
34
+ }
35
+
36
+ def_fn ! ( { println!( "quux" ) ; } ) ;
37
+
38
+ pub fn main ( ) {
39
+ Baz :: bar ( ) ;
40
+ Qux :: bar ( ) ;
41
+ bar ( ) ;
42
+ }
You can’t perform that action at this time.
0 commit comments