From f53e489e6e721f914f6a3c59a7792dc5dfb80ad2 Mon Sep 17 00:00:00 2001 From: Noah Lev Date: Sat, 11 Dec 2021 17:54:53 -0800 Subject: [PATCH] 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. --- compiler/rustc_lint/src/unused.rs | 4 +++- src/test/ui/lint/unused/unused-result.rs | 2 +- src/test/ui/lint/unused/unused-result.stderr | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index da1edcf6fe3b4..ed24b94e2fd3b 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -169,7 +169,9 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults { } 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). diff --git a/src/test/ui/lint/unused/unused-result.rs b/src/test/ui/lint/unused/unused-result.rs index a65e98990dceb..e283eaa88dd13 100644 --- a/src/test/ui/lint/unused/unused-result.rs +++ b/src/test/ui/lint/unused/unused-result.rs @@ -31,7 +31,7 @@ fn test2() { } fn main() { - foo::(); //~ ERROR: unused result + foo::(); //~ ERROR: unused result of type `isize` foo::(); //~ ERROR: unused `MustUse` that must be used foo::(); //~ ERROR: unused `MustUseMsg` that must be used //~^ NOTE: some message diff --git a/src/test/ui/lint/unused/unused-result.stderr b/src/test/ui/lint/unused/unused-result.stderr index 1b1dcab3a1bc9..087e06341cdde 100644 --- a/src/test/ui/lint/unused/unused-result.stderr +++ b/src/test/ui/lint/unused/unused-result.stderr @@ -18,7 +18,7 @@ LL | foo::(); | = note: some message -error: unused result +error: unused result of type `isize` --> $DIR/unused-result.rs:34:5 | LL | foo::();