Convert unexpected_cfg_{name,value} to struct diagnostics
This commit is contained in:
parent
bac6b6248b
commit
2482f3c17c
21 changed files with 474 additions and 190 deletions
|
@ -1953,3 +1953,254 @@ pub struct UnitBindingsDiag {
|
|||
#[help]
|
||||
#[note]
|
||||
pub struct BuiltinNamedAsmLabel;
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
#[help(lint_unexpected_cfg_add_cargo_feature)]
|
||||
#[help(lint_unexpected_cfg_add_cargo_toml_lint_cfg)]
|
||||
#[help(lint_unexpected_cfg_add_build_rs_println)]
|
||||
pub struct UnexpectedCfgCargoHelp {
|
||||
pub build_rs_println: String,
|
||||
pub cargo_toml_lint_cfg: String,
|
||||
}
|
||||
|
||||
impl UnexpectedCfgCargoHelp {
|
||||
pub fn new(unescaped: &str, escaped: &str) -> Self {
|
||||
Self {
|
||||
cargo_toml_lint_cfg: format!(
|
||||
"\n [lints.rust]\n unexpected_cfgs = {{ level = \"warn\", check-cfg = ['{unescaped}'] }}",
|
||||
),
|
||||
build_rs_println: format!("println!(\"cargo::rustc-check-cfg={escaped}\");",),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
#[help(lint_unexpected_cfg_add_cmdline_arg)]
|
||||
pub struct UnexpectedCfgRustcHelp {
|
||||
pub cmdline_arg: String,
|
||||
}
|
||||
|
||||
impl UnexpectedCfgRustcHelp {
|
||||
pub fn new(unescaped: &str) -> Self {
|
||||
Self { cmdline_arg: format!("--check-cfg={unescaped}") }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
pub struct UnexpectedCfgNameSub {
|
||||
#[subdiagnostic]
|
||||
pub code_sugg: unexpected_cfg_name::CodeSuggestion,
|
||||
#[subdiagnostic]
|
||||
pub invocation_help: unexpected_cfg_name::InvocationHelp,
|
||||
}
|
||||
|
||||
pub mod unexpected_cfg_name {
|
||||
use rustc_errors::DiagSymbolList;
|
||||
use rustc_macros::Subdiagnostic;
|
||||
use rustc_span::{Span, Symbol};
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
pub enum CodeSuggestion {
|
||||
#[help(lint_unexpected_cfg_define_features)]
|
||||
DefineFeatures,
|
||||
#[suggestion(
|
||||
lint_unexpected_cfg_name_similar_name_value,
|
||||
applicability = "maybe-incorrect",
|
||||
code = "{code}"
|
||||
)]
|
||||
SimilarNameAndValue {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
code: String,
|
||||
},
|
||||
#[suggestion(
|
||||
lint_unexpected_cfg_name_similar_name_no_value,
|
||||
applicability = "maybe-incorrect",
|
||||
code = "{code}"
|
||||
)]
|
||||
SimilarNameNoValue {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
code: String,
|
||||
},
|
||||
#[suggestion(
|
||||
lint_unexpected_cfg_name_similar_name_different_values,
|
||||
applicability = "maybe-incorrect",
|
||||
code = "{code}"
|
||||
)]
|
||||
SimilarNameDifferentValues {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
code: String,
|
||||
#[subdiagnostic]
|
||||
expected: Option<ExpectedValues>,
|
||||
},
|
||||
#[suggestion(
|
||||
lint_unexpected_cfg_name_similar_name,
|
||||
applicability = "maybe-incorrect",
|
||||
code = "{code}"
|
||||
)]
|
||||
SimilarName {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
code: String,
|
||||
#[subdiagnostic]
|
||||
expected: Option<ExpectedValues>,
|
||||
},
|
||||
SimilarValues {
|
||||
#[subdiagnostic]
|
||||
with_similar_values: Vec<FoundWithSimilarValue>,
|
||||
#[subdiagnostic]
|
||||
expected_names: Option<ExpectedNames>,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
#[help(lint_unexpected_cfg_name_expected_values)]
|
||||
pub struct ExpectedValues {
|
||||
pub best_match: Symbol,
|
||||
pub possibilities: DiagSymbolList,
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
#[suggestion(
|
||||
lint_unexpected_cfg_name_with_similar_value,
|
||||
applicability = "maybe-incorrect",
|
||||
code = "{code}"
|
||||
)]
|
||||
pub struct FoundWithSimilarValue {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
pub code: String,
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
#[help_once(lint_unexpected_cfg_name_expected_names)]
|
||||
pub struct ExpectedNames {
|
||||
pub possibilities: DiagSymbolList,
|
||||
pub and_more: usize,
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
pub enum InvocationHelp {
|
||||
#[note(lint_unexpected_cfg_doc_cargo)]
|
||||
Cargo {
|
||||
#[subdiagnostic]
|
||||
sub: Option<super::UnexpectedCfgCargoHelp>,
|
||||
},
|
||||
#[note(lint_unexpected_cfg_doc_rustc)]
|
||||
Rustc(#[subdiagnostic] super::UnexpectedCfgRustcHelp),
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
pub struct UnexpectedCfgValueSub {
|
||||
#[subdiagnostic]
|
||||
pub code_sugg: unexpected_cfg_value::CodeSuggestion,
|
||||
#[subdiagnostic]
|
||||
pub invocation_help: unexpected_cfg_value::InvocationHelp,
|
||||
}
|
||||
|
||||
pub mod unexpected_cfg_value {
|
||||
use rustc_errors::DiagSymbolList;
|
||||
use rustc_macros::Subdiagnostic;
|
||||
use rustc_span::{Span, Symbol};
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
pub enum CodeSuggestion {
|
||||
ChangeValue {
|
||||
#[subdiagnostic]
|
||||
expected_values: ExpectedValues,
|
||||
#[subdiagnostic]
|
||||
suggestion: Option<ChangeValueSuggestion>,
|
||||
},
|
||||
#[note(lint_unexpected_cfg_value_no_expected_value)]
|
||||
RemoveValue {
|
||||
#[subdiagnostic]
|
||||
suggestion: Option<RemoveValueSuggestion>,
|
||||
|
||||
name: Symbol,
|
||||
},
|
||||
#[note(lint_unexpected_cfg_value_no_expected_values)]
|
||||
RemoveCondition {
|
||||
#[subdiagnostic]
|
||||
suggestion: RemoveConditionSuggestion,
|
||||
|
||||
name: Symbol,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
pub enum ChangeValueSuggestion {
|
||||
#[suggestion(
|
||||
lint_unexpected_cfg_value_similar_name,
|
||||
code = r#""{best_match}""#,
|
||||
applicability = "maybe-incorrect"
|
||||
)]
|
||||
SimilarName {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
best_match: Symbol,
|
||||
},
|
||||
#[suggestion(
|
||||
lint_unexpected_cfg_value_specify_value,
|
||||
code = r#" = "{first_possibility}""#,
|
||||
applicability = "maybe-incorrect"
|
||||
)]
|
||||
SpecifyValue {
|
||||
#[primary_span]
|
||||
span: Span,
|
||||
first_possibility: Symbol,
|
||||
},
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
#[suggestion(
|
||||
lint_unexpected_cfg_value_remove_value,
|
||||
code = "",
|
||||
applicability = "maybe-incorrect"
|
||||
)]
|
||||
pub struct RemoveValueSuggestion {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
#[suggestion(
|
||||
lint_unexpected_cfg_value_remove_condition,
|
||||
code = "",
|
||||
applicability = "maybe-incorrect"
|
||||
)]
|
||||
pub struct RemoveConditionSuggestion {
|
||||
#[primary_span]
|
||||
pub span: Span,
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
#[note(lint_unexpected_cfg_value_expected_values)]
|
||||
pub struct ExpectedValues {
|
||||
pub name: Symbol,
|
||||
pub have_none_possibility: bool,
|
||||
pub possibilities: DiagSymbolList,
|
||||
pub and_more: usize,
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
pub enum InvocationHelp {
|
||||
#[note(lint_unexpected_cfg_doc_cargo)]
|
||||
Cargo(#[subdiagnostic] Option<CargoHelp>),
|
||||
#[note(lint_unexpected_cfg_doc_rustc)]
|
||||
Rustc(#[subdiagnostic] Option<super::UnexpectedCfgRustcHelp>),
|
||||
}
|
||||
|
||||
#[derive(Subdiagnostic)]
|
||||
pub enum CargoHelp {
|
||||
#[help(lint_unexpected_cfg_value_add_feature)]
|
||||
AddFeature {
|
||||
value: Symbol,
|
||||
},
|
||||
#[help(lint_unexpected_cfg_define_features)]
|
||||
DefineFeatures,
|
||||
Other(#[subdiagnostic] super::UnexpectedCfgCargoHelp),
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue