diff options
| author | Ryan Levick <ryan.levick@gmail.com> | 2021-01-11 11:47:16 +0100 |
|---|---|---|
| committer | Ryan Levick <me@ryanlevick.com> | 2021-03-03 11:22:54 +0100 |
| commit | 95e330bd0197a658096dfa1922ec3b3e6a4e6b78 (patch) | |
| tree | 0372eec123609c379d87f8c3cda84aa7d54e0533 /compiler/rustc_lint/src/noop_method_call.rs | |
| parent | 16c4afbde4bcc0b2471cd48cf29378d557a8f4ab (diff) | |
| download | rust-95e330bd0197a658096dfa1922ec3b3e6a4e6b78.tar.gz rust-95e330bd0197a658096dfa1922ec3b3e6a4e6b78.zip | |
Update error message
Diffstat (limited to 'compiler/rustc_lint/src/noop_method_call.rs')
| -rw-r--r-- | compiler/rustc_lint/src/noop_method_call.rs | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/compiler/rustc_lint/src/noop_method_call.rs b/compiler/rustc_lint/src/noop_method_call.rs index b9b5009d9dd..e91dd37d8aa 100644 --- a/compiler/rustc_lint/src/noop_method_call.rs +++ b/compiler/rustc_lint/src/noop_method_call.rs @@ -39,7 +39,7 @@ declare_lint_pass!(NoopMethodCall => [NOOP_METHOD_CALL]); impl<'tcx> LateLintPass<'tcx> for NoopMethodCall { fn check_expr(&mut self, cx: &LateContext<'tcx>, expr: &'tcx Expr<'_>) { // We only care about method calls - if let ExprKind::MethodCall(..) = expr.kind { + if let ExprKind::MethodCall(call, ..) = expr.kind { // Get the `DefId` only when dealing with an `AssocFn` if let Some((DefKind::AssocFn, did)) = cx.typeck_results().type_dependent_def(expr.hir_id) @@ -55,7 +55,7 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall { } let substs = cx.typeck_results().node_substs(expr.hir_id); - // We can't resolve on types that recursively require monomorphization, + // We can't resolve on types that require monomorphization, // so check that we don't need to perfom substitution if !substs.needs_subst() { let param_env = cx.tcx.param_env(trait_id); @@ -73,9 +73,12 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall { let expr_span = expr.span; cx.struct_span_lint(NOOP_METHOD_CALL, expr_span, |lint| { - let message = "call to method that does nothing"; + let method = &call.ident.name; + let message = format!("call to `.{}()` on a reference in this situation does nothing", &method); lint.build(&message) .span_label(expr_span, "unnecessary method call") + .note("the type the method is being called on and the return type are functionally equivalent.") + .note("therefore, the method call doesn't actually do anything and can be removed.") .emit() }); } |
