-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Closed
rust-lang/rust
#153823Labels
C-bugCategory: bugCategory: bugS-triageStatus: This issue is waiting on initial triage.Status: This issue is waiting on initial triage.
Description
Problem
Documentation for cargo script says a script may be as simple as fn main() {}. Trying this, or another file without specifying a frontmatter, causes a warning:
warning: feature `frontmatter` is declared but not used
--> <crate attribute>:1:12
|
1 | #![feature(frontmatter)]
| ^^^^^^^^^^^
|
= note: `#[warn(unused_features)]` (part of `#[warn(unused)]`) on by default
Steps
- Create
nop.rsthat containsfn main() {} - Run
cargo +nightly -Zscript nop.rs
Possible Solution(s)
Since I never specified #![feature(frontmatter)] myself, I assume Cargo injects it. I quick search finds:
cargo/src/cargo/core/compiler/mod.rs
Lines 797 to 806 in 0c7001f
| if unit.pkg.manifest().is_embedded() { | |
| if !gctx.cli_unstable().script { | |
| anyhow::bail!( | |
| "parsing `{}` requires `-Zscript`", | |
| unit.pkg.manifest_path().display() | |
| ); | |
| } | |
| base.arg("-Z").arg("crate-attr=feature(frontmatter)"); | |
| base.arg("-Z").arg("crate-attr=allow(unused_features)"); | |
| } |
crate-attr=allow(unused_features) is also used, presumably to avoid this exact warning, but strangely it seems ineffective.
Notes
Specifiying #![allow(unused_features)] in the source file works around the issue, as does using an empty frontmatter.
Version
cargo 1.96.0-nightly (90ed291a5 2026-03-05)
release: 1.96.0-nightly
commit-hash: 90ed291a50efc459e0c380d7b455777ed41c6799
commit-date: 2026-03-05
host: x86_64-unknown-linux-gnu
libgit2: 1.9.2 (sys:0.20.4 vendored)
libcurl: 8.15.0-DEV (sys:0.4.83+curl-8.15.0 vendored ssl:OpenSSL/3.5.4)
ssl: OpenSSL 3.5.4 30 Sep 2025
os: Fedora 43.0.0 [64-bit]
And in case it’s relevant:
rustc 1.96.0-nightly (3102493c7 2026-03-12)
binary: rustc
commit-hash: 3102493c71626b5912d11d06c393b013569beb52
commit-date: 2026-03-12
host: x86_64-unknown-linux-gnu
release: 1.96.0-nightly
LLVM version: 22.1.0
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
C-bugCategory: bugCategory: bugS-triageStatus: This issue is waiting on initial triage.Status: This issue is waiting on initial triage.
Type
Fields
Give feedbackNo fields configured for issues without a type.