]> git.lizzy.rs Git - rust.git/commitdiff
lint: port pass-by-value diagnostics
authorDavid Wood <david.wood@huawei.com>
Mon, 27 Jun 2022 15:57:40 +0000 (16:57 +0100)
committerDavid Wood <david.wood@huawei.com>
Thu, 30 Jun 2022 07:59:21 +0000 (08:59 +0100)
Signed-off-by: David Wood <david.wood@huawei.com>
compiler/rustc_error_messages/locales/en-US/lint.ftl
compiler/rustc_lint/src/pass_by_value.rs

index d93007644dbcab0e009ad478abb218f6c24ecb43..e3c588b6ff1ec23db1d3ca29eddf47a13a13af0a 100644 (file)
@@ -128,3 +128,6 @@ lint-non-upper_case-global = {$sort} `{$name}` should have an upper case name
 lint-noop-method-call = call to `.{$method}()` on a reference in this situation does nothing
     .label = unnecessary method call
     .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
+
+lint-pass-by-value = passing `{$ty}` by reference
+    .suggestion = try passing by value
index 2c8b41d7214031459287c74e181eb42fcf310168..af5e5faf1f568aef60d44de98c57acafe0b69615 100644 (file)
@@ -1,5 +1,5 @@
 use crate::{LateContext, LateLintPass, LintContext};
-use rustc_errors::Applicability;
+use rustc_errors::{fluent, Applicability};
 use rustc_hir as hir;
 use rustc_hir::def::Res;
 use rustc_hir::{GenericArg, PathSegment, QPath, TyKind};
@@ -30,10 +30,11 @@ fn check_ty(&mut self, cx: &LateContext<'_>, ty: &'tcx hir::Ty<'tcx>) {
                 }
                 if let Some(t) = path_for_pass_by_value(cx, &inner_ty) {
                     cx.struct_span_lint(PASS_BY_VALUE, ty.span, |lint| {
-                        lint.build(&format!("passing `{}` by reference", t))
+                        lint.build(fluent::lint::pass_by_value)
+                            .set_arg("ty", t.clone())
                             .span_suggestion(
                                 ty.span,
-                                "try passing by value",
+                                fluent::lint::suggestion,
                                 t,
                                 // Changing type of function argument
                                 Applicability::MaybeIncorrect,