Add runtime check to avoid overwrite arg easily in diag and store and restore snapshot when set subdiag arg
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
This commit is contained in:
@@ -482,7 +482,8 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
|
||||
let name = lint_name.as_str();
|
||||
let suggestion = RenamedLintSuggestion::WithoutSpan { replace };
|
||||
let requested_level = RequestedLevel { level, lint_name };
|
||||
let lint = RenamedLintFromCommandLine { name, suggestion, requested_level };
|
||||
let lint =
|
||||
RenamedLintFromCommandLine { name, replace, suggestion, requested_level };
|
||||
self.emit_lint(RENAMED_AND_REMOVED_LINTS, lint);
|
||||
}
|
||||
CheckLintNameResult::Removed(ref reason) => {
|
||||
@@ -824,7 +825,7 @@ impl<'s, P: LintLevelsProvider> LintLevelsBuilder<'s, P> {
|
||||
RenamedLintSuggestion::WithSpan { suggestion: sp, replace };
|
||||
let name =
|
||||
tool_ident.map(|tool| format!("{tool}::{name}")).unwrap_or(name);
|
||||
let lint = RenamedLint { name: name.as_str(), suggestion };
|
||||
let lint = RenamedLint { name: name.as_str(), replace, suggestion };
|
||||
self.emit_span_lint(RENAMED_AND_REMOVED_LINTS, sp.into(), lint);
|
||||
}
|
||||
|
||||
|
||||
@@ -422,12 +422,12 @@ fn build_mismatch_suggestion(
|
||||
lifetime_name: &str,
|
||||
infos: &[&Info<'_>],
|
||||
) -> lints::MismatchedLifetimeSyntaxesSuggestion {
|
||||
let lifetime_name = lifetime_name.to_owned();
|
||||
let lifetime_name_sugg = lifetime_name.to_owned();
|
||||
|
||||
let suggestions = infos.iter().map(|info| info.suggestion(&lifetime_name)).collect();
|
||||
|
||||
lints::MismatchedLifetimeSyntaxesSuggestion::Explicit {
|
||||
lifetime_name,
|
||||
lifetime_name_sugg,
|
||||
suggestions,
|
||||
tool_only: false,
|
||||
}
|
||||
|
||||
@@ -1089,6 +1089,7 @@ pub(crate) struct DeprecatedLintNameFromCommandLine<'a> {
|
||||
#[diag(lint_renamed_lint)]
|
||||
pub(crate) struct RenamedLint<'a> {
|
||||
pub name: &'a str,
|
||||
pub replace: &'a str,
|
||||
#[subdiagnostic]
|
||||
pub suggestion: RenamedLintSuggestion<'a>,
|
||||
}
|
||||
@@ -1109,6 +1110,7 @@ pub(crate) enum RenamedLintSuggestion<'a> {
|
||||
#[diag(lint_renamed_lint)]
|
||||
pub(crate) struct RenamedLintFromCommandLine<'a> {
|
||||
pub name: &'a str,
|
||||
pub replace: &'a str,
|
||||
#[subdiagnostic]
|
||||
pub suggestion: RenamedLintSuggestion<'a>,
|
||||
#[subdiagnostic]
|
||||
@@ -3227,7 +3229,7 @@ pub(crate) enum MismatchedLifetimeSyntaxesSuggestion {
|
||||
},
|
||||
|
||||
Explicit {
|
||||
lifetime_name: String,
|
||||
lifetime_name_sugg: String,
|
||||
suggestions: Vec<(Span, String)>,
|
||||
tool_only: bool,
|
||||
},
|
||||
@@ -3281,13 +3283,12 @@ impl Subdiagnostic for MismatchedLifetimeSyntaxesSuggestion {
|
||||
);
|
||||
}
|
||||
|
||||
Explicit { lifetime_name, suggestions, tool_only } => {
|
||||
diag.arg("lifetime_name", lifetime_name);
|
||||
|
||||
Explicit { lifetime_name_sugg, suggestions, tool_only } => {
|
||||
diag.arg("lifetime_name_sugg", lifetime_name_sugg);
|
||||
let msg = diag.eagerly_translate(
|
||||
fluent::lint_mismatched_lifetime_syntaxes_suggestion_explicit,
|
||||
);
|
||||
|
||||
diag.remove_arg("lifetime_name_sugg");
|
||||
diag.multipart_suggestion_with_style(
|
||||
msg,
|
||||
suggestions,
|
||||
|
||||
Reference in New Issue
Block a user