Skip to content

Commit 37588d6

Browse files
committed
lint: port pass-by-value diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
1 parent 855f237 commit 37588d6

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

compiler/rustc_error_messages/locales/en-US/lint.ftl

+3
Original file line numberDiff line numberDiff line change
@@ -128,3 +128,6 @@ lint-non-upper_case-global = {$sort} `{$name}` should have an upper case name
128128
lint-noop-method-call = call to `.{$method}()` on a reference in this situation does nothing
129129
.label = unnecessary method call
130130
.note = the type `{$receiver_ty}` which `{$method}` is being called on is the same as the type returned from `{$method}`, so the method call does not do anything and can be removed
131+
132+
lint-pass-by-value = passing `{$ty}` by reference
133+
.suggestion = try passing by value

compiler/rustc_lint/src/pass_by_value.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::{LateContext, LateLintPass, LintContext};
2-
use rustc_errors::Applicability;
2+
use rustc_errors::{fluent, Applicability};
33
use rustc_hir as hir;
44
use rustc_hir::def::Res;
55
use rustc_hir::{GenericArg, PathSegment, QPath, TyKind};
@@ -30,10 +30,11 @@ impl<'tcx> LateLintPass<'tcx> for PassByValue {
3030
}
3131
if let Some(t) = path_for_pass_by_value(cx, &inner_ty) {
3232
cx.struct_span_lint(PASS_BY_VALUE, ty.span, |lint| {
33-
lint.build(&format!("passing `{}` by reference", t))
33+
lint.build(fluent::lint::pass_by_value)
34+
.set_arg("ty", t.clone())
3435
.span_suggestion(
3536
ty.span,
36-
"try passing by value",
37+
fluent::lint::suggestion,
3738
t,
3839
// Changing type of function argument
3940
Applicability::MaybeIncorrect,

0 commit comments

Comments
 (0)