Improve warning
This commit is contained in:
parent
c5ff54cbdb
commit
217c88655b
3 changed files with 18 additions and 16 deletions
|
@ -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()
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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]
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue