@@ -179,21 +179,18 @@ pub enum Base {
179
179
/// but shebang isn't a part of rust syntax.
180
180
pub fn strip_shebang ( input : & str ) -> Option < usize > {
181
181
// Shebang must start with `#!` literally, without any preceding whitespace.
182
- if input. starts_with ( "#!" ) {
183
- let input_tail = & input[ 2 ..] ;
184
- // Shebang must have something non-whitespace after `#!` on the first line.
185
- let first_line_tail = input_tail. lines ( ) . next ( ) ?;
186
- if first_line_tail. contains ( |c| !is_whitespace ( c) ) {
187
- // Ok, this is a shebang but if the next non-whitespace token is `[` or maybe
188
- // a doc comment (due to `TokenKind::(Line,Block)Comment` ambiguity at lexer level),
189
- // then it may be valid Rust code, so consider it Rust code.
190
- let next_non_whitespace_token = tokenize ( input_tail) . map ( |tok| tok. kind ) . find ( |tok|
191
- !matches ! ( tok, TokenKind :: Whitespace | TokenKind :: LineComment | TokenKind :: BlockComment { .. } )
192
- ) ;
193
- if next_non_whitespace_token != Some ( TokenKind :: OpenBracket ) {
194
- // No other choice than to consider this a shebang.
195
- return Some ( 2 + first_line_tail. len ( ) ) ;
196
- }
182
+ // For simplicity we consider any line starting with `#!` a shebang,
183
+ // regardless of restrictions put on shebangs by specific platforms.
184
+ if let Some ( input_tail) = input. strip_prefix ( "#!" ) {
185
+ // Ok, this is a shebang but if the next non-whitespace token is `[` or maybe
186
+ // a doc comment (due to `TokenKind::(Line,Block)Comment` ambiguity at lexer level),
187
+ // then it may be valid Rust code, so consider it Rust code.
188
+ let next_non_whitespace_token = tokenize ( input_tail) . map ( |tok| tok. kind ) . find ( |tok|
189
+ !matches ! ( tok, TokenKind :: Whitespace | TokenKind :: LineComment | TokenKind :: BlockComment { .. } )
190
+ ) ;
191
+ if next_non_whitespace_token != Some ( TokenKind :: OpenBracket ) {
192
+ // No other choice than to consider this a shebang.
193
+ return Some ( 2 + input_tail. lines ( ) . next ( ) . unwrap_or_default ( ) . len ( ) ) ;
197
194
}
198
195
}
199
196
None
0 commit comments