Skip to content

warning: feature frontmatter is declared but not used #16747

@SimonSapin

Description

@SimonSapin

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

  1. Create nop.rs that contains fn main() {}
  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: bugS-triageStatus: This issue is waiting on initial triage.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions