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.rs that contains fn 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:
|
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
Problem
Documentation for
cargo scriptsays a script may be as simple asfn main() {}. Trying this, or another file without specifying a frontmatter, causes a warning:Steps
nop.rsthat containsfn main() {}cargo +nightly -Zscript nop.rsPossible 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
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
And in case it’s relevant: