Skip to content

Commit 4148bb3

Browse files
committed
fix clippy-dev update_lints
1 parent 44908a2 commit 4148bb3

File tree

3 files changed

+42
-26
lines changed

3 files changed

+42
-26
lines changed

clippy_dev/src/lib.rs

+23-7
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,32 @@ pub fn gen_deprecated<'a>(lints: impl Iterator<Item = &'a Lint>) -> Vec<String>
146146
}
147147

148148
#[must_use]
149-
pub fn gen_register_lint_list<'a>(lints: impl Iterator<Item = &'a Lint>) -> Vec<String> {
150-
let pre = " store.register_lints(&[".to_string();
151-
let post = " ]);".to_string();
152-
let mut inner = lints
149+
pub fn gen_register_lint_list<'a>(
150+
internal_lints: impl Iterator<Item = &'a Lint>,
151+
usable_lints: impl Iterator<Item = &'a Lint>,
152+
) -> Vec<String> {
153+
let header = " store.register_lints(&[".to_string();
154+
let footer = " ]);".to_string();
155+
let internal_lints = internal_lints
156+
.sorted_by_key(|l| format!(" &{}::{},", l.module, l.name.to_uppercase()))
157+
.map(|l| {
158+
format!(
159+
" #[cfg(feature = \"internal-lints\")]\n &{}::{},",
160+
l.module,
161+
l.name.to_uppercase()
162+
)
163+
})
164+
.collect::<Vec<String>>();
165+
let other_lints = usable_lints
166+
.sorted_by_key(|l| format!(" &{}::{},", l.module, l.name.to_uppercase()))
153167
.map(|l| format!(" &{}::{},", l.module, l.name.to_uppercase()))
154168
.sorted()
155169
.collect::<Vec<String>>();
156-
inner.insert(0, pre);
157-
inner.push(post);
158-
inner
170+
let mut lint_list = vec![header];
171+
lint_list.extend(internal_lints);
172+
lint_list.extend(other_lints);
173+
lint_list.push(footer);
174+
lint_list
159175
}
160176

161177
/// Gathers all files in `src/clippy_lints` and gathers all lints inside

clippy_dev/src/update_lints.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub fn run(update_mode: UpdateMode) {
8181
"end register lints",
8282
false,
8383
update_mode == UpdateMode::Change,
84-
|| gen_register_lint_list(usable_lints.iter().chain(internal_lints.iter())),
84+
|| gen_register_lint_list(internal_lints.iter(), usable_lints.iter()),
8585
)
8686
.changed;
8787

clippy_lints/src/lib.rs

+18-18
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,24 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
499499

500500
// begin register lints, do not remove this comment, it’s used in `update_lints`
501501
store.register_lints(&[
502+
#[cfg(feature = "internal-lints")]
503+
&utils::internal_lints::CLIPPY_LINTS_INTERNAL,
504+
#[cfg(feature = "internal-lints")]
505+
&utils::internal_lints::COLLAPSIBLE_SPAN_LINT_CALLS,
506+
#[cfg(feature = "internal-lints")]
507+
&utils::internal_lints::COMPILER_LINT_FUNCTIONS,
508+
#[cfg(feature = "internal-lints")]
509+
&utils::internal_lints::DEFAULT_LINT,
510+
#[cfg(feature = "internal-lints")]
511+
&utils::internal_lints::INVALID_PATHS,
512+
#[cfg(feature = "internal-lints")]
513+
&utils::internal_lints::LINT_WITHOUT_LINT_PASS,
514+
#[cfg(feature = "internal-lints")]
515+
&utils::internal_lints::MATCH_TYPE_ON_DIAGNOSTIC_ITEM,
516+
#[cfg(feature = "internal-lints")]
517+
&utils::internal_lints::OUTER_EXPN_EXPN_DATA,
518+
#[cfg(feature = "internal-lints")]
519+
&utils::internal_lints::PRODUCE_ICE,
502520
&approx_const::APPROX_CONSTANT,
503521
&arithmetic::FLOAT_ARITHMETIC,
504522
&arithmetic::INTEGER_ARITHMETIC,
@@ -902,24 +920,6 @@ pub fn register_plugins(store: &mut rustc_lint::LintStore, sess: &Session, conf:
902920
&unwrap_in_result::UNWRAP_IN_RESULT,
903921
&use_self::USE_SELF,
904922
&useless_conversion::USELESS_CONVERSION,
905-
#[cfg(feature = "internal-lints")]
906-
&utils::internal_lints::CLIPPY_LINTS_INTERNAL,
907-
#[cfg(feature = "internal-lints")]
908-
&utils::internal_lints::COLLAPSIBLE_SPAN_LINT_CALLS,
909-
#[cfg(feature = "internal-lints")]
910-
&utils::internal_lints::COMPILER_LINT_FUNCTIONS,
911-
#[cfg(feature = "internal-lints")]
912-
&utils::internal_lints::DEFAULT_LINT,
913-
#[cfg(feature = "internal-lints")]
914-
&utils::internal_lints::INVALID_PATHS,
915-
#[cfg(feature = "internal-lints")]
916-
&utils::internal_lints::LINT_WITHOUT_LINT_PASS,
917-
#[cfg(feature = "internal-lints")]
918-
&utils::internal_lints::MATCH_TYPE_ON_DIAGNOSTIC_ITEM,
919-
#[cfg(feature = "internal-lints")]
920-
&utils::internal_lints::OUTER_EXPN_EXPN_DATA,
921-
#[cfg(feature = "internal-lints")]
922-
&utils::internal_lints::PRODUCE_ICE,
923923
&vec::USELESS_VEC,
924924
&vec_resize_to_zero::VEC_RESIZE_TO_ZERO,
925925
&verbose_file_reads::VERBOSE_FILE_READS,

0 commit comments

Comments
 (0)