Skip to content

Commit 6cad1e3

Browse files
authored
Rollup merge of rust-lang#71634 - eddyb:revert-71372, r=petrochenkov
Revert rust-lang#71372 ("Fix #! (shebang) stripping account space issue"). While rust-lang#71372 fixed some of the problems `#!`-stripping had, it introduced others: * inefficient implementation (`.chars().filter(...).collect()` on the entire input file) * this also means the length returned isn't always correct, leading to e.g. rust-lang#71471 * it ignores whitespace anywhere, stripping ` # ! ...` which isn't a valid shebang * the definition of "whitespace" it uses includes newlines, which means even `\n#\n!\n...` is stripped as a shebang (and anything matching the regex `\s*#\s*!\s*`, and not followed by `[`, really) * it's backward-incompatible but didn't go through Crater Now, rust-lang#71487 is already open and will solve all of these issues. But for running Crater, and just in case rust-lang#71487 takes a bit longer, I decided it's safer to just revert rust-lang#71372. This will also make rust-lang#71372's diff clearer, as it will start again from the original whitespace-unaware version. r? @petrochenkov
2 parents 8e025db + 4d67c8d commit 6cad1e3

File tree

2 files changed

+1
-24
lines changed

2 files changed

+1
-24
lines changed

src/librustc_lexer/src/lib.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -236,17 +236,12 @@ pub enum Base {
236236
/// (e.g. "#![deny(missing_docs)]").
237237
pub fn strip_shebang(input: &str) -> Option<usize> {
238238
debug_assert!(!input.is_empty());
239-
let s: &str = &remove_whitespace(input);
240-
if !s.starts_with("#!") || s.starts_with("#![") {
239+
if !input.starts_with("#!") || input.starts_with("#![") {
241240
return None;
242241
}
243242
Some(input.find('\n').unwrap_or(input.len()))
244243
}
245244

246-
fn remove_whitespace(s: &str) -> String {
247-
s.chars().filter(|c| !c.is_whitespace()).collect()
248-
}
249-
250245
/// Parses the first token from the provided input string.
251246
pub fn first_token(input: &str) -> Token {
252247
debug_assert!(!input.is_empty());

src/librustc_lexer/src/tests.rs

-18
Original file line numberDiff line numberDiff line change
@@ -145,22 +145,4 @@ mod tests {
145145
}),
146146
);
147147
}
148-
149-
#[test]
150-
fn test_valid_shebang() {
151-
// https://github.com/rust-lang/rust/issues/70528
152-
let input = "#!/usr/bin/rustrun";
153-
let actual = strip_shebang(input);
154-
let expected: Option<usize> = Some(18);
155-
assert_eq!(expected, actual);
156-
}
157-
158-
#[test]
159-
fn test_invalid_shebang_valid_rust_syntax() {
160-
// https://github.com/rust-lang/rust/issues/70528
161-
let input = "#! [bad_attribute]";
162-
let actual = strip_shebang(input);
163-
let expected: Option<usize> = None;
164-
assert_eq!(expected, actual);
165-
}
166148
}

0 commit comments

Comments
 (0)