Skip to content

Commit 8ab24d7

Browse files
committed
Auto merge of #4650 - Mark-Simulacrum:clippy-up-lintstore-lockless, r=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
2 parents 87536f0 + b261664 commit 8ab24d7

13 files changed

+1215
-890
lines changed

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ You can use [rustup-toolchain-install-master][rtim] to do that:
147147

148148
```bash
149149
cargo install rustup-toolchain-install-master
150-
rustup-toolchain-install-master --force -n master
150+
rustup-toolchain-install-master --force -n master -c rustc-dev
151151
rustup override set master
152152
cargo test
153153
```

appveyor.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ install:
2525
- set PATH=%PATH%;C:\Users\appveyor\.cargo\bin
2626
- del rust-toolchain
2727
- cargo install -Z install-upgrade rustup-toolchain-install-master
28-
- rustup-toolchain-install-master -f -n master
28+
- rustup-toolchain-install-master -f -n master -c rustc-dev
2929
- rustup component add rustfmt --toolchain nightly & exit 0 # Format test handles missing rustfmt
3030
- rustup default master
3131
- set PATH=%PATH%;C:\Users\appveyor\.rustup\toolchains\master\bin

clippy_dev/src/lib.rs

+23-3
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ pub fn gen_lint_group_list(lints: Vec<Lint>) -> Vec<String> {
8282
if l.is_internal() || l.deprecation.is_some() {
8383
None
8484
} else {
85-
Some(format!(" {}::{},", l.module, l.name.to_uppercase()))
85+
Some(format!(" LintId::of(&{}::{}),", l.module, l.name.to_uppercase()))
8686
}
8787
})
8888
.sorted()
@@ -143,6 +143,26 @@ pub fn gen_deprecated(lints: &[Lint]) -> Vec<String> {
143143
.collect::<Vec<String>>()
144144
}
145145

146+
#[must_use]
147+
pub fn gen_register_lint_list(lints: &[Lint]) -> Vec<String> {
148+
let pre = " store.register_lints(&[".to_string();
149+
let post = " ]);".to_string();
150+
let mut inner = lints
151+
.iter()
152+
.filter_map(|l| {
153+
if !l.is_internal() && l.deprecation.is_none() {
154+
Some(format!(" &{}::{},", l.module, l.name.to_uppercase()))
155+
} else {
156+
None
157+
}
158+
})
159+
.sorted()
160+
.collect::<Vec<String>>();
161+
inner.insert(0, pre);
162+
inner.push(post);
163+
inner
164+
}
165+
146166
/// Gathers all files in `src/clippy_lints` and gathers all lints inside
147167
pub fn gather_all() -> impl Iterator<Item = Lint> {
148168
lint_files().flat_map(|f| gather_from_file(&f))
@@ -487,8 +507,8 @@ fn test_gen_lint_group_list() {
487507
Lint::new("incorrect_internal", "internal_style", "abc", None, "module_name"),
488508
];
489509
let expected = vec![
490-
" module_name::ABC,".to_string(),
491-
" module_name::SHOULD_ASSERT_EQ,".to_string(),
510+
" LintId::of(&module_name::ABC),".to_string(),
511+
" LintId::of(&module_name::SHOULD_ASSERT_EQ),".to_string(),
492512
];
493513
assert_eq!(expected, gen_lint_group_list(lints));
494514
}

clippy_dev/src/main.rs

+13-2
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ fn print_lints() {
109109
println!("there are {} lints", lint_count);
110110
}
111111

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

@@ -170,6 +171,16 @@ fn update_lints(update_mode: &UpdateMode) {
170171
)
171172
.changed;
172173

174+
file_change |= replace_region_in_file(
175+
"../clippy_lints/src/lib.rs",
176+
"begin register lints",
177+
"end register lints",
178+
false,
179+
update_mode == &UpdateMode::Change,
180+
|| gen_register_lint_list(&lint_list),
181+
)
182+
.changed;
183+
173184
file_change |= replace_region_in_file(
174185
"../clippy_lints/src/lib.rs",
175186
"begin lints modules",
@@ -183,7 +194,7 @@ fn update_lints(update_mode: &UpdateMode) {
183194
// Generate lists of lints in the clippy::all lint group
184195
file_change |= replace_region_in_file(
185196
"../clippy_lints/src/lib.rs",
186-
r#"reg.register_lint_group\("clippy::all""#,
197+
r#"store.register_group\(true, "clippy::all""#,
187198
r#"\]\);"#,
188199
false,
189200
update_mode == &UpdateMode::Change,
@@ -206,7 +217,7 @@ fn update_lints(update_mode: &UpdateMode) {
206217
for (lint_group, lints) in Lint::by_lint_group(&usable_lints) {
207218
file_change |= replace_region_in_file(
208219
"../clippy_lints/src/lib.rs",
209-
&format!("reg.register_lint_group\\(\"clippy::{}\"", lint_group),
220+
&format!("store.register_group\\(true, \"clippy::{}\"", lint_group),
210221
r#"\]\);"#,
211222
false,
212223
update_mode == &UpdateMode::Change,

0 commit comments

Comments
 (0)