diff options
| author | Matthias Krüger <476013+matthiaskrgr@users.noreply.github.com> | 2025-04-17 06:25:16 +0200 | 
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-04-17 06:25:16 +0200 | 
| commit | 0757d24f71de8c5cb0758c41878b5ce93118878c (patch) | |
| tree | d94bdb8db912d72d645d39b475eb91830c16e49a | |
| parent | 6426050b68a4455db62131fd463b28fa063073ce (diff) | |
| parent | 8c8212ef12b13ccb635c81aa9e29915dd1c189e5 (diff) | |
| download | rust-0757d24f71de8c5cb0758c41878b5ce93118878c.tar.gz rust-0757d24f71de8c5cb0758c41878b5ce93118878c.zip  | |
Rollup merge of #139782 - xizheyin:issue-139627, r=wesleywiser
Consistent with treating Ctor Call as Struct in liveness analysis Fixes #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
| -rw-r--r-- | compiler/rustc_passes/src/liveness.rs | 5 | ||||
| -rw-r--r-- | tests/ui/reachable/unreachable-by-call-arguments-issue-139627.rs | 16 | 
2 files changed, 20 insertions, 1 deletions
diff --git a/compiler/rustc_passes/src/liveness.rs b/compiler/rustc_passes/src/liveness.rs index 7054bbf468b..4e9b7fd44d4 100644 --- a/compiler/rustc_passes/src/liveness.rs +++ b/compiler/rustc_passes/src/liveness.rs @@ -1020,7 +1020,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) } diff --git a/tests/ui/reachable/unreachable-by-call-arguments-issue-139627.rs b/tests/ui/reachable/unreachable-by-call-arguments-issue-139627.rs new file mode 100644 index 00000000000..b3310ac1c75 --- /dev/null +++ b/tests/ui/reachable/unreachable-by-call-arguments-issue-139627.rs @@ -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() {}  | 
