Auto merge of #10443 - dtolnay-contrib:formerids, r=llogiq

Include former name of renamed lints in lints.json

I am interested in having a programmatic way to process [`RENAMED_LINTS`](113c704d22/clippy_lints/src/renamed_lints.rs (L4)) for https://github.com/dtolnay/noisy-clippy/issues/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)
This commit is contained in:
bors 2023-03-04 16:08:09 +00:00
commit d423703aba

View file

@ -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};
@ -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 {
@ -283,6 +286,7 @@ impl LintMetadata {
version,
docs,
applicability: None,
former_ids: BTreeSet::new(),
}
}
}
@ -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());
}