Skip to content

Commit fdb8752

Browse files
committed
cleanup shebang handling in the lexer
1 parent 546cb21 commit fdb8752

File tree

1 file changed

+5
-11
lines changed
  • src/libsyntax/parse/lexer

1 file changed

+5
-11
lines changed

src/libsyntax/parse/lexer/mod.rs

+5-11
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use crate::ast::{self, Ident};
2-
use crate::source_map::{SourceMap, FilePathMapping};
32
use crate::parse::{token, ParseSess};
43
use crate::symbol::Symbol;
54

65
use errors::{Applicability, FatalError, Diagnostic, DiagnosticBuilder};
7-
use syntax_pos::{BytePos, CharPos, Pos, Span, NO_EXPANSION};
6+
use syntax_pos::{BytePos, Pos, Span, NO_EXPANSION};
87
use core::unicode::property::Pattern_White_Space;
98

109
use std::borrow::Cow;
@@ -667,14 +666,9 @@ impl<'a> StringReader<'a> {
667666
return None;
668667
}
669668

670-
// I guess this is the only way to figure out if
671-
// we're at the beginning of the file...
672-
let smap = SourceMap::new(FilePathMapping::empty());
673-
smap.files.borrow_mut().source_files.push(self.source_file.clone());
674-
let loc = smap.lookup_char_pos_adj(self.pos);
675-
debug!("Skipping a shebang");
676-
if loc.line == 1 && loc.col == CharPos(0) {
677-
// FIXME: Add shebang "token", return it
669+
let is_beginning_of_file = self.pos == self.source_file.start_pos;
670+
if is_beginning_of_file {
671+
debug!("Skipping a shebang");
678672
let start = self.pos;
679673
while !self.ch_is('\n') && !self.is_eof() {
680674
self.bump();
@@ -1911,7 +1905,7 @@ mod tests {
19111905

19121906
use crate::ast::{Ident, CrateConfig};
19131907
use crate::symbol::Symbol;
1914-
use crate::source_map::SourceMap;
1908+
use crate::source_map::{SourceMap, FilePathMapping};
19151909
use crate::feature_gate::UnstableFeatures;
19161910
use crate::parse::token;
19171911
use crate::diagnostics::plugin::ErrorMap;

0 commit comments

Comments
 (0)