File tree 3 files changed +14
-13
lines changed
src/test/ui/parser/shebang
3 files changed +14
-13
lines changed Original file line number Diff line number Diff line change @@ -191,12 +191,16 @@ pub fn strip_shebang(input: &str) -> Option<usize> {
191
191
// For simplicity we consider any line starting with `#!` a shebang,
192
192
// regardless of restrictions put on shebangs by specific platforms.
193
193
if let Some ( input_tail) = input. strip_prefix ( "#!" ) {
194
- // Ok, this is a shebang but if the next non-whitespace token is `[` or maybe
195
- // a doc comment (due to `TokenKind::(Line,Block)Comment` ambiguity at lexer level),
194
+ // Ok, this is a shebang but if the next non-whitespace token is `[`,
196
195
// then it may be valid Rust code, so consider it Rust code.
197
- let next_non_whitespace_token = tokenize ( input_tail) . map ( |tok| tok. kind ) . find ( |tok|
198
- !matches ! ( tok, TokenKind :: Whitespace | TokenKind :: LineComment { .. } | TokenKind :: BlockComment { .. } )
199
- ) ;
196
+ let next_non_whitespace_token = tokenize ( input_tail) . map ( |tok| tok. kind ) . find ( |tok| {
197
+ !matches ! (
198
+ tok,
199
+ TokenKind :: Whitespace
200
+ | TokenKind :: LineComment { doc_style: None }
201
+ | TokenKind :: BlockComment { doc_style: None , .. }
202
+ )
203
+ } ) ;
200
204
if next_non_whitespace_token != Some ( TokenKind :: OpenBracket ) {
201
205
// No other choice than to consider this a shebang.
202
206
return Some ( 2 + input_tail. lines ( ) . next ( ) . unwrap_or_default ( ) . len ( ) ) ;
Original file line number Diff line number Diff line change 1
1
#! ///bin/bash
2
2
[allow(unused_variables)]
3
- //~^^ ERROR expected ` [` , found doc comment
4
-
5
- // Doc comment is misinterpreted as a whitespace (regular comment) during shebang detection.
6
- // Even if it wasn' t, it would still result in an error, just a different one.
3
+ //~^ ERROR expected item, found ` [`
Original file line number Diff line number Diff line change 1
- error: expected `[` , found doc comment `///bin/bash `
2
- --> $DIR/shebang-doc-comment.rs:1:3
1
+ error: expected item , found `[ `
2
+ --> $DIR/shebang-doc-comment.rs:2:1
3
3
|
4
- LL | #!///bin/bash
5
- | ^^^^^^^^^^^ expected `[`
4
+ LL | [allow(unused_variables)]
5
+ | ^ expected item
6
6
7
7
error: aborting due to previous error
8
8
You can’t perform that action at this time.
0 commit comments