Show the unused type for unused_results lint

I think it's helpful to know what type was unused when looking at these
warnings. The type will likely determine whether the result *should* be
used, or whether it should just be ignored.

Including the type also matches the behavior of the `must_use` lint:
unused `SomeType` that must be used.
This commit is contained in:
Noah Lev 2021-12-11 17:54:53 -08:00
parent 229d0a9412
commit f53e489e6e
3 changed files with 5 additions and 3 deletions

View File

@ -169,7 +169,9 @@ fn check_stmt(&mut self, cx: &LateContext<'_>, s: &hir::Stmt<'_>) {
}
if !(type_permits_lack_of_use || fn_warned || op_warned) {
cx.struct_span_lint(UNUSED_RESULTS, s.span, |lint| lint.build("unused result").emit());
cx.struct_span_lint(UNUSED_RESULTS, s.span, |lint| {
lint.build(&format!("unused result of type `{}`", ty)).emit()
});
}
// Returns whether an error has been emitted (and thus another does not need to be later).

View File

@ -31,7 +31,7 @@ fn test2() {
}
fn main() {
foo::<isize>(); //~ ERROR: unused result
foo::<isize>(); //~ ERROR: unused result of type `isize`
foo::<MustUse>(); //~ ERROR: unused `MustUse` that must be used
foo::<MustUseMsg>(); //~ ERROR: unused `MustUseMsg` that must be used
//~^ NOTE: some message

View File

@ -18,7 +18,7 @@ LL | foo::<MustUseMsg>();
|
= note: some message
error: unused result
error: unused result of type `isize`
--> $DIR/unused-result.rs:34:5
|
LL | foo::<isize>();