Skip to content

Commit 77af56d

Browse files
committed
Auto merge of #7525 - xFrednet:7172-update-define-conf-macro, r=flip1995
Updated `define_Conf!` to support multi-line doc comments Updated the `define_Conf!` macro to support multi-line doc comments for readability. This also enables configuration documentation to have multiple paragraphs. I've also added the `metadata-collector-lint` feature to the CI build and testing tasks. (I would think that we want this, now that we officially switched over) --- Now a small informal explanation what this PR changes (just for fun): * *Once upon a time there was a monster. It was handsome, supportive and happy to dig through the best source code it has ever seen. Spanning over hundreds of lines and reading over complete crates, it was purely marvels!* *However, there was one region in its territory that wasn't clean and well formatted like the rest. That was the mighty `define_Conf` macro. The monster would have cleaned it up a long time ago but, the previous ruler of this kingdom a powerful Python script was prohibiting it. But now that the old king was slain in the great battle of rust-1.54.0, everything was possible again. Our lovely monster was now able to grab its cleaning equipment and get some nice formatting into the now unprotected area.* *Said and done! Let this day go down in history!* (I'll be the first to admit, that I'm a bit lost today. And I'm also procrastinating on some other discussions where I have some catching up to do... Oh, well, this was fun) --- changelog: none r? `@flip1995`
2 parents 4e760b6 + 51f94ad commit 77af56d

File tree

4 files changed

+113
-42
lines changed

4 files changed

+113
-42
lines changed

.github/workflows/clippy.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,13 @@ jobs:
4949
echo "LD_LIBRARY_PATH=${SYSROOT}/lib${LD_LIBRARY_PATH+:${LD_LIBRARY_PATH}}" >> $GITHUB_ENV
5050
5151
- name: Build
52-
run: cargo build --features deny-warnings,internal-lints
52+
run: cargo build --features deny-warnings,internal-lints,metadata-collector-lint
5353

5454
- name: Test
55-
run: cargo test --features deny-warnings,internal-lints
55+
run: cargo test --features deny-warnings,internal-lints,metadata-collector-lint
5656

5757
- name: Test clippy_lints
58-
run: cargo test --features deny-warnings,internal-lints
58+
run: cargo test --features deny-warnings,internal-lints,metadata-collector-lint
5959
working-directory: clippy_lints
6060

6161
- name: Test rustc_tools_util

.github/workflows/clippy_bors.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,13 +112,13 @@ jobs:
112112
echo "$SYSROOT/bin" >> $GITHUB_PATH
113113
114114
- name: Build
115-
run: cargo build --features deny-warnings,internal-lints
115+
run: cargo build --features deny-warnings,internal-lints,metadata-collector-lint
116116

117117
- name: Test
118-
run: cargo test --features deny-warnings,internal-lints
118+
run: cargo test --features deny-warnings,internal-lints,metadata-collector-lint
119119

120120
- name: Test clippy_lints
121-
run: cargo test --features deny-warnings,internal-lints
121+
run: cargo test --features deny-warnings,internal-lints,metadata-collector-lint
122122
working-directory: clippy_lints
123123

124124
- name: Test rustc_tools_util

clippy_lints/src/utils/conf.rs

Lines changed: 100 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ impl TryConf {
3636
/// See (rust-clippy#7172)
3737
macro_rules! define_Conf {
3838
($(
39-
#[doc = $doc:literal]
39+
$(#[doc = $doc:literal])+
4040
$(#[conf_deprecated($dep:literal)])?
4141
($name:ident: $ty:ty = $default:expr),
4242
)*) => {
4343
/// Clippy lint configuration
4444
pub struct Conf {
45-
$(#[doc = $doc] pub $name: $ty,)*
45+
$($(#[doc = $doc])+ pub $name: $ty,)*
4646
}
4747

4848
mod defaults {
@@ -119,7 +119,7 @@ macro_rules! define_Conf {
119119
stringify!($name),
120120
stringify!($ty),
121121
format!("{:?}", super::defaults::$name()),
122-
$doc,
122+
concat!($($doc, '\n',)*),
123123
deprecation_reason,
124124
)
125125
},
@@ -132,18 +132,30 @@ macro_rules! define_Conf {
132132

133133
// N.B., this macro is parsed by util/lintlib.py
134134
define_Conf! {
135-
/// Lint: ENUM_VARIANT_NAMES, LARGE_TYPES_PASSED_BY_VALUE, TRIVIALLY_COPY_PASS_BY_REF, UNNECESSARY_WRAPS, UPPER_CASE_ACRONYMS, WRONG_SELF_CONVENTION. Suppress lints whenever the suggested change would cause breakage for other crates.
135+
/// Lint: ENUM_VARIANT_NAMES, LARGE_TYPES_PASSED_BY_VALUE, TRIVIALLY_COPY_PASS_BY_REF, UNNECESSARY_WRAPS, UPPER_CASE_ACRONYMS, WRONG_SELF_CONVENTION.
136+
///
137+
/// Suppress lints whenever the suggested change would cause breakage for other crates.
136138
(avoid_breaking_exported_api: bool = true),
137-
/// Lint: MANUAL_STR_REPEAT, CLONED_INSTEAD_OF_COPIED, REDUNDANT_FIELD_NAMES, REDUNDANT_STATIC_LIFETIMES, FILTER_MAP_NEXT, CHECKED_CONVERSIONS, MANUAL_RANGE_CONTAINS, USE_SELF, MEM_REPLACE_WITH_DEFAULT, MANUAL_NON_EXHAUSTIVE, OPTION_AS_REF_DEREF, MAP_UNWRAP_OR, MATCH_LIKE_MATCHES_MACRO, MANUAL_STRIP, MISSING_CONST_FOR_FN, UNNESTED_OR_PATTERNS, FROM_OVER_INTO, PTR_AS_PTR, IF_THEN_SOME_ELSE_NONE. The minimum rust version that the project supports
139+
/// Lint: MANUAL_STR_REPEAT, CLONED_INSTEAD_OF_COPIED, REDUNDANT_FIELD_NAMES, REDUNDANT_STATIC_LIFETIMES, FILTER_MAP_NEXT, CHECKED_CONVERSIONS, MANUAL_RANGE_CONTAINS, USE_SELF, MEM_REPLACE_WITH_DEFAULT, MANUAL_NON_EXHAUSTIVE, OPTION_AS_REF_DEREF, MAP_UNWRAP_OR, MATCH_LIKE_MATCHES_MACRO, MANUAL_STRIP, MISSING_CONST_FOR_FN, UNNESTED_OR_PATTERNS, FROM_OVER_INTO, PTR_AS_PTR, IF_THEN_SOME_ELSE_NONE.
140+
///
141+
/// The minimum rust version that the project supports
138142
(msrv: Option<String> = None),
139-
/// Lint: BLACKLISTED_NAME. The list of blacklisted names to lint about. NB: `bar` is not here since it has legitimate uses
143+
/// Lint: BLACKLISTED_NAME.
144+
///
145+
/// The list of blacklisted names to lint about. NB: `bar` is not here since it has legitimate uses
140146
(blacklisted_names: Vec<String> = ["foo", "baz", "quux"].iter().map(ToString::to_string).collect()),
141-
/// Lint: COGNITIVE_COMPLEXITY. The maximum cognitive complexity a function can have
147+
/// Lint: COGNITIVE_COMPLEXITY.
148+
///
149+
/// The maximum cognitive complexity a function can have
142150
(cognitive_complexity_threshold: u64 = 25),
143-
/// DEPRECATED LINT: CYCLOMATIC_COMPLEXITY. Use the Cognitive Complexity lint instead.
151+
/// DEPRECATED LINT: CYCLOMATIC_COMPLEXITY.
152+
///
153+
/// Use the Cognitive Complexity lint instead.
144154
#[conf_deprecated("Please use `cognitive-complexity-threshold` instead")]
145155
(cyclomatic_complexity_threshold: Option<u64> = None),
146-
/// Lint: DOC_MARKDOWN. The list of words this lint should not consider as identifiers needing ticks
156+
/// Lint: DOC_MARKDOWN.
157+
///
158+
/// The list of words this lint should not consider as identifiers needing ticks
147159
(doc_valid_idents: Vec<String> = [
148160
"KiB", "MiB", "GiB", "TiB", "PiB", "EiB",
149161
"DirectX",
@@ -164,55 +176,109 @@ define_Conf! {
164176
"MinGW",
165177
"CamelCase",
166178
].iter().map(ToString::to_string).collect()),
167-
/// Lint: TOO_MANY_ARGUMENTS. The maximum number of argument a function or method can have
179+
/// Lint: TOO_MANY_ARGUMENTS.
180+
///
181+
/// The maximum number of argument a function or method can have
168182
(too_many_arguments_threshold: u64 = 7),
169-
/// Lint: TYPE_COMPLEXITY. The maximum complexity a type can have
183+
/// Lint: TYPE_COMPLEXITY.
184+
///
185+
/// The maximum complexity a type can have
170186
(type_complexity_threshold: u64 = 250),
171-
/// Lint: MANY_SINGLE_CHAR_NAMES. The maximum number of single char bindings a scope may have
187+
/// Lint: MANY_SINGLE_CHAR_NAMES.
188+
///
189+
/// The maximum number of single char bindings a scope may have
172190
(single_char_binding_names_threshold: u64 = 4),
173-
/// Lint: BOXED_LOCAL, USELESS_VEC. The maximum size of objects (in bytes) that will be linted. Larger objects are ok on the heap
191+
/// Lint: BOXED_LOCAL, USELESS_VEC.
192+
///
193+
/// The maximum size of objects (in bytes) that will be linted. Larger objects are ok on the heap
174194
(too_large_for_stack: u64 = 200),
175-
/// Lint: ENUM_VARIANT_NAMES. The minimum number of enum variants for the lints about variant names to trigger
195+
/// Lint: ENUM_VARIANT_NAMES.
196+
///
197+
/// The minimum number of enum variants for the lints about variant names to trigger
176198
(enum_variant_name_threshold: u64 = 3),
177-
/// Lint: LARGE_ENUM_VARIANT. The maximum size of a enum's variant to avoid box suggestion
199+
/// Lint: LARGE_ENUM_VARIANT.
200+
///
201+
/// The maximum size of a enum's variant to avoid box suggestion
178202
(enum_variant_size_threshold: u64 = 200),
179-
/// Lint: VERBOSE_BIT_MASK. The maximum allowed size of a bit mask before suggesting to use 'trailing_zeros'
203+
/// Lint: VERBOSE_BIT_MASK.
204+
///
205+
/// The maximum allowed size of a bit mask before suggesting to use 'trailing_zeros'
180206
(verbose_bit_mask_threshold: u64 = 1),
181-
/// Lint: DECIMAL_LITERAL_REPRESENTATION. The lower bound for linting decimal literals
207+
/// Lint: DECIMAL_LITERAL_REPRESENTATION.
208+
///
209+
/// The lower bound for linting decimal literals
182210
(literal_representation_threshold: u64 = 16384),
183-
/// Lint: TRIVIALLY_COPY_PASS_BY_REF. The maximum size (in bytes) to consider a `Copy` type for passing by value instead of by reference.
211+
/// Lint: TRIVIALLY_COPY_PASS_BY_REF.
212+
///
213+
/// The maximum size (in bytes) to consider a `Copy` type for passing by value instead of by reference.
184214
(trivial_copy_size_limit: Option<u64> = None),
185-
/// Lint: LARGE_TYPE_PASS_BY_MOVE. The minimum size (in bytes) to consider a type for passing by reference instead of by value.
215+
/// Lint: LARGE_TYPE_PASS_BY_MOVE.
216+
///
217+
/// The minimum size (in bytes) to consider a type for passing by reference instead of by value.
186218
(pass_by_value_size_limit: u64 = 256),
187-
/// Lint: TOO_MANY_LINES. The maximum number of lines a function or method can have
219+
/// Lint: TOO_MANY_LINES.
220+
///
221+
/// The maximum number of lines a function or method can have
188222
(too_many_lines_threshold: u64 = 100),
189-
/// Lint: LARGE_STACK_ARRAYS, LARGE_CONST_ARRAYS. The maximum allowed size for arrays on the stack
223+
/// Lint: LARGE_STACK_ARRAYS, LARGE_CONST_ARRAYS.
224+
///
225+
/// The maximum allowed size for arrays on the stack
190226
(array_size_threshold: u64 = 512_000),
191-
/// Lint: VEC_BOX. The size of the boxed type in bytes, where boxing in a `Vec` is allowed
227+
/// Lint: VEC_BOX.
228+
///
229+
/// The size of the boxed type in bytes, where boxing in a `Vec` is allowed
192230
(vec_box_size_threshold: u64 = 4096),
193-
/// Lint: TYPE_REPETITION_IN_BOUNDS. The maximum number of bounds a trait can have to be linted
231+
/// Lint: TYPE_REPETITION_IN_BOUNDS.
232+
///
233+
/// The maximum number of bounds a trait can have to be linted
194234
(max_trait_bounds: u64 = 3),
195-
/// Lint: STRUCT_EXCESSIVE_BOOLS. The maximum number of bool fields a struct can have
235+
/// Lint: STRUCT_EXCESSIVE_BOOLS.
236+
///
237+
/// The maximum number of bool fields a struct can have
196238
(max_struct_bools: u64 = 3),
197-
/// Lint: FN_PARAMS_EXCESSIVE_BOOLS. The maximum number of bool parameters a function can have
239+
/// Lint: FN_PARAMS_EXCESSIVE_BOOLS.
240+
///
241+
/// The maximum number of bool parameters a function can have
198242
(max_fn_params_bools: u64 = 3),
199-
/// Lint: WILDCARD_IMPORTS. Whether to allow certain wildcard imports (prelude, super in tests).
243+
/// Lint: WILDCARD_IMPORTS.
244+
///
245+
/// Whether to allow certain wildcard imports (prelude, super in tests).
200246
(warn_on_all_wildcard_imports: bool = false),
201-
/// Lint: DISALLOWED_METHOD. The list of disallowed methods, written as fully qualified paths.
247+
/// Lint: DISALLOWED_METHOD.
248+
///
249+
/// The list of disallowed methods, written as fully qualified paths.
202250
(disallowed_methods: Vec<String> = Vec::new()),
203-
/// Lint: DISALLOWED_TYPE. The list of disallowed types, written as fully qualified paths.
251+
/// Lint: DISALLOWED_TYPE.
252+
///
253+
/// The list of disallowed types, written as fully qualified paths.
204254
(disallowed_types: Vec<String> = Vec::new()),
205-
/// Lint: UNREADABLE_LITERAL. Should the fraction of a decimal be linted to include separators.
255+
/// Lint: UNREADABLE_LITERAL.
256+
///
257+
/// Should the fraction of a decimal be linted to include separators.
206258
(unreadable_literal_lint_fractions: bool = true),
207-
/// Lint: UPPER_CASE_ACRONYMS. Enables verbose mode. Triggers if there is more than one uppercase char next to each other
259+
/// Lint: UPPER_CASE_ACRONYMS.
260+
///
261+
/// Enables verbose mode. Triggers if there is more than one uppercase char next to each other
208262
(upper_case_acronyms_aggressive: bool = false),
209-
/// Lint: _CARGO_COMMON_METADATA. For internal testing only, ignores the current `publish` settings in the Cargo manifest.
263+
/// Lint: _CARGO_COMMON_METADATA.
264+
///
265+
/// For internal testing only, ignores the current `publish` settings in the Cargo manifest.
210266
(cargo_ignore_publish: bool = false),
211-
/// Lint: NONSTANDARD_MACRO_BRACES. Enforce the named macros always use the braces specified. <br> A `MacroMatcher` can be added like so `{ name = "macro_name", brace = "(" }`. If the macro is could be used with a full path two `MacroMatcher`s have to be added one with the full path `crate_name::macro_name` and one with just the macro name.
267+
/// Lint: NONSTANDARD_MACRO_BRACES.
268+
///
269+
/// Enforce the named macros always use the braces specified.
270+
///
271+
/// A `MacroMatcher` can be added like so `{ name = "macro_name", brace = "(" }`. If the macro
272+
/// is could be used with a full path two `MacroMatcher`s have to be added one with the full path
273+
/// `crate_name::macro_name` and one with just the macro name.
212274
(standard_macro_braces: Vec<crate::nonstandard_macro_braces::MacroMatcher> = Vec::new()),
213-
/// Lint: MISSING_ENFORCED_IMPORT_RENAMES. The list of imports to always rename, a fully qualified path followed by the rename.
275+
/// Lint: MISSING_ENFORCED_IMPORT_RENAMES.
276+
///
277+
/// The list of imports to always rename, a fully qualified path followed by the rename.
214278
(enforced_import_renames: Vec<crate::utils::conf::Rename> = Vec::new()),
215-
/// Lint: RESTRICTED_SCRIPTS. The list of unicode scripts allowed to be used in the scope.
279+
/// Lint: RESTRICTED_SCRIPTS.
280+
///
281+
/// The list of unicode scripts allowed to be used in the scope.
216282
(allowed_scripts: Vec<String> = vec!["Latin".to_string()]),
217283
}
218284

clippy_lints/src/utils/internal_lints/metadata_collector.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ This lint has the following configuration variables:
8282
/// `default`
8383
macro_rules! CONFIGURATION_VALUE_TEMPLATE {
8484
() => {
85-
"* {name}: {ty}: {doc} (defaults to `{default}`)\n"
85+
"* {name}: `{ty}`: {doc} (defaults to `{default}`)\n"
8686
};
8787
}
8888

@@ -344,11 +344,16 @@ fn parse_config_field_doc(doc_comment: &str) -> Option<(Vec<String>, String)> {
344344
if let Some(split_pos) = doc_comment.find('.');
345345
then {
346346
let mut doc_comment = doc_comment.to_string();
347-
let documentation = doc_comment.split_off(split_pos);
347+
let mut documentation = doc_comment.split_off(split_pos);
348348

349+
// Extract lints
349350
doc_comment.make_ascii_lowercase();
350351
let lints: Vec<String> = doc_comment.split_off(DOC_START.len()).split(", ").map(str::to_string).collect();
351352

353+
// Format documentation correctly
354+
// split off leading `.` from lint name list and indent for correct formatting
355+
documentation = documentation.trim_start_matches('.').trim().replace("\n ", "\n ");
356+
352357
Some((lints, documentation))
353358
} else {
354359
None

0 commit comments

Comments
 (0)