Skip to content

Clippy warnings on stable and non-activating doc(cfg) attribute #11

@leighmcculloch

Description

@leighmcculloch

What version are you using?

Current main (crate version 0.1.1, commit 5b99774). Reproduced with both the crate's MSRV (1.74.0) and the latest stable Rust toolchain.

What did you do?

Ran clippy against the crate:

cargo clippy --all-targets

What did you expect to see?

A clean clippy run with no warnings, and — when building docs with the doc make target — rustdoc annotations indicating which items require the alloc feature.

What did you see instead?

Three warnings, and doc(cfg(...)) hints that never activate:

  1. feature = "doc" is not a defined featuresrc/escape.rs:15 and src/unescape.rs:22 use #[cfg_attr(feature = "doc", doc(cfg(feature = "alloc")))]. No feature named doc is defined in Cargo.toml (only alloc, default, and docs), which triggers unexpected_cfgs:

    warning: unexpected `cfg` condition value: `doc`
      --> src/escape.rs:15:12
       |
    15 | #[cfg_attr(feature = "doc", doc(cfg(feature = "alloc")))]
       |            ^^^^^^^^^^-----
       |                      |
       |                      help: there is a expected value with a similar name: `"docs"`
    

    The Makefile's doc target sets RUSTDOCFLAGS="--cfg doc", which suggests the attribute was meant to key off the bare cfg(doc) predicate rather than a feature = "doc". Because the attribute never matches, rustdoc output never gains the doc(cfg(feature = "alloc")) annotation on gated items.

  2. let...else can be replaced with ?src/escape.rs:135 inside Escape::next triggers clippy::question_mark:

    warning: this `let...else` may be rewritten with the `?` operator
       --> src/escape.rs:135:17
        |
    135 | /                 let Some(b) = self.input.next() else {
    136 | |                     return None;
    137 | |                 };
    

Suggested fix

  • Change #[cfg_attr(feature = "doc", ...)] to #[cfg_attr(doc, ...)] in src/escape.rs and src/unescape.rs so the annotation activates when the Makefile's --cfg doc flag is set.
  • Enable the nightly doc_cfg feature conditionally in src/lib.rs via #![cfg_attr(doc, feature(doc_cfg))], so doc(cfg(...)) compiles on the nightly toolchain the doc target uses, without affecting stable builds.
  • Replace the let...else in src/escape.rs with let b = self.input.next()?;.

Affected files

  • src/lib.rs
  • src/escape.rs
  • src/unescape.rs

Metadata

Metadata

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions