Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#![attr] not ignored on the first line of the file #13153

Closed
SiegeLord opened this issue Mar 26, 2014 · 3 comments
Closed

#![attr] not ignored on the first line of the file #13153

SiegeLord opened this issue Mar 26, 2014 · 3 comments

Comments

@SiegeLord
Copy link
Contributor

! on the first line of Rust files is generally treated as a shebang comment. This does not appear to be the case if the first line is a valid inner attribute, e.g. this:

#![crate_id="abc"];
fn main() {}

creates an executable named 'abc'. While unlikely, '[crate_id="abc"];' is a valid program name. Either way, it's simpler to be consistent about this rule (and it makes the job easier for syntax highlighting).

I note that this was added deliberately by #13037 but I think it is a mistake, as per above.

@hyunjunekim
Copy link

Is #! comment in the rust?

@sfackler
Copy link
Member

It's the new syntax for an inner attribute.

It's not immediately clear to me why rustc would handle shebangs at all. Does anyone actually do anything like #!/usr/bin/rustc -?

@alexcrichton
Copy link
Member

Closing as working as intended.

The parser intentionally ignores shebang comments for parsing (lines starting with # are not normally a comment), but it assumes that if the first line tokenizes to #![ that it's actually an inner attribute. There's lots of discussion in #2569 about shebangs.

flip1995 pushed a commit to flip1995/rust that referenced this issue Jul 25, 2024
… r=Manishearth

Make `BindInsteadOfMap` a struct

Makes it codegen once instead of three times

changelog: none
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants