Skip to content

Commit

Permalink
refactor: use references to reduce unnecessary clones
Browse files Browse the repository at this point in the history
  • Loading branch information
weihanglo committed Aug 24, 2023
1 parent 81a2492 commit 73152a3
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 28 deletions.
15 changes: 7 additions & 8 deletions compiler/rustc_lint/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -343,33 +343,32 @@ impl LintStore {
sess.emit_err(UnsupportedGroup { lint_group: crate::WARNINGS.name_lower() });
return;
}
let lint_name = lint_name.to_string();
match self.check_lint_name(lint_name_only, tool_name, registered_tools) {
CheckLintNameResult::Renamed(replace) => {
sess.emit_warning(CheckNameRenamed {
lint_name: lint_name.clone(),
replace,
lint_name,
replace: &replace,
sub: RequestedLevel { level, lint_name },
});
}
CheckLintNameResult::Removed(reason) => {
sess.emit_warning(CheckNameRemoved {
lint_name: lint_name.clone(),
reason,
lint_name,
reason: &reason,
sub: RequestedLevel { level, lint_name },
});
}
CheckLintNameResult::NoLint(suggestion) => {
sess.emit_err(CheckNameUnknown {
lint_name: lint_name.clone(),
lint_name,
suggestion,
sub: RequestedLevel { level, lint_name },
});
}
CheckLintNameResult::Tool(Err((Some(_), new_name))) => {
sess.emit_warning(CheckNameDeprecated {
lint_name: lint_name.clone(),
new_name,
lint_name,
new_name: &new_name,
sub: RequestedLevel { level, lint_name },
});
}
Expand Down
40 changes: 20 additions & 20 deletions compiler/rustc_lint/src/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,9 @@ pub struct BuiltinEllipsisInclusiveRangePatterns {

#[derive(Subdiagnostic)]
#[note(lint_requested_level)]
pub struct RequestedLevel {
pub struct RequestedLevel<'a> {
pub level: Level,
pub lint_name: String,
pub lint_name: &'a str,
}

#[derive(Diagnostic)]
Expand All @@ -102,13 +102,13 @@ pub struct UnsupportedGroup {
pub lint_group: String,
}

pub struct CheckNameUnknown {
pub lint_name: String,
pub struct CheckNameUnknown<'a> {
pub lint_name: &'a str,
pub suggestion: Option<Symbol>,
pub sub: RequestedLevel,
pub sub: RequestedLevel<'a>,
}

impl IntoDiagnostic<'_> for CheckNameUnknown {
impl IntoDiagnostic<'_> for CheckNameUnknown<'_> {
fn into_diagnostic(
self,
handler: &Handler,
Expand All @@ -127,35 +127,35 @@ impl IntoDiagnostic<'_> for CheckNameUnknown {

#[derive(Diagnostic)]
#[diag(lint_check_name_unknown_tool, code = "E0602")]
pub struct CheckNameUnknownTool {
pub struct CheckNameUnknownTool<'a> {
pub tool_name: Symbol,
#[subdiagnostic]
pub sub: RequestedLevel,
pub sub: RequestedLevel<'a>,
}

#[derive(Diagnostic)]
#[diag(lint_check_name_renamed)]
pub struct CheckNameRenamed {
pub lint_name: String,
pub replace: String,
pub struct CheckNameRenamed<'a> {
pub lint_name: &'a str,
pub replace: &'a str,
#[subdiagnostic]
pub sub: RequestedLevel,
pub sub: RequestedLevel<'a>,
}

#[derive(Diagnostic)]
#[diag(lint_check_name_removed)]
pub struct CheckNameRemoved {
pub lint_name: String,
pub reason: String,
pub struct CheckNameRemoved<'a> {
pub lint_name: &'a str,
pub reason: &'a str,
#[subdiagnostic]
pub sub: RequestedLevel,
pub sub: RequestedLevel<'a>,
}

#[derive(Diagnostic)]
#[diag(lint_check_name_deprecated)]
pub struct CheckNameDeprecated {
pub lint_name: String,
pub new_name: String,
pub struct CheckNameDeprecated<'a> {
pub lint_name: &'a str,
pub new_name: &'a str,
#[subdiagnostic]
pub sub: RequestedLevel,
pub sub: RequestedLevel<'a>,
}

0 comments on commit 73152a3

Please sign in to comment.