refactor: use references to reduce unnecessary clones

This commit is contained in:
Weihang Lo 2023-08-24 00:23:01 +01:00
parent 81a24922e7
commit 73152a3efb
No known key found for this signature in database
GPG Key ID: D7DBF189825E82E7
2 changed files with 27 additions and 28 deletions

View File

@ -343,33 +343,32 @@ impl LintStore {
sess.emit_err(UnsupportedGroup { lint_group: crate::WARNINGS.name_lower() }); sess.emit_err(UnsupportedGroup { lint_group: crate::WARNINGS.name_lower() });
return; return;
} }
let lint_name = lint_name.to_string();
match self.check_lint_name(lint_name_only, tool_name, registered_tools) { match self.check_lint_name(lint_name_only, tool_name, registered_tools) {
CheckLintNameResult::Renamed(replace) => { CheckLintNameResult::Renamed(replace) => {
sess.emit_warning(CheckNameRenamed { sess.emit_warning(CheckNameRenamed {
lint_name: lint_name.clone(), lint_name,
replace, replace: &replace,
sub: RequestedLevel { level, lint_name }, sub: RequestedLevel { level, lint_name },
}); });
} }
CheckLintNameResult::Removed(reason) => { CheckLintNameResult::Removed(reason) => {
sess.emit_warning(CheckNameRemoved { sess.emit_warning(CheckNameRemoved {
lint_name: lint_name.clone(), lint_name,
reason, reason: &reason,
sub: RequestedLevel { level, lint_name }, sub: RequestedLevel { level, lint_name },
}); });
} }
CheckLintNameResult::NoLint(suggestion) => { CheckLintNameResult::NoLint(suggestion) => {
sess.emit_err(CheckNameUnknown { sess.emit_err(CheckNameUnknown {
lint_name: lint_name.clone(), lint_name,
suggestion, suggestion,
sub: RequestedLevel { level, lint_name }, sub: RequestedLevel { level, lint_name },
}); });
} }
CheckLintNameResult::Tool(Err((Some(_), new_name))) => { CheckLintNameResult::Tool(Err((Some(_), new_name))) => {
sess.emit_warning(CheckNameDeprecated { sess.emit_warning(CheckNameDeprecated {
lint_name: lint_name.clone(), lint_name,
new_name, new_name: &new_name,
sub: RequestedLevel { level, lint_name }, sub: RequestedLevel { level, lint_name },
}); });
} }

View File

@ -91,9 +91,9 @@ pub struct BuiltinEllipsisInclusiveRangePatterns {
#[derive(Subdiagnostic)] #[derive(Subdiagnostic)]
#[note(lint_requested_level)] #[note(lint_requested_level)]
pub struct RequestedLevel { pub struct RequestedLevel<'a> {
pub level: Level, pub level: Level,
pub lint_name: String, pub lint_name: &'a str,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
@ -102,13 +102,13 @@ pub struct UnsupportedGroup {
pub lint_group: String, pub lint_group: String,
} }
pub struct CheckNameUnknown { pub struct CheckNameUnknown<'a> {
pub lint_name: String, pub lint_name: &'a str,
pub suggestion: Option<Symbol>, pub suggestion: Option<Symbol>,
pub sub: RequestedLevel, pub sub: RequestedLevel<'a>,
} }
impl IntoDiagnostic<'_> for CheckNameUnknown { impl IntoDiagnostic<'_> for CheckNameUnknown<'_> {
fn into_diagnostic( fn into_diagnostic(
self, self,
handler: &Handler, handler: &Handler,
@ -127,35 +127,35 @@ impl IntoDiagnostic<'_> for CheckNameUnknown {
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(lint_check_name_unknown_tool, code = "E0602")] #[diag(lint_check_name_unknown_tool, code = "E0602")]
pub struct CheckNameUnknownTool { pub struct CheckNameUnknownTool<'a> {
pub tool_name: Symbol, pub tool_name: Symbol,
#[subdiagnostic] #[subdiagnostic]
pub sub: RequestedLevel, pub sub: RequestedLevel<'a>,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(lint_check_name_renamed)] #[diag(lint_check_name_renamed)]
pub struct CheckNameRenamed { pub struct CheckNameRenamed<'a> {
pub lint_name: String, pub lint_name: &'a str,
pub replace: String, pub replace: &'a str,
#[subdiagnostic] #[subdiagnostic]
pub sub: RequestedLevel, pub sub: RequestedLevel<'a>,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(lint_check_name_removed)] #[diag(lint_check_name_removed)]
pub struct CheckNameRemoved { pub struct CheckNameRemoved<'a> {
pub lint_name: String, pub lint_name: &'a str,
pub reason: String, pub reason: &'a str,
#[subdiagnostic] #[subdiagnostic]
pub sub: RequestedLevel, pub sub: RequestedLevel<'a>,
} }
#[derive(Diagnostic)] #[derive(Diagnostic)]
#[diag(lint_check_name_deprecated)] #[diag(lint_check_name_deprecated)]
pub struct CheckNameDeprecated { pub struct CheckNameDeprecated<'a> {
pub lint_name: String, pub lint_name: &'a str,
pub new_name: String, pub new_name: &'a str,
#[subdiagnostic] #[subdiagnostic]
pub sub: RequestedLevel, pub sub: RequestedLevel<'a>,
} }