Skip to content

Commit

Permalink
Auto merge of #4650 - Mark-Simulacrum:clippy-up-lintstore-lockless, r…
Browse files Browse the repository at this point in the history
…=phansch

Update clippy for latest rustc changes

Specifically, this revises the clippy integration to utilize a new
callback to register its lints, as the prior editing of lint store in
Session is no longer possible.

---

changelog: none
  • Loading branch information
bors committed Oct 24, 2019
2 parents 87536f0 + b261664 commit 8ab24d7
Show file tree
Hide file tree
Showing 13 changed files with 1,215 additions and 890 deletions.
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ You can use [rustup-toolchain-install-master][rtim] to do that:

```bash
cargo install rustup-toolchain-install-master
rustup-toolchain-install-master --force -n master
rustup-toolchain-install-master --force -n master -c rustc-dev
rustup override set master
cargo test
```
Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ install:
- set PATH=%PATH%;C:\Users\appveyor\.cargo\bin
- del rust-toolchain
- cargo install -Z install-upgrade rustup-toolchain-install-master
- rustup-toolchain-install-master -f -n master
- rustup-toolchain-install-master -f -n master -c rustc-dev
- rustup component add rustfmt --toolchain nightly & exit 0 # Format test handles missing rustfmt
- rustup default master
- set PATH=%PATH%;C:\Users\appveyor\.rustup\toolchains\master\bin
Expand Down
26 changes: 23 additions & 3 deletions clippy_dev/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub fn gen_lint_group_list(lints: Vec<Lint>) -> Vec<String> {
if l.is_internal() || l.deprecation.is_some() {
None
} else {
Some(format!(" {}::{},", l.module, l.name.to_uppercase()))
Some(format!(" LintId::of(&{}::{}),", l.module, l.name.to_uppercase()))
}
})
.sorted()
Expand Down Expand Up @@ -143,6 +143,26 @@ pub fn gen_deprecated(lints: &[Lint]) -> Vec<String> {
.collect::<Vec<String>>()
}

#[must_use]
pub fn gen_register_lint_list(lints: &[Lint]) -> Vec<String> {
let pre = " store.register_lints(&[".to_string();
let post = " ]);".to_string();
let mut inner = lints
.iter()
.filter_map(|l| {
if !l.is_internal() && l.deprecation.is_none() {
Some(format!(" &{}::{},", l.module, l.name.to_uppercase()))
} else {
None
}
})
.sorted()
.collect::<Vec<String>>();
inner.insert(0, pre);
inner.push(post);
inner
}

/// Gathers all files in `src/clippy_lints` and gathers all lints inside
pub fn gather_all() -> impl Iterator<Item = Lint> {
lint_files().flat_map(|f| gather_from_file(&f))
Expand Down Expand Up @@ -487,8 +507,8 @@ fn test_gen_lint_group_list() {
Lint::new("incorrect_internal", "internal_style", "abc", None, "module_name"),
];
let expected = vec![
" module_name::ABC,".to_string(),
" module_name::SHOULD_ASSERT_EQ,".to_string(),
" LintId::of(&module_name::ABC),".to_string(),
" LintId::of(&module_name::SHOULD_ASSERT_EQ),".to_string(),
];
assert_eq!(expected, gen_lint_group_list(lints));
}
15 changes: 13 additions & 2 deletions clippy_dev/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ fn print_lints() {
println!("there are {} lints", lint_count);
}

#[allow(clippy::too_many_lines)]
fn update_lints(update_mode: &UpdateMode) {
let lint_list: Vec<Lint> = gather_all().collect();

Expand Down Expand Up @@ -170,6 +171,16 @@ fn update_lints(update_mode: &UpdateMode) {
)
.changed;

file_change |= replace_region_in_file(
"../clippy_lints/src/lib.rs",
"begin register lints",
"end register lints",
false,
update_mode == &UpdateMode::Change,
|| gen_register_lint_list(&lint_list),
)
.changed;

file_change |= replace_region_in_file(
"../clippy_lints/src/lib.rs",
"begin lints modules",
Expand All @@ -183,7 +194,7 @@ fn update_lints(update_mode: &UpdateMode) {
// Generate lists of lints in the clippy::all lint group
file_change |= replace_region_in_file(
"../clippy_lints/src/lib.rs",
r#"reg.register_lint_group\("clippy::all""#,
r#"store.register_group\(true, "clippy::all""#,
r#"\]\);"#,
false,
update_mode == &UpdateMode::Change,
Expand All @@ -206,7 +217,7 @@ fn update_lints(update_mode: &UpdateMode) {
for (lint_group, lints) in Lint::by_lint_group(&usable_lints) {
file_change |= replace_region_in_file(
"../clippy_lints/src/lib.rs",
&format!("reg.register_lint_group\\(\"clippy::{}\"", lint_group),
&format!("store.register_group\\(true, \"clippy::{}\"", lint_group),
r#"\]\);"#,
false,
update_mode == &UpdateMode::Change,
Expand Down
Loading

0 comments on commit 8ab24d7

Please sign in to comment.