Commit e74196a
authored
Do not trigger
Code marked with `#[automatically_derived]` attribute is macro generated
and its syntax is out of user's control. Since `ref_patterns` is a lint
for clarity, it should not be triggered for auto derived code.
Fixed by converting the lint into a late pass lint and checking the auto
derived attribute using `in_automatically_derived` utility.
changelog: Fix [`ref_patterns`] false positive: shouldn't trigger on
`#[automatically_derived]` annotated code
fixes #17198
---
Note: I converted the lint into late pass because I found an existing
utility `in_automatically_derived` that operates on the HIR, but the
util only checks for the impl blocks (which is a subset of the possible
auto derived code, I suppose).
```rust
/// Checks if the given HIR node is inside an `impl` block with the `automatically_derived`
/// attribute.
pub fn in_automatically_derived(tcx: TyCtxt<'_>, id: HirId) -> bool {
tcx.hir_parent_owner_iter(id)
.filter(|(_, node)| matches!(node, OwnerNode::Item(item) if matches!(item.kind, ItemKind::Impl(_))))
.any(|(id, _)| find_attr!(tcx, id.def_id, AutomaticallyDerived))
}
```
So, should I create a new utility for checking all possible nodes for
auto derived attribute?
Thanks!ref_patterns lint on automatically derived code (#17250)3 files changed
Lines changed: 18 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
534 | 534 | | |
535 | 535 | | |
536 | 536 | | |
537 | | - | |
538 | 537 | | |
539 | 538 | | |
540 | 539 | | |
| |||
862 | 861 | | |
863 | 862 | | |
864 | 863 | | |
| 864 | + | |
865 | 865 | | |
866 | 866 | | |
867 | 867 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | | - | |
3 | | - | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
4 | 5 | | |
5 | 6 | | |
6 | 7 | | |
| |||
29 | 30 | | |
30 | 31 | | |
31 | 32 | | |
32 | | - | |
33 | | - | |
34 | | - | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
35 | 36 | | |
| 37 | + | |
36 | 38 | | |
37 | 39 | | |
38 | 40 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
19 | 19 | | |
20 | 20 | | |
21 | 21 | | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
22 | 32 | | |
0 commit comments