Skip to content

Consistent with treating Ctor Call as Struct in liveness analysis #139782

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
Apr 17, 2025
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
5 changes: 4 additions & 1 deletion compiler/rustc_passes/src/liveness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,10 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
}

hir::ExprKind::Call(ref f, args) => {
let succ = self.check_is_ty_uninhabited(expr, succ);
let is_ctor = |f: &Expr<'_>| matches!(f.kind, hir::ExprKind::Path(hir::QPath::Resolved(_, path)) if matches!(path.res, rustc_hir::def::Res::Def(rustc_hir::def::DefKind::Ctor(_, _), _)));
let succ =
if !is_ctor(f) { self.check_is_ty_uninhabited(expr, succ) } else { succ };

let succ = self.propagate_through_exprs(args, succ);
self.propagate_through_expr(f, succ)
}
Expand Down
16 changes: 16 additions & 0 deletions tests/ui/reachable/unreachable-by-call-arguments-issue-139627.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//@ check-pass
#![deny(unreachable_code)]
#![deny(unused)]

pub enum Void {}

pub struct S<T>(T);

pub fn foo(void: Void, void1: Void) {
let s = S(void);
drop(s);
let s1 = S { 0: void1 };
drop(s1);
}

fn main() {}
Loading