1
Fork 0

Improve warning

This commit is contained in:
Ryan Levick 2021-01-08 11:37:52 +01:00 committed by Ryan Levick
parent c5ff54cbdb
commit 217c88655b
3 changed files with 18 additions and 16 deletions

View file

@ -70,11 +70,13 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall {
.iter() .iter()
.any(|s| cx.tcx.is_diagnostic_item(*s, i.def_id())) .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| { cx.struct_span_lint(NOOP_METHOD_CALL, expr_span, |lint| {
let message = "call to noop method"; let message = "call to method that does nothing";
lint.build(&message).emit() lint.build(&message)
.span_label(expr_span, "unnecessary method call")
.emit()
}); });
} }
} }

View file

@ -21,19 +21,19 @@ impl<T> Deref for DerefExample<T> {
fn main() { fn main() {
let foo = &Foo(1u32); 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 = &Bar(1u32);
let bar_clone: Bar<u32> = bar.clone(); let bar_clone: Bar<u32> = bar.clone();
let deref = &&DerefExample(12u32); 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 deref = &DerefExample(12u32);
let derefed: &u32 = deref.deref(); let derefed: &u32 = deref.deref();
let a = &&Foo(1u32); 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>) { fn generic<T>(foo: &Foo<T>) {
@ -41,5 +41,5 @@ fn generic<T>(foo: &Foo<T>) {
} }
fn non_generic(foo: &Foo<u32>) { 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]
} }

View file

@ -1,28 +1,28 @@
warning: call to noop method warning: call to method that does nothing
--> $DIR/noop-method-call.rs:24:32 --> $DIR/noop-method-call.rs:24:32
| |
LL | let foo_clone: &Foo<u32> = foo.clone(); LL | let foo_clone: &Foo<u32> = foo.clone();
| ^^^^^^^^^^^ | ^^^^^^^^^^^ unnecessary method call
| |
= note: `#[warn(noop_method_call)]` on by default = 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 --> $DIR/noop-method-call.rs:30:39
| |
LL | let derefed: &DerefExample<u32> = deref.deref(); 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 --> $DIR/noop-method-call.rs:36:31
| |
LL | let borrowed: &Foo<u32> = a.borrow(); 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 --> $DIR/noop-method-call.rs:44:5
| |
LL | foo.clone(); LL | foo.clone();
| ^^^^^^^^^^^ | ^^^^^^^^^^^ unnecessary method call
warning: 4 warnings emitted warning: 4 warnings emitted