8000 Apply #[must_use] lint to components of tuples by varkor · Pull Request #61100 · rust-lang/rust · GitHub
[go: up one dir, main page]

Skip to content

Apply #[must_use] lint to components of tuples #61100

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 7 commits into from
Jun 3, 2019
Merged
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
Next Next commit
Fix issue with recursively encountering uninhabited type
  • Loading branch information
varkor committed Jun 3, 2019
commit 3c768ade4d7c18db873c201a8aebda0f9c243a30
21 changes: 10 additions & 11 deletions src/librustc_lint/unused.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
}

let ty = cx.tables.expr_ty(&expr);
let type_permits_lack_of_use = if ty.is_unit()
|| cx.tcx.is_ty_uninhabited_from(
cx.tcx.hir().get_module_parent_by_hir_id(expr.hir_id), ty)
{
true
} else {
check_must_use_ty(cx, ty, &expr, s.span)
};
let type_permits_lack_of_use = check_must_use_ty(cx, ty, &expr, s.span);

let mut fn_warned = false;
let mut op_warned = false;
Expand Down Expand Up @@ -135,12 +128,18 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for UnusedResults {
}

// Returns whether an error has been emitted (and thus another does not need to be later).
fn check_must_use_ty(
cx: &LateContext<'_, '_>,
ty: Ty<'_>,
fn check_must_use_ty<'tcx>(
cx: &LateContext<'_, 'tcx>,
ty: Ty<'tcx>,
expr: &hir::Expr,
span: Span,
) -> bool {
if ty.is_unit() || cx.tcx.is_ty_uninhabited_from(
cx.tcx.hir().get_module_parent_by_hir_id(expr.hir_id), ty)
{
return true;
}

match ty.sty {
ty::Adt(def, _) => check_must_use_def(cx, def.did, span, "", ""),
ty::Opaque(def, _) => {
Expand Down
0