Skip to content

Commit

Permalink
Auto merge of #10443 - dtolnay-contrib:formerids, r=llogiq
Browse files Browse the repository at this point in the history
Include former name of renamed lints in lints.json

I am interested in having a programmatic way to process [`RENAMED_LINTS`](https://github.com/rust-lang/rust-clippy/blob/113c704d225c63c1a0eec29cfa9478b7537e7d73/clippy_lints/src/renamed_lints.rs#L4) for dtolnay/noisy-clippy#15.

<details>
<summary>lints.json diff</summary>

```diff
60c60,63
<     }
---
>     },
>     "former_ids": [
>       "almost_complete_letter_range"
>     ]
300c303,306
<     }
---
>     },
>     "former_ids": [
>       "option_and_then_some"
>     ]
330c336,340
<     }
---
>     },
>     "former_ids": [
>       "block_in_if_condition_expr",
>       "block_in_if_condition_stmt"
>     ]
450c460,463
<     }
---
>     },
>     "former_ids": [
>       "box_vec"
>     ]
945c958,961
<     }
---
>     },
>     "former_ids": [
>       "cyclomatic_complexity"
>     ]
1335c1351,1354
<     }
---
>     },
>     "former_ids": [
>       "derive_hash_xor_eq"
>     ]
1365c1384,1387
<     }
---
>     },
>     "former_ids": [
>       "disallowed_method"
>     ]
1380c1402,1405
<     }
---
>     },
>     "former_ids": [
>       "blacklisted_name"
>     ]
1410c1435,1438
<     }
---
>     },
>     "former_ids": [
>       "disallowed_type"
>     ]
1890c1918,1922
<     }
---
>     },
>     "former_ids": [
>       "option_expect_used",
>       "result_expect_used"
>     ]
3150c3182,3185
<     }
---
>     },
>     "former_ids": [
>       "zero_width_space"
>     ]
4185c4220,4225
<     }
---
>     },
>     "former_ids": [
>       "option_map_unwrap_or",
>       "option_map_unwrap_or_else",
>       "result_map_unwrap_or_else"
>     ]
4290c4330,4333
<     }
---
>     },
>     "former_ids": [
>       "if_let_some_result"
>     ]
4710c4753,4756
<     }
---
>     },
>     "former_ids": [
>       "eval_order_dependence"
>     ]
4755c4801,4804
<     }
---
>     },
>     "former_ids": [
>       "stutter"
>     ]
5055c5104,5107
<     }
---
>     },
>     "former_ids": [
>       "ref_in_deref"
>     ]
5400c5452,5455
<     }
---
>     },
>     "former_ids": [
>       "new_without_default_derive"
>     ]
5820c5875,5878
<     }
---
>     },
>     "former_ids": [
>       "logic_bug"
>     ]
6330c6388,6391
<     }
---
>     },
>     "former_ids": [
>       "to_string_in_display"
>     ]
6525c6586,6589
<     }
---
>     },
>     "former_ids": [
>       "const_static_lifetime"
>     ]
7065c7129,7132
<     }
---
>     },
>     "former_ids": [
>       "single_char_push_str"
>     ]
8820c8887,8891
<     }
---
>     },
>     "former_ids": [
>       "option_unwrap_used",
>       "result_unwrap_used"
>     ]
8925c8996,8999
<     }
---
>     },
>     "former_ids": [
>       "identity_conversion"
>     ]
```
</details>

changelog: Include `"former_ids": […]` for renamed lints in [lints.json](https://rust-lang.github.io/rust-clippy/master/lints.json)
  • Loading branch information
bors committed Mar 4, 2023
2 parents 113c704 + cc6180c commit d423703
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion clippy_lints/src/utils/internal_lints/metadata_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use rustc_session::{declare_tool_lint, impl_lint_pass};
use rustc_span::symbol::Ident;
use rustc_span::{sym, Loc, Span, Symbol};
use serde::{ser::SerializeStruct, Serialize, Serializer};
use std::collections::BinaryHeap;
use std::collections::{BTreeSet, BinaryHeap};
use std::fmt;
use std::fmt::Write as _;
use std::fs::{self, OpenOptions};
Expand Down Expand Up @@ -264,6 +264,9 @@ struct LintMetadata {
/// This field is only used in the output and will only be
/// mapped shortly before the actual output.
applicability: Option<ApplicabilityInfo>,
/// All the past names of lints which have been renamed.
#[serde(skip_serializing_if = "BTreeSet::is_empty")]
former_ids: BTreeSet<String>,
}

impl LintMetadata {
Expand All @@ -283,6 +286,7 @@ impl LintMetadata {
version,
docs,
applicability: None,
former_ids: BTreeSet::new(),
}
}
}
Expand Down Expand Up @@ -901,6 +905,7 @@ fn collect_renames(lints: &mut Vec<LintMetadata>) {
if name == lint_name;
if let Some(past_name) = k.strip_prefix(CLIPPY_LINT_GROUP_PREFIX);
then {
lint.former_ids.insert(past_name.to_owned());
writeln!(collected, "* `{past_name}`").unwrap();
names.push(past_name.to_string());
}
Expand Down

0 comments on commit d423703

Please sign in to comment.