Skip to content

List possible values for configuration enums #15216

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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions book/src/lint_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,8 @@ be filtering for common types.

**Default Value:** `"WellKnownTypes"`

**Possible Values:** `"AllTypes"`, `"Never"`, `"WellKnownTypes"`

---
**Affected lints:**
* [`manual_let_else`](https://rust-lang.github.io/rust-clippy/master/index.html#manual_let_else)
Expand Down Expand Up @@ -911,6 +913,8 @@ exported visibility, or whether they are marked as "pub".

**Default Value:** `"PubliclyExported"`

**Possible Values:** `"AllPubFields"`, `"PubliclyExported"`

---
**Affected lints:**
* [`pub_underscore_fields`](https://rust-lang.github.io/rust-clippy/master/index.html#pub_underscore_fields)
Expand Down
8 changes: 8 additions & 0 deletions clippy_config/src/conf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@ macro_rules! define_Conf {
$(#[doc = $doc:literal])+
$(#[conf_deprecated($dep:literal, $new_conf:ident)])?
$(#[default_text = $default_text:expr])?
$(#[possible_values = [$($possible_value:expr),+]])?
$(#[disallowed_paths_allow_replacements = $replacements_allowed:expr])?
$(#[lints($($for_lints:ident),* $(,)?)])?
$name:ident: $ty:ty = $default:expr,
Expand Down Expand Up @@ -315,6 +316,11 @@ macro_rules! define_Conf {
ClippyConfiguration {
name: stringify!($name).replace('_', "-"),
default: default_text!(defaults::$name() $(, $default_text)?),
possible_values: {
let possibilities = &[$($(stringify!($possible_value)),*)?];
assert!(possibilities.len() == std::mem::variant_count::<$ty>());
possibilities
},
lints: &[$($(stringify!($for_lints)),*)?],
doc: concat!($($doc, '\n',)*),
deprecation_reason: wrap_option!($($dep)?)
Expand Down Expand Up @@ -677,6 +683,7 @@ define_Conf! {
literal_representation_threshold: u64 = 16384,
/// Whether the matches should be considered by the lint, and whether there should
/// be filtering for common types.
#[possible_values = ["AllTypes", "Never", "WellKnownTypes"]]
#[lints(manual_let_else)]
matches_for_let_else: MatchLintBehaviour = MatchLintBehaviour::WellKnownTypes,
/// The maximum number of bool parameters a function can have
Expand Down Expand Up @@ -802,6 +809,7 @@ define_Conf! {
pass_by_value_size_limit: u64 = 256,
/// Lint "public" fields in a struct that are prefixed with an underscore based on their
/// exported visibility, or whether they are marked as "pub".
#[possible_values = ["AllPubFields", "PubliclyExported"]]
#[lints(pub_underscore_fields)]
pub_underscore_fields_behavior: PubUnderscoreFieldsBehaviour = PubUnderscoreFieldsBehaviour::PubliclyExported,
/// Whether to lint only if it's multiline.
Expand Down
8 changes: 7 additions & 1 deletion clippy_config/src/metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::fmt;
pub struct ClippyConfiguration {
pub name: String,
pub default: String,
pub possible_values: &'static [&'static str],
pub lints: &'static [&'static str],
pub doc: &'static str,
pub deprecation_reason: Option<&'static str>,
Expand All @@ -23,10 +24,15 @@ impl fmt::Display for ClippyConfiguration {
impl ClippyConfiguration {
pub fn to_markdown_paragraph(&self) -> String {
format!(
"## `{}`\n{}\n\n**Default Value:** `{}`\n\n---\n**Affected lints:**\n{}\n\n",
"## `{}`\n{}\n\n**Default Value:** `{}`{}\n\n---\n**Affected lints:**\n{}\n\n",
self.name,
self.doc.lines().map(|x| x.strip_prefix(' ').unwrap_or(x)).join("\n"),
self.default,
if self.possible_values.is_empty() {
String::new()
} else {
format!("\n\n**Possible Values:** `{}`", self.possible_values.join("`, `"))
},
self.lints.iter().format_with("\n", |name, f| f(&format_args!(
"* [`{name}`](https://rust-lang.github.io/rust-clippy/master/index.html#{name})"
))),
Expand Down
2 changes: 1 addition & 1 deletion clippy_lints/src/pub_underscore_fields.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ declare_clippy_lint! {
///
/// ### Why is this bad?
/// Fields prefixed with an `_` are inferred as unused, which suggests it should not be marked
/// as `pub`, because marking it as `pub` infers it will be used.
/// as `pub`, because marking it as `pub` implies that it will be used.
///
/// ### Example
/// ```rust
Expand Down
Loading