diff options
| author | David Wood <david.wood@huawei.com> | 2022-06-27 16:52:51 +0100 |
|---|---|---|
| committer | David Wood <david.wood@huawei.com> | 2022-06-30 08:59:21 +0100 |
| commit | 855f23773b3d6a4c14a8d7c92af35f86e990cfb5 (patch) | |
| tree | 4ad4aed434ce14ece179ed9642c58042ad73b372 /compiler/rustc_lint/src/noop_method_call.rs | |
| parent | 096a69dd19dc70c6583be329bef7a54010b8ce23 (diff) | |
| download | rust-855f23773b3d6a4c14a8d7c92af35f86e990cfb5.tar.gz rust-855f23773b3d6a4c14a8d7c92af35f86e990cfb5.zip | |
lint: port no-op method call diagnostics
Signed-off-by: David Wood <david.wood@huawei.com>
Diffstat (limited to 'compiler/rustc_lint/src/noop_method_call.rs')
| -rw-r--r-- | compiler/rustc_lint/src/noop_method_call.rs | 19 |
1 files changed, 7 insertions, 12 deletions
diff --git a/compiler/rustc_lint/src/noop_method_call.rs b/compiler/rustc_lint/src/noop_method_call.rs index 675bee738a6..2e847c8b89c 100644 --- a/compiler/rustc_lint/src/noop_method_call.rs +++ b/compiler/rustc_lint/src/noop_method_call.rs @@ -2,6 +2,7 @@ use crate::context::LintContext; use crate::rustc_middle::ty::TypeFoldable; use crate::LateContext; use crate::LateLintPass; +use rustc_errors::fluent; use rustc_hir::def::DefKind; use rustc_hir::{Expr, ExprKind}; use rustc_middle::ty; @@ -80,7 +81,6 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall { ) { return; } - let method = &call.ident.name; let receiver = &elements[0]; let receiver_ty = cx.typeck_results().expr_ty(receiver); let expr_ty = cx.typeck_results().expr_ty_adjusted(expr); @@ -90,19 +90,14 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall { return; } let expr_span = expr.span; - let note = format!( - "the type `{:?}` which `{}` is being called on is the same as \ - the type returned from `{}`, so the method call does not do \ - anything and can be removed", - receiver_ty, method, method, - ); - let span = expr_span.with_lo(receiver.span.hi()); cx.struct_span_lint(NOOP_METHOD_CALL, span, |lint| { - let method = &call.ident.name; - let message = - format!("call to `.{}()` on a reference in this situation does nothing", &method,); - lint.build(&message).span_label(span, "unnecessary method call").note(¬e).emit(); + lint.build(fluent::lint::noop_method_call) + .set_arg("method", call.ident.name) + .set_arg("receiver_ty", receiver_ty) + .span_label(span, fluent::lint::label) + .note(fluent::lint::note) + .emit(); }); } } |
