diff --git a/compiler/rustc_passes/src/liveness.rs b/compiler/rustc_passes/src/liveness.rs index 06eb76c30c5..24fac199911 100644 --- a/compiler/rustc_passes/src/liveness.rs +++ b/compiler/rustc_passes/src/liveness.rs @@ -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) } diff --git a/tests/ui/reachable/unreachable-by-call-arguments-issue-139627.rs b/tests/ui/reachable/unreachable-by-call-arguments-issue-139627.rs index 422ae95e8b7..b3310ac1c75 100644 --- a/tests/ui/reachable/unreachable-by-call-arguments-issue-139627.rs +++ b/tests/ui/reachable/unreachable-by-call-arguments-issue-139627.rs @@ -1,3 +1,4 @@ +//@ check-pass #![deny(unreachable_code)] #![deny(unused)] @@ -5,9 +6,9 @@ pub enum Void {} pub struct S(T); -pub fn foo(void: Void, void1: Void) { //~ ERROR unused variable: `void1` - let s = S(void); //~ ERROR unused variable: `s` - drop(s); //~ ERROR unreachable expression +pub fn foo(void: Void, void1: Void) { + let s = S(void); + drop(s); let s1 = S { 0: void1 }; drop(s1); } diff --git a/tests/ui/reachable/unreachable-by-call-arguments-issue-139627.stderr b/tests/ui/reachable/unreachable-by-call-arguments-issue-139627.stderr deleted file mode 100644 index ce24705324e..00000000000 --- a/tests/ui/reachable/unreachable-by-call-arguments-issue-139627.stderr +++ /dev/null @@ -1,36 +0,0 @@ -error: unreachable expression - --> $DIR/unreachable-by-call-arguments-issue-139627.rs:10:10 - | -LL | let s = S(void); - | ------- any code following this expression is unreachable -LL | drop(s); - | ^ unreachable expression - | -note: this expression has type `S`, which is uninhabited - --> $DIR/unreachable-by-call-arguments-issue-139627.rs:9:13 - | -LL | let s = S(void); - | ^^^^^^^ -note: the lint level is defined here - --> $DIR/unreachable-by-call-arguments-issue-139627.rs:2:9 - | -LL | #![deny(unused)] - | ^^^^^^ - = note: `#[deny(unreachable_code)]` implied by `#[deny(unused)]` - -error: unused variable: `s` - --> $DIR/unreachable-by-call-arguments-issue-139627.rs:9:9 - | -LL | let s = S(void); - | ^ help: if this is intentional, prefix it with an underscore: `_s` - | - = note: `#[deny(unused_variables)]` implied by `#[deny(unused)]` - -error: unused variable: `void1` - --> $DIR/unreachable-by-call-arguments-issue-139627.rs:8:24 - | -LL | pub fn foo(void: Void, void1: Void) { - | ^^^^^ help: if this is intentional, prefix it with an underscore: `_void1` - -error: aborting due to 3 previous errors -