Skip to content

Commit 73152a3

Browse files
committed
refactor: use references to reduce unnecessary clones
1 parent 81a2492 commit 73152a3

File tree

2 files changed

+27
-28
lines changed

2 files changed

+27
-28
lines changed

compiler/rustc_lint/src/context.rs

+7-8
Original file line numberDiff line numberDiff line change
@@ -343,33 +343,32 @@ impl LintStore {
343343
sess.emit_err(UnsupportedGroup { lint_group: crate::WARNINGS.name_lower() });
344344
return;
345345
}
346-
let lint_name = lint_name.to_string();
347346
match self.check_lint_name(lint_name_only, tool_name, registered_tools) {
348347
CheckLintNameResult::Renamed(replace) => {
349348
sess.emit_warning(CheckNameRenamed {
350-
lint_name: lint_name.clone(),
351-
replace,
349+
lint_name,
350+
replace: &replace,
352351
sub: RequestedLevel { level, lint_name },
353352
});
354353
}
355354
CheckLintNameResult::Removed(reason) => {
356355
sess.emit_warning(CheckNameRemoved {
357-
lint_name: lint_name.clone(),
358-
reason,
356+
lint_name,
357+
reason: &reason,
359358
sub: RequestedLevel { level, lint_name },
360359
});
361360
}
362361
CheckLintNameResult::NoLint(suggestion) => {
363362
sess.emit_err(CheckNameUnknown {
364-
lint_name: lint_name.clone(),
363+
lint_name,
365364
suggestion,
366365
sub: RequestedLevel { level, lint_name },
367366
});
368367
}
369368
CheckLintNameResult::Tool(Err((Some(_), new_name))) => {
370369
sess.emit_warning(CheckNameDeprecated {
371-
lint_name: lint_name.clone(),
372-
new_name,
370+
lint_name,
371+
new_name: &new_name,
373372
sub: RequestedLevel { level, lint_name },
374373
});
375374
}

compiler/rustc_lint/src/errors.rs

+20-20
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,9 @@ pub struct BuiltinEllipsisInclusiveRangePatterns {
9191

9292
#[derive(Subdiagnostic)]
9393
#[note(lint_requested_level)]
94-
pub struct RequestedLevel {
94+
pub struct RequestedLevel<'a> {
9595
pub level: Level,
96-
pub lint_name: String,
96+
pub lint_name: &'a str,
9797
}
9898

9999
#[derive(Diagnostic)]
@@ -102,13 +102,13 @@ pub struct UnsupportedGroup {
102102
pub lint_group: String,
103103
}
104104

105-
pub struct CheckNameUnknown {
106-
pub lint_name: String,
105+
pub struct CheckNameUnknown<'a> {
106+
pub lint_name: &'a str,
107107
pub suggestion: Option<Symbol>,
108-
pub sub: RequestedLevel,
108+
pub sub: RequestedLevel<'a>,
109109
}
110110

111-
impl IntoDiagnostic<'_> for CheckNameUnknown {
111+
impl IntoDiagnostic<'_> for CheckNameUnknown<'_> {
112112
fn into_diagnostic(
113113
self,
114114
handler: &Handler,
@@ -127,35 +127,35 @@ impl IntoDiagnostic<'_> for CheckNameUnknown {
127127

128128
#[derive(Diagnostic)]
129129
#[diag(lint_check_name_unknown_tool, code = "E0602")]
130-
pub struct CheckNameUnknownTool {
130+
pub struct CheckNameUnknownTool<'a> {
131131
pub tool_name: Symbol,
132132
#[subdiagnostic]
133-
pub sub: RequestedLevel,
133+
pub sub: RequestedLevel<'a>,
134134
}
135135

136136
#[derive(Diagnostic)]
137137
#[diag(lint_check_name_renamed)]
138-
pub struct CheckNameRenamed {
139-
pub lint_name: String,
140-
pub replace: String,
138+
pub struct CheckNameRenamed<'a> {
139+
pub lint_name: &'a str,
140+
pub replace: &'a str,
141141
#[subdiagnostic]
142-
pub sub: RequestedLevel,
142+
pub sub: RequestedLevel<'a>,
143143
}
144144

145145
#[derive(Diagnostic)]
146146
#[diag(lint_check_name_removed)]
147-
pub struct CheckNameRemoved {
148-
pub lint_name: String,
149-
pub reason: String,
147+
pub struct CheckNameRemoved<'a> {
148+
pub lint_name: &'a str,
149+
pub reason: &'a str,
150150
#[subdiagnostic]
151-
pub sub: RequestedLevel,
151+
pub sub: RequestedLevel<'a>,
152152
}
153153

154154
#[derive(Diagnostic)]
155155
#[diag(lint_check_name_deprecated)]
156-
pub struct CheckNameDeprecated {
157-
pub lint_name: String,
158-
pub new_name: String,
156+
pub struct CheckNameDeprecated<'a> {
157+
pub lint_name: &'a str,
158+
pub new_name: &'a str,
159159
#[subdiagnostic]
160-
pub sub: RequestedLevel,
160+
pub sub: RequestedLevel<'a>,
161161
}

0 commit comments

Comments
 (0)