@@ -239,21 +239,18 @@ pub enum Base {
239239/// but shebang isn't a part of rust syntax.
240240pub fn strip_shebang ( input : & str ) -> Option < usize > {
241241 // Shebang must start with `#!` literally, without any preceding whitespace.
242- if input. starts_with ( "#!" ) {
243- let input_tail = & input[ 2 ..] ;
244- // Shebang must have something non-whitespace after `#!` on the first line.
245- let first_line_tail = input_tail. lines ( ) . next ( ) ?;
246- if first_line_tail. contains ( |c| !is_whitespace ( c) ) {
247- // Ok, this is a shebang but if the next non-whitespace token is `[` or maybe
248- // a doc comment (due to `TokenKind::(Line,Block)Comment` ambiguity at lexer level),
249- // then it may be valid Rust code, so consider it Rust code.
250- let next_non_whitespace_token = tokenize ( input_tail) . map ( |tok| tok. kind ) . filter ( |tok|
251- !matches ! ( tok, TokenKind :: Whitespace | TokenKind :: LineComment | TokenKind :: BlockComment { .. } )
252- ) . next ( ) ;
253- if next_non_whitespace_token != Some ( TokenKind :: OpenBracket ) {
254- // No other choice than to consider this a shebang.
255- return Some ( 2 + first_line_tail. len ( ) ) ;
256- }
242+ // For simplicity we consider any line starting with `#!` a shebang,
243+ // regardless of restrictions put on shebangs by specific platforms.
244+ if let Some ( input_tail) = input. strip_prefix ( "#!" ) {
245+ // Ok, this is a shebang but if the next non-whitespace token is `[` or maybe
246+ // a doc comment (due to `TokenKind::(Line,Block)Comment` ambiguity at lexer level),
247+ // then it may be valid Rust code, so consider it Rust code.
248+ let next_non_whitespace_token = tokenize ( input_tail) . map ( |tok| tok. kind ) . find ( |tok|
249+ !matches ! ( tok, TokenKind :: Whitespace | TokenKind :: LineComment | TokenKind :: BlockComment { .. } )
250+ ) ;
251+ if next_non_whitespace_token != Some ( TokenKind :: OpenBracket ) {
252+ // No other choice than to consider this a shebang.
253+ return Some ( 2 + input_tail. lines ( ) . next ( ) . unwrap_or_default ( ) . len ( ) ) ;
257254 }
258255 }
259256 None
0 commit comments