Description
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:
#! [bad_attribute]
In this third example, it also strips just the #!
, breaking the attribute:
#!
[bad_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 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.
This issue has been assigned to @rcoh via this comment.