diff options
| author | Ryan Levick <ryan.levick@gmail.com> | 2021-01-08 11:37:52 +0100 |
|---|---|---|
| committer | Ryan Levick <me@ryanlevick.com> | 2021-03-03 11:22:52 +0100 |
| commit | 217c88655b1155796739edbf415e7ce37d30830b (patch) | |
| tree | 7ae1bb24e8eb4e8ed865e6f424e9d3ffaa4a7e4e | |
| parent | c5ff54cbdb6b0da742110b416cdbcf0ca0ff0fc4 (diff) | |
| download | rust-217c88655b1155796739edbf415e7ce37d30830b.tar.gz rust-217c88655b1155796739edbf415e7ce37d30830b.zip | |
Improve warning
| -rw-r--r-- | compiler/rustc_lint/src/noop_method_call.rs | 10 | ||||
| -rw-r--r-- | src/test/ui/lint/noop-method-call.rs | 8 | ||||
| -rw-r--r-- | src/test/ui/lint/noop-method-call.stderr | 16 |
3 files changed, 18 insertions, 16 deletions
diff --git a/compiler/rustc_lint/src/noop_method_call.rs b/compiler/rustc_lint/src/noop_method_call.rs index dad557128f8..b9b5009d9dd 100644 --- a/compiler/rustc_lint/src/noop_method_call.rs +++ b/compiler/rustc_lint/src/noop_method_call.rs @@ -70,11 +70,13 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall { .iter() .any(|s| cx.tcx.is_diagnostic_item(*s, i.def_id())) { - let span = expr.span; + let expr_span = expr.span; - cx.struct_span_lint(NOOP_METHOD_CALL, span, |lint| { - let message = "call to noop method"; - lint.build(&message).emit() + cx.struct_span_lint(NOOP_METHOD_CALL, expr_span, |lint| { + let message = "call to method that does nothing"; + lint.build(&message) + .span_label(expr_span, "unnecessary method call") + .emit() }); } } diff --git a/src/test/ui/lint/noop-method-call.rs b/src/test/ui/lint/noop-method-call.rs index 4b81e04d3f7..b8ff75845bd 100644 --- a/src/test/ui/lint/noop-method-call.rs +++ b/src/test/ui/lint/noop-method-call.rs @@ -21,19 +21,19 @@ impl<T> Deref for DerefExample<T> { fn main() { let foo = &Foo(1u32); - let foo_clone: &Foo<u32> = foo.clone(); //~ WARNING call to noop method + let foo_clone: &Foo<u32> = foo.clone(); //~ WARNING call to method that does nothing [noop_method_call] let bar = &Bar(1u32); let bar_clone: Bar<u32> = bar.clone(); let deref = &&DerefExample(12u32); - let derefed: &DerefExample<u32> = deref.deref(); //~ WARNING call to noop method + let derefed: &DerefExample<u32> = deref.deref(); //~ WARNING call to method that does nothing [noop_method_call] let deref = &DerefExample(12u32); let derefed: &u32 = deref.deref(); let a = &&Foo(1u32); - let borrowed: &Foo<u32> = a.borrow(); //~ WARNING call to noop method + let borrowed: &Foo<u32> = a.borrow(); //~ WARNING call to method that does nothing [noop_method_call] } fn generic<T>(foo: &Foo<T>) { @@ -41,5 +41,5 @@ fn generic<T>(foo: &Foo<T>) { } fn non_generic(foo: &Foo<u32>) { - foo.clone(); //~ WARNING call to noop method + foo.clone(); //~ WARNING call to method that does nothing [noop_method_call] } diff --git a/src/test/ui/lint/noop-method-call.stderr b/src/test/ui/lint/noop-method-call.stderr index 1120adee121..f5b766f4233 100644 --- a/src/test/ui/lint/noop-method-call.stderr +++ b/src/test/ui/lint/noop-method-call.stderr @@ -1,28 +1,28 @@ -warning: call to noop method +warning: call to method that does nothing --> $DIR/noop-method-call.rs:24:32 | LL | let foo_clone: &Foo<u32> = foo.clone(); - | ^^^^^^^^^^^ + | ^^^^^^^^^^^ unnecessary method call | = note: `#[warn(noop_method_call)]` on by default -warning: call to noop method +warning: call to method that does nothing --> $DIR/noop-method-call.rs:30:39 | LL | let derefed: &DerefExample<u32> = deref.deref(); - | ^^^^^^^^^^^^^ + | ^^^^^^^^^^^^^ unnecessary method call -warning: call to noop method +warning: call to method that does nothing --> $DIR/noop-method-call.rs:36:31 | LL | let borrowed: &Foo<u32> = a.borrow(); - | ^^^^^^^^^^ + | ^^^^^^^^^^ unnecessary method call -warning: call to noop method +warning: call to method that does nothing --> $DIR/noop-method-call.rs:44:5 | LL | foo.clone(); - | ^^^^^^^^^^^ + | ^^^^^^^^^^^ unnecessary method call warning: 4 warnings emitted |
