Skip to content

Commit 6e90e8b

Browse files
authored
Rollup merge of rust-lang#91818 - camelid:unused-result-type, r=jackh726
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.
2 parents 84fbd22 + f53e489 commit 6e90e8b

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

compiler/rustc_lint/src/unused.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,9 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
169169
}
170170

171171
if !(type_permits_lack_of_use || fn_warned || op_warned) {
172-
cx.struct_span_lint(UNUSED_RESULTS, s.span, |lint| lint.build("unused result").emit());
172+
cx.struct_span_lint(UNUSED_RESULTS, s.span, |lint| {
173+
lint.build(&format!("unused result of type `{}`", ty)).emit()
174+
});
173175
}
174176

175177
// Returns whether an error has been emitted (and thus another does not need to be later).

src/test/ui/lint/unused/unused-result.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ fn test2() {
3131
}
3232

3333
fn main() {
34-
foo::<isize>(); //~ ERROR: unused result
34+
foo::<isize>(); //~ ERROR: unused result of type `isize`
3535
foo::<MustUse>(); //~ ERROR: unused `MustUse` that must be used
3636
foo::<MustUseMsg>(); //~ ERROR: unused `MustUseMsg` that must be used
3737
//~^ NOTE: some message

src/test/ui/lint/unused/unused-result.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ LL | foo::<MustUseMsg>();
1818
|
1919
= note: some message
2020

21-
error: unused result
21+
error: unused result of type `isize`
2222
--> $DIR/unused-result.rs:34:5
2323
|
2424
LL | foo::<isize>();

0 commit comments

Comments
 (0)