Consistent with treating Ctor Call as Struct in liveness analysis

Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
This commit is contained in:
xizheyin 2025-04-14 14:29:14 +08:00
parent edfdb9205c
commit 8c8212ef12
No known key found for this signature in database
GPG key ID: 0A0D90BE99CEDEAD
3 changed files with 8 additions and 40 deletions

View file

@ -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)
}

View file

@ -1,3 +1,4 @@
//@ check-pass
#![deny(unreachable_code)]
#![deny(unused)]
@ -5,9 +6,9 @@ pub enum Void {}
pub struct S<T>(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);
}

View file

@ -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<Void>`, 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