diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2020-09-02 00:22:47 +0300 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2020-09-02 00:40:19 +0300 |
| commit | b1491eacfc2f2ff05ff2a1d3b557c30e15c5f81f (patch) | |
| tree | a55ad3e4f3b06403a6d6d5ebef901e161143acd1 /compiler | |
| parent | eb9e7c357e26bf41c47661720e46f4498de32b83 (diff) | |
| download | rust-b1491eacfc2f2ff05ff2a1d3b557c30e15c5f81f.tar.gz rust-b1491eacfc2f2ff05ff2a1d3b557c30e15c5f81f.zip | |
lexer: Tiny improvement to shebang detection
Lexer now discerns between regular comments and doc comments, so use that. The change only affects the choice of reported errors.
Diffstat (limited to 'compiler')
| -rw-r--r-- | compiler/rustc_lexer/src/lib.rs | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/compiler/rustc_lexer/src/lib.rs b/compiler/rustc_lexer/src/lib.rs index b7d6194cd77..44999bbe857 100644 --- a/compiler/rustc_lexer/src/lib.rs +++ b/compiler/rustc_lexer/src/lib.rs @@ -191,12 +191,16 @@ pub fn strip_shebang(input: &str) -> Option<usize> { // For simplicity we consider any line starting with `#!` a shebang, // regardless of restrictions put on shebangs by specific platforms. if let Some(input_tail) = input.strip_prefix("#!") { - // Ok, this is a shebang but if the next non-whitespace token is `[` or maybe - // a doc comment (due to `TokenKind::(Line,Block)Comment` ambiguity at lexer level), + // Ok, this is a shebang but if the next non-whitespace token is `[`, // then it may be valid Rust code, so consider it Rust code. - let next_non_whitespace_token = tokenize(input_tail).map(|tok| tok.kind).find(|tok| - !matches!(tok, TokenKind::Whitespace | TokenKind::LineComment { .. } | TokenKind::BlockComment { .. }) - ); + let next_non_whitespace_token = tokenize(input_tail).map(|tok| tok.kind).find(|tok| { + !matches!( + tok, + TokenKind::Whitespace + | TokenKind::LineComment { doc_style: None } + | TokenKind::BlockComment { doc_style: None, .. } + ) + }); if next_non_whitespace_token != Some(TokenKind::OpenBracket) { // No other choice than to consider this a shebang. return Some(2 + input_tail.lines().next().unwrap_or_default().len()); |
