This repository was archived by the owner on May 28, 2025. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +14
-13
lines changed
src/test/ui/parser/shebang Expand file tree Collapse file tree 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> {
191191 // For simplicity we consider any line starting with `#!` a shebang,
192192 // regardless of restrictions put on shebangs by specific platforms.
193193 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 `[`,
196195 // 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+ } ) ;
200204 if next_non_whitespace_token != Some ( TokenKind :: OpenBracket ) {
201205 // No other choice than to consider this a shebang.
202206 return Some ( 2 + input_tail. lines ( ) . next ( ) . unwrap_or_default ( ) . len ( ) ) ;
Original file line number Diff line number Diff line change 11#! ///bin/bash
22[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
33 |
4- LL | #!///bin/bash
5- | ^^^^^^^^^^^ expected `[`
4+ LL | [allow(unused_variables)]
5+ | ^ expected item
66
77error: aborting due to previous error
88
You can’t perform that action at this time.
0 commit comments