diff options
| author | Noah Lev <camelidcamel@gmail.com> | 2021-12-11 17:54:53 -0800 |
|---|---|---|
| committer | Noah Lev <camelidcamel@gmail.com> | 2021-12-11 17:58:11 -0800 |
| commit | f53e489e6e721f914f6a3c59a7792dc5dfb80ad2 (patch) | |
| tree | 50cc063fca88ca0d0f7e62b8a6f01d3e7594dee5 | |
| parent | 229d0a94128d036fb07dafdb1f73db5eba5ab0d3 (diff) | |
| download | rust-f53e489e6e721f914f6a3c59a7792dc5dfb80ad2.tar.gz rust-f53e489e6e721f914f6a3c59a7792dc5dfb80ad2.zip | |
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.
| -rw-r--r-- | compiler/rustc_lint/src/unused.rs | 4 | ||||
| -rw-r--r-- | src/test/ui/lint/unused/unused-result.rs | 2 | ||||
| -rw-r--r-- | 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 da1edcf6fe3..ed24b94e2fd 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 a65e98990dc..e283eaa88dd 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::<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 diff --git a/src/test/ui/lint/unused/unused-result.stderr b/src/test/ui/lint/unused/unused-result.stderr index 1b1dcab3a1b..087e06341cd 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::<MustUseMsg>(); | = note: some message -error: unused result +error: unused result of type `isize` --> $DIR/unused-result.rs:34:5 | LL | foo::<isize>(); |
