Skip to content

Commit 217c886

Browse files
committed
Improve warning
1 parent c5ff54c commit 217c886

File tree

3 files changed

+18
-16
lines changed

3 files changed

+18
-16
lines changed

compiler/rustc_lint/src/noop_method_call.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,13 @@ impl<'tcx> LateLintPass<'tcx> for NoopMethodCall {
7070
.iter()
7171
.any(|s| cx.tcx.is_diagnostic_item(*s, i.def_id()))
7272
{
73-
let span = expr.span;
73+
let expr_span = expr.span;
7474

75-
cx.struct_span_lint(NOOP_METHOD_CALL, span, |lint| {
76-
let message = "call to noop method";
77-
lint.build(&message).emit()
75+
cx.struct_span_lint(NOOP_METHOD_CALL, expr_span, |lint| {
76+
let message = "call to method that does nothing";
77+
lint.build(&message)
78+
.span_label(expr_span, "unnecessary method call")
79+
.emit()
7880
});
7981
}
8082
}

src/test/ui/lint/noop-method-call.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,25 +21,25 @@ impl<T> Deref for DerefExample<T> {
2121

2222
fn main() {
2323
let foo = &Foo(1u32);
24-
let foo_clone: &Foo<u32> = foo.clone(); //~ WARNING call to noop method
24+
let foo_clone: &Foo<u32> = foo.clone(); //~ WARNING call to method that does nothing [noop_method_call]
2525

2626
let bar = &Bar(1u32);
2727
let bar_clone: Bar<u32> = bar.clone();
2828

2929
let deref = &&DerefExample(12u32);
30-
let derefed: &DerefExample<u32> = deref.deref(); //~ WARNING call to noop method
30+
let derefed: &DerefExample<u32> = deref.deref(); //~ WARNING call to method that does nothing [noop_method_call]
3131

3232
let deref = &DerefExample(12u32);
3333
let derefed: &u32 = deref.deref();
3434

3535
let a = &&Foo(1u32);
36-
let borrowed: &Foo<u32> = a.borrow(); //~ WARNING call to noop method
36+
let borrowed: &Foo<u32> = a.borrow(); //~ WARNING call to method that does nothing [noop_method_call]
3737
}
3838

3939
fn generic<T>(foo: &Foo<T>) {
4040
foo.clone();
4141
}
4242

4343
fn non_generic(foo: &Foo<u32>) {
44-
foo.clone(); //~ WARNING call to noop method
44+
foo.clone(); //~ WARNING call to method that does nothing [noop_method_call]
4545
}
Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
warning: call to noop method
1+
warning: call to method that does nothing
22
--> $DIR/noop-method-call.rs:24:32
33
|
44
LL | let foo_clone: &Foo<u32> = foo.clone();
5-
| ^^^^^^^^^^^
5+
| ^^^^^^^^^^^ unnecessary method call
66
|
77
= note: `#[warn(noop_method_call)]` on by default
88

9-
warning: call to noop method
9+
warning: call to method that does nothing
1010
--> $DIR/noop-method-call.rs:30:39
1111
|
1212
LL | let derefed: &DerefExample<u32> = deref.deref();
13-
| ^^^^^^^^^^^^^
13+
| ^^^^^^^^^^^^^ unnecessary method call
1414

15-
warning: call to noop method
15+
warning: call to method that does nothing
1616
--> $DIR/noop-method-call.rs:36:31
1717
|
1818
LL | let borrowed: &Foo<u32> = a.borrow();
19-
| ^^^^^^^^^^
19+
| ^^^^^^^^^^ unnecessary method call
2020

21-
warning: call to noop method
21+
warning: call to method that does nothing
2222
--> $DIR/noop-method-call.rs:44:5
2323
|
2424
LL | foo.clone();
25-
| ^^^^^^^^^^^
25+
| ^^^^^^^^^^^ unnecessary method call
2626

2727
warning: 4 warnings emitted
2828

0 commit comments

Comments
 (0)