Skip to content
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

multiple_unsafe_ops_per_block should not warn external macros #10259

Closed
taiki-e opened this issue Jan 30, 2023 · 2 comments · Fixed by #10260
Closed

multiple_unsafe_ops_per_block should not warn external macros #10259

taiki-e opened this issue Jan 30, 2023 · 2 comments · Fixed by #10260
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

@taiki-e
Copy link
Member

taiki-e commented Jan 30, 2023

Summary

multiple_unsafe_ops_per_block currently warns of unsafe code generated by external macros, but it should not. (there is no way for the user to fix it.)

Mentioning @Niki4tap who implemented this lint in #10206.

Lint Name

multiple_unsafe_ops_per_block

Reproducer

I tried this code:

# Cargo.toml
[package]
name = "repro"
version = "0.1.0"
edition = "2021"

[dependencies]
pin-project = "=1.0.12"
// src/lib.rs
#![warn(clippy::multiple_unsafe_ops_per_block)]

#[pin_project::pin_project(project_replace)]
struct S {
    f: (),
}

I saw this happen:

warning: this `unsafe` block contains 4 unsafe operations, expected only one
 --> src/lib.rs:3:1
  |
3 | #[pin_project::pin_project(project_replace)]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  |
note: unsafe method call occurs here
 --> src/lib.rs:3:1
  |
3 | #[pin_project::pin_project(project_replace)]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: unsafe function call occurs here
 --> src/lib.rs:3:1
  |
3 | #[pin_project::pin_project(project_replace)]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: raw pointer dereference occurs here
 --> src/lib.rs:3:1
  |
3 | #[pin_project::pin_project(project_replace)]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
note: unsafe function call occurs here
 --> src/lib.rs:3:1
  |
3 | #[pin_project::pin_project(project_replace)]
  | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#multiple_unsafe_ops_per_block
note: the lint level is defined here
 --> src/lib.rs:1:9
  |
1 | #![warn(clippy::multiple_unsafe_ops_per_block)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  = note: this warning originates in the derive macro `::pin_project::__private::__PinProjectInternalDerive` (in Nightly builds, run with -Z macro-backtrace for more info)

I expected to see this happen: no warnings

Version

rustc 1.69.0-nightly (e972bc808 2023-01-29)
binary: rustc
commit-hash: e972bc8083d5228536dfd42913c8778b6bb04c8e
commit-date: 2023-01-29
host: aarch64-apple-darwin
release: 1.69.0-nightly
LLVM version: 15.0.7

Additional Labels

No response

@taiki-e taiki-e 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 Jan 30, 2023
@Niki4tap
Copy link
Contributor

@rustbot claim

Thanks for the report!

To be honest, I didn't even consider the lint triggering in external macros, but after this report it seems so obvious, sorry for overlooking this :v

The fix should be pretty simple, I'll PR it asap.

@taiki-e
Copy link
Member Author

taiki-e commented Jan 31, 2023

Thanks for the quick fix!

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