-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Closed
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingE-hardCall for participation: This a hard problem and requires more experience or effort to work onCall for participation: This a hard problem and requires more experience or effort to work onI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveT-macrosType: Issues with macros and macro expansionType: Issues with macros and macro expansion
Description
Summary
When a proc macro emits an unsafe block with a span somewhere inside the crate using it, it triggers the undocumented_unsafe_blocks lint, even if there's documentation on it in the using crate, or if using quote, on the original unsafe block
Lint Name
undocumented_unsafe_blocks
Reproducer
I tried this code:
foo-proc crate
use proc_macro::TokenStream;
use quote::quote_spanned;
use quote::spanned::Spanned;
#[proc_macro]
pub fn foo(ts: TokenStream) -> TokenStream {
quote_spanned!(proc_macro2::TokenStream::from(ts).__span() => {
// SAFETY: Foobar
unsafe { ::core::mem::transmute::<i32, i32>(1) }
}).into()
}foo crate
#![warn(clippy::undocumented_unsafe_blocks)]
use foo_proc::foo;
fn main() {
// SAFETY: Foo
let _ = foo!(a b c);
}
I saw this happen:
warning: unsafe block missing a safety comment
--> src/main.rs:7:5
|
7 | let _ = foo!(a b c);
| ^^^^^^^^^^^^^^^^^^^^
|
note: the lint level is defined here
--> src/main.rs:1:9
|
1 | #![warn(clippy::undocumented_unsafe_blocks)]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#undocumented_unsafe_blocks
help: consider adding a safety comment
|
7 ~ // SAFETY: ...
8 + let _ = foo!(a b c);
|
I expected to see this happen:
No output. Preferably, there should be no SAFETY comment required in the user's code, as I'd expect it to be the macro's responsibility to handle its safety requirements.
Version
rustc 1.59.0-nightly (8f3238f89 2022-01-02)
binary: rustc
commit-hash: 8f3238f898163f09726c3d2b2cc9bafb09da26f3
commit-date: 2022-01-02
host: x86_64-unknown-linux-gnu
release: 1.59.0-nightly
LLVM version: 13.0.0
Additional Labels
No response
PatchMixolydic and shssoichiro
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingE-hardCall for participation: This a hard problem and requires more experience or effort to work onCall for participation: This a hard problem and requires more experience or effort to work onI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveT-macrosType: Issues with macros and macro expansionType: Issues with macros and macro expansion