Skip to content

Commit 0757d24

Browse files
authored
Rollup merge of rust-lang#139782 - xizheyin:issue-139627, r=wesleywiser
Consistent with treating Ctor Call as Struct in liveness analysis Fixes rust-lang#139627 When `ExprKind::Call` is a `Ctor`, skips the checking of `expr` and only checks the arguments, thus being consistent with `ExprKind::Struct`. r? compiler
2 parents 6426050 + 8c8212e commit 0757d24

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

compiler/rustc_passes/src/liveness.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -1020,7 +1020,10 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
10201020
}
10211021

10221022
hir::ExprKind::Call(ref f, args) => {
1023-
let succ = self.check_is_ty_uninhabited(expr, succ);
1023+
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(_, _), _)));
1024+
let succ =
1025+
if !is_ctor(f) { self.check_is_ty_uninhabited(expr, succ) } else { succ };
1026+
10241027
let succ = self.propagate_through_exprs(args, succ);
10251028
self.propagate_through_expr(f, succ)
10261029
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//@ check-pass
2+
#![deny(unreachable_code)]
3+
#![deny(unused)]
4+
5+
pub enum Void {}
6+
7+
pub struct S<T>(T);
8+
9+
pub fn foo(void: Void, void1: Void) {
10+
let s = S(void);
11+
drop(s);
12+
let s1 = S { 0: void1 };
13+
drop(s1);
14+
}
15+
16+
fn main() {}

0 commit comments

Comments
 (0)