-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Closed
Labels
C-bugCategory: bugCategory: bugS-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.Z-scriptNightly: cargo scriptNightly: cargo script
Description
Rustc has logic to detect and ignore shebangs
https://github.com/rust-lang/rust/blob/6171d944aea415a3023d4262e0895aa3b18c771f/compiler/rustc_lexer/src/lib.rs#L255-L278
Cargo needs something similar for knowing whether we should look for a frontmatter
cargo/src/cargo/util/toml/embedded.rs
Lines 195 to 215 in e3fa31e
// See rust-lang/rust's compiler/rustc_lexer/src/lib.rs's `strip_shebang` | |
// Shebang must start with `#!` literally, without any preceding whitespace. | |
// For simplicity we consider any line starting with `#!` a shebang, | |
// regardless of restrictions put on shebangs by specific platforms. | |
if let Some(rest) = source.content.strip_prefix("#!") { | |
// Ok, this is a shebang but if the next non-whitespace token is `[`, | |
// then it may be valid Rust code, so consider it Rust code. | |
if rest.trim_start().starts_with('[') { | |
return Ok(source); | |
} | |
// No other choice than to consider this a shebang. | |
let newline_end = source | |
.content | |
.find('\n') | |
.map(|pos| pos + 1) | |
.unwrap_or(source.content.len()); | |
let (shebang, content) = source.content.split_at(newline_end); | |
source.shebang = Some(shebang); | |
source.content = content; | |
} |
These differ and we need to decide how we want to reconcile these
Originally reported in #14857 (comment)
Metadata
Metadata
Assignees
Labels
C-bugCategory: bugCategory: bugS-needs-designStatus: Needs someone to work further on the design for the feature or fix. NOT YET accepted.Status: Needs someone to work further on the design for the feature or fix. NOT YET accepted.Z-scriptNightly: cargo scriptNightly: cargo script