rust-lang / rust-lang/rust-clippy

regression: needless_continue triggers within a macro

Open
#16,175 3 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug I-false-positive
Dominant language
Rust
Stars
13.5k
Forks
2.2k
Avg merge
2d 10h
Merged PRs (30d)
32

Description

Summary

I am using darling which has macros that apparently trigger the clippy::needless_continue lint. However, this is hidden in the current version clippy 0.1.91 (ed61e7d7e2 2025-11-07), but is reported in clippy 0.1.92 (f3f12444a0 2025-11-09). If I read the docs this should be a false positive. Or was this was intentionally changed?

Lint Name

needless_continue

Reproducer

I tried this code:

#[derive(darling::FromVariant)]
#[darling(attributes(can))]
pub struct CanDecodeVariant {
    ident: syn::Ident,
}

which expands to:

#[automatically_derived]
#[allow(clippy::manual_unwrap_or_default)]
impl ::darling::FromVariant for Foo {
    fn from_variant(__variant: &::darling::export::syn::Variant) -> ::darling::Result<Self> {
        let mut __errors = ::darling::Error::accumulator();
        use ::darling::ToTokens;
        for __attr in &__variant.attrs {
            match ::darling::export::ToString::to_string(&__attr.path().clone().into_token_stream())
                .as_str()
            {
                "foo" => match ::darling::util::parse_attribute_to_meta_list(__attr) {
                    ::darling::export::Ok(__data) => {
                        match ::darling::export::NestedMeta::parse_meta_list(__data.tokens) {
                            ::darling::export::Ok(ref __items) => {
                                if __items.is_empty() {
                                    continue;
                                }
                                for __item in __items {
                                    match *__item {
                                        ::darling::export::NestedMeta::Meta(ref __inner) => {
                                            let __name =
                                                ::darling::util::path_to_string(__inner.path());
                                            match __name.as_str() {
                                                __other => {
                                                    __errors.push(
                                                        ::darling::Error::unknown_field(__other)
                                                            .with_span(__inner),
                                                    );
                                                }
                                            }
                                        }
                                        ::darling::export::NestedMeta::Lit(ref __inner) => {
                                            __errors.push(
                                                ::darling::Error::unsupported_format("literal")
                                                    .with_span(__inner),
                                            );
                                        }
                                    }
                                }
                            }
                            ::darling::export::Err(__err) => {
                                __errors.push(__err.into());
                            }
                        }
                    }
                    ::darling::export::Err(__err) => {
                        __errors.push(__err);
                    }
                },
                _ => continue,
            }
        }
        __errors.finish()?;
        ::darling::export::Ok(Self {
            ident: __variant.ident.clone(),
        })
    }
}

I saw this happen when running cargo +beta clippy:

warning: this `continue` expression is redundant
  --> datatypes/src/lib.rs:82:10
   |
82 | #[derive(darling::FromVariant)]
   |          ^^^^^^^^^^^^^^^^^^^^
   |
   = help: consider dropping the `continue` expression
   = help: for further information visit https://rust-lang.github.io/rust-clippy/beta/index.html#needless_continue
   = note: `-W clippy::needless-continue` implied by `-W clippy::pedantic`
   = help: to override `-W clippy::pedantic` add `#[allow(clippy::needless_continue)]`
   = note: this warning originates in the derive macro `darling::FromVariant` (in Nightly builds, run with -Z macro-backtrace for more info)

When I run cargo clippy, it doesn't report this error though.

Version
ustc 1.92.0-beta.3 (f3f12444a 2025-11-09)
binary: rustc
commit-hash: f3f12444a017add0468f683f3a10656d29438a05
commit-date: 2025-11-09
host: x86_64-apple-darwin
release: 1.92.0-beta.3
LLVM version: 21.1.3
Additional Labels

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the warning from datatypes/src/lib.rs with cargo +beta clippy, using the needless_continue lint and the darling::FromVariant expansion shown in the report. Start by tracing needless_continue's macro-expansion handling and compare the beta behavior with the current clippy behavior. Done means the generated macro code is not falsely warned about while ordinary needless continue cases remain detected.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers, devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.