Skip to content

Update clippy for latest rustc changes #4650

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Oct 24, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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