Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
yonip23 opened this issue May 7, 2022 · 1 comment · Fixed by #9028
Closed

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

yonip23 opened this issue May 7, 2022 · 1 comment · Fixed by #9028
Assignees
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@yonip23
Copy link
Contributor

yonip23 commented May 7, 2022

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

@yonip23 yonip23 added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels May 7, 2022
@yonip23 yonip23 changed the title [[maybe]] false positive in collapsible-span-lint-calls false positive in collapsible-span-lint-calls May 7, 2022
@kyoto7250
Copy link
Contributor

@rustbot claim

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants