8000 Fix unused_result lint triggering when a function returns `()`, `!` or an empty enum by pengowen123 · Pull Request #43813 · rust-lang/rust · GitHub
[go: up one dir, main page]

Skip to content

Fix unused_result lint triggering when a function returns (), ! or an empty enum #43813

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

Merged
merged 2 commits into from
Aug 13, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Don't trigger unused_result on functions returning empty enums
  • Loading branch information
pengowen123 committed Aug 12, 2017
commit eeb748aa12a3bb7f6bbd1205385fa0a0adbef90c
8 changes: 7 additions & 1 deletion src/librustc_lint/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
let ty_warned = match t.sty {
ty::TyTuple(ref tys, _) if tys.is_empty() => return,
ty::TyNever => return,
Copy link
Member

Choose a reason for hiding this comment

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

Should this also apply to enum Void {}, and other such uninhabited types? (Possibly like #38069?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Makes sense to me. I'll add that.

ty::TyAdt(def, _) => check_must_use(cx, def.did, s.span, ""),
ty::TyAdt(def, _) => {
if def.variants.is_empty() {
return;
} else {
check_must_use(cx, def.did, s.span, "")
}
},
_ => false,
};

Expand Down
7 changes: 7 additions & 0 deletions src/test/ui/issue-43806.rs
7547
Original file line numberDiff line number Diff line change
Expand Up @@ -12,15 +12,22 @@

#![deny(unused_results)]

enum Void {}

fn foo() {}

fn bar() -> ! {
loop {}
}

fn baz() -> Void {
loop {}
}

fn qux() {
foo();
bar();
baz();
}

fn main() {}
0