@@ -20,7 +20,7 @@ use syntax::ext::base;
20
20
use syntax:: ext:: base:: * ;
21
21
use syntax:: feature_gate;
22
22
use syntax:: parse:: token:: { intern, InternedString } ;
23
- use syntax:: parse:: token;
23
+ use syntax:: parse:: { self , token} ;
24
24
use syntax:: ptr:: P ;
25
25
use syntax:: ast:: AsmDialect ;
26
26
@@ -58,8 +58,17 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
58
58
return DummyResult :: expr ( sp) ;
59
59
}
60
60
61
- let mut p = cx. new_parser_from_tts ( tts) ;
62
- let mut asm = InternedString :: new ( "" ) ;
61
+ // Split the tts before the first colon, to avoid `asm!("x": y)` being
62
+ // parsed as `asm!(z)` with `z = "x": y` which is type ascription.
63
+ let first_colon = tts. iter ( ) . position ( |tt| {
64
+ match * tt {
65
+ ast:: TtToken ( _, token:: Colon ) |
66
+ ast:: TtToken ( _, token:: ModSep ) => true ,
67
+ _ => false
68
+ }
69
+ } ) . unwrap_or ( tts. len ( ) ) ;
70
+ let mut p = cx. new_parser_from_tts ( & tts[ first_colon..] ) ;
71
+ let mut asm = token:: InternedString :: new ( "" ) ;
63
72
let mut asm_str_style = None ;
64
73
let mut outputs = Vec :: new ( ) ;
65
74
let mut inputs = Vec :: new ( ) ;
@@ -79,12 +88,22 @@ pub fn expand_asm<'cx>(cx: &'cx mut ExtCtxt, sp: Span, tts: &[ast::TokenTree])
79
88
cx. span_err ( sp, "malformed inline assembly" ) ;
80
89
return DummyResult :: expr ( sp) ;
81
90
}
82
- let ( s, style) = match expr_to_string ( cx, panictry ! ( p. parse_expr( ) ) ,
91
+ // Nested parser, stop before the first colon (see above).
92
+ let mut p2 = cx. new_parser_from_tts ( & tts[ ..first_colon] ) ;
93
+ let ( s, style) = match expr_to_string ( cx, panictry ! ( p2. parse_expr( ) ) ,
83
94
"inline assembly must be a string literal" ) {
84
95
Some ( ( s, st) ) => ( s, st) ,
85
96
// let compilation continue
86
97
None => return DummyResult :: expr ( sp) ,
87
98
} ;
99
+
100
+ // This is most likely malformed.
101
+ if p2. token != token:: Eof {
102
+ let mut extra_tts = p2. parse_all_token_trees ( ) ;
103
+ extra_tts. extend ( tts[ first_colon..] . iter ( ) . cloned ( ) ) ;
104
+ p = parse:: tts_to_parser ( cx. parse_sess , extra_tts, cx. cfg ( ) ) ;
105
+ }
106
+
88
107
asm = s;
89
108
asm_str_style = Some ( style) ;
90
109
}
0 commit comments