diff options
| author | Alejandra González <blyxyas@gmail.com> | 2025-04-01 18:05:23 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-01 18:05:23 +0000 |
| commit | e429bdebbdbfaad7b86caa0fa394e12e2dea22f5 (patch) | |
| tree | cfffaa6c6d4cb6ca0ff84e8a98980326d78ab07d /tests | |
| parent | 46878e320a5c602c0600e0af25de5b32eb35517b (diff) | |
| parent | ffaecd008d8c2361d1043a20e06c7090f64193c3 (diff) | |
| download | rust-e429bdebbdbfaad7b86caa0fa394e12e2dea22f5.tar.gz rust-e429bdebbdbfaad7b86caa0fa394e12e2dea22f5.zip | |
Manually fulfill lint expectations for all unsafe blocks with metavars (#14501)
Fixes #14488 Context: the `macro_metavars_in_unsafe` lint looks for unsafe blocks with a macro span that then contain expressions with a root context span (which means that it is a macro with an unsafe block expanding a metavariable inside). In order to avoid emitting a warning for every single macro invocation, it will deduplicate the unsafe blocks by the span in the macro. This leads to the linked issue where because of the deduplicating and removing unsafe blocks that all belong to the same unsafe block in the macro, only one of the unsafe blocks will actually have its lint expectation fulfilled. This PR fixes that by manually fulfilling all of the unsafe blocks from all expansions before deduplicating them. changelog: [`macro_metavars_in_unsafe`]: fix unfulfilled `#[expect]` if macro is invoked multiple times
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/ui-toml/macro_metavars_in_unsafe/default/test.rs | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/tests/ui-toml/macro_metavars_in_unsafe/default/test.rs b/tests/ui-toml/macro_metavars_in_unsafe/default/test.rs index 2465fe45645..d3d5b0c103e 100644 --- a/tests/ui-toml/macro_metavars_in_unsafe/default/test.rs +++ b/tests/ui-toml/macro_metavars_in_unsafe/default/test.rs @@ -251,6 +251,16 @@ pub mod issue13219 { } } +#[macro_export] +macro_rules! issue14488 { + ($e:expr) => { + #[expect(clippy::macro_metavars_in_unsafe)] + unsafe { + $e + } + }; +} + fn main() { allow_works!(1); simple!(1); @@ -271,4 +281,10 @@ fn main() { multiple_unsafe_blocks!(1, 1, 1); unsafe_from_root_ctxt!(unsafe { 1 }); nested_macros!(1, 1); + + // These two invocations lead to two expanded unsafe blocks, each with an `#[expect]` on it. + // Only of them gets a warning, which used to result in an unfulfilled expectation for the other + // expanded unsafe block. + issue14488!(1); + issue14488!(2); } |
