Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show the unused type for unused_results lint #91818

Merged
merged 1 commit into from
Dec 18, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion compiler/rustc_lint/src/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/lint/unused/unused-result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/lint/unused/unused-result.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ LL | foo::<MustUseMsg>();
|
= note: some message

error: unused result
error: unused result of type `isize`
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively, the type could be displayed in a note, but using the title is consistent with unused_must_use and easier to scan IMO.

--> $DIR/unused-result.rs:34:5
|
LL | foo::<isize>();
Expand Down