Skip to content

false positive in collapsible-span-lint-calls #8798

Closed
@yonip23

Description

@yonip23

Summary

I encountered this issue while working on a pr to this project: #8769, by running cargo test --features deny-warnings,internal

Lint Name

collapsible-span-lint-calls

Reproducer

I tried this code:

span_lint_and_then(
        cx,
        RC_CLONE_IN_VEC_INIT,
        macro_call.span,
        &format!("calling `{symbol_name}::new` in `vec![elem; len]`"),
        |diag| {
            diag.note(format!("each element will point to the same `{symbol_name}` instance"))
                .help(format!(
                    "if this is intentional, consider extracting the `{symbol_name}` initialization to a variable"
                ))
                .help("or if not, initilaize each element individually");
        },
    );

I saw this happen:

error: this call is collapsible
  --> src/rc_clone_in_vec_init.rs:58:5
   |
58 | /     span_lint_and_then(
59 | |         cx,
60 | |         RC_CLONE_IN_VEC_INIT,
61 | |         macro_call.span,
...  |
69 | |         },
70 | |     );
   | |_____^ help: collapse into: `span_lint_and_help(cx, RC_CLONE_IN_VEC_INIT, macro_call.span, &format!("calling `{symbol_name}::new` in `vec![elem; len]`"), None, "or if not, initilaize each element individually")`
   |
   = note: `-D clippy::collapsible-span-lint-calls` implied by `-D clippy::internal`
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#collapsible_span_lint_calls

I expected to see this happen:
No warning should have been printed, since I'm calling .help twice, and the code in the suggestion does not include the first help section.

It happens only when I chain-call .help:

diag.help(...).help(...);

And when I'm switching to:

diag.help(...);
diag.help(...);

This warning disappears

Version

rustc 1.62.0-nightly (4c60a0ea5 2022-05-04)
binary: rustc
commit-hash: 4c60a0ea5b2385d7400df9db1ad04e96f2a4c154
commit-date: 2022-05-04
host: x86_64-unknown-linux-gnu
release: 1.62.0-nightly
LLVM version: 14.0.1

Additional Labels

No response

Metadata

Metadata

Assignees

Labels

C-bugCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't have

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions