A file containing only this correctly errors:
But this doesn't error, as it's stripped the same way #!/usr/bin/env ... (i.e. "shebang") would be:
In this third example, it also strips just the #!, breaking the attribute:
The code responsible is this:
|
/// Line won't be skipped if it represents a valid Rust syntax |
|
/// (e.g. "#![deny(missing_docs)]"). |
|
pub fn strip_shebang(input: &str) -> Option<usize> { |
|
debug_assert!(!input.is_empty()); |
|
if !input.starts_with("#!") || input.starts_with("#![") { |
It doesn't seem to account for any whitespace between the ! and [.
I believe that we should allow any characters c where c != '\n' && is_whitespace(c) after the #!, and determine whether this is a shebang, by the next character on the same line:
- if there are no non-whitespace characters, it's not a valid shebang
- if the next character is
[, this is the start of an inner comment
- otherwise, it's probably a shebang
I have no idea what to do for Rust comment syntax (#!//... and #!/*...), however.
And, of course, at the end of the day, this might be a backwards-incompatible change to make.
cc @matklad @petrochenkov
This issue has been assigned to @rcoh via this comment.
A file containing only this correctly errors:
#![bad_attribute]But this doesn't error, as it's stripped the same way
#!/usr/bin/env ...(i.e. "shebang") would be:In this third example, it also strips just the
#!, breaking the attribute:The code responsible is this:
rust/src/librustc_lexer/src/lib.rs
Lines 156 to 160 in 8045865
It doesn't seem to account for any whitespace between the
!and[.I believe that we should allow any characters
cwherec != '\n' && is_whitespace(c)after the#!, and determine whether this is a shebang, by the next character on the same line:[, this is the start of an inner commentI have no idea what to do for Rust comment syntax (
#!//...and#!/*...), however.And, of course, at the end of the day, this might be a backwards-incompatible change to make.
cc @matklad @petrochenkov
This issue has been assigned to @rcoh via this comment.