Skip to content

Commit 8c8212e

Browse files
committed
Consistent with treating Ctor Call as Struct in liveness analysis
Signed-off-by: xizheyin <[email protected]>
1 parent edfdb92 commit 8c8212e

File tree

3 files changed

+8
-40
lines changed

3 files changed

+8
-40
lines changed

compiler/rustc_passes/src/liveness.rs

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

10231023
hir::ExprKind::Call(ref f, args) => {
1024-
let succ = self.check_is_ty_uninhabited(expr, succ);
1024+
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(_, _), _)));
1025+
let succ =
1026+
if !is_ctor(f) { self.check_is_ty_uninhabited(expr, succ) } else { succ };
1027+
10251028
let succ = self.propagate_through_exprs(args, succ);
10261029
self.propagate_through_expr(f, succ)
10271030
}

tests/ui/reachable/unreachable-by-call-arguments-issue-139627.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
1+
//@ check-pass
12
#![deny(unreachable_code)]
23
#![deny(unused)]
34

45
pub enum Void {}
56

67
pub struct S<T>(T);
78

8-
pub fn foo(void: Void, void1: Void) { //~ ERROR unused variable: `void1`
9-
let s = S(void); //~ ERROR unused variable: `s`
10-
drop(s); //~ ERROR unreachable expression
9+
pub fn foo(void: Void, void1: Void) {
10+
let s = S(void);
11+
drop(s);
1112
let s1 = S { 0: void1 };
1213
drop(s1);
1314
}

tests/ui/reachable/unreachable-by-call-arguments-issue-139627.stderr

-36
This file was deleted.

0 commit comments

Comments
 (0)