Rust-GCC / Rust-GCC/gccrs

Invalid never constructed warning from DeadCode scan

Open
#667 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug diagnostic
Dominant language
C++
Stars
2.9k
Forks
230
Avg merge
19h 55m
Merged PRs (30d)
67

Description

I tried this code:

extern "C" {
    fn printf(s: *const i8, ...);
}

trait A {
    fn a() -> i32 {
        123
    }
}

trait B: A {
    fn b() -> i32 {
        <T as A>::a() + 456
    }
}

struct T;
impl A for T {
    fn a() -> i32 {
        321
    }
}

struct S;
impl A for S {}
impl B for S {}

pub fn main() {
    let aa = S::a();
    let bb = S::b();

    unsafe {
        let a = "%i, %i\n\0";
        let b = a as *const str;
        let c = b as *const i8;

        printf(c, aa, bb);
    };
}

I expected to see this happen:

I expect no warning to occur on this code see: https://godbolt.org/z/3Ex35d13s

Instead, this happened:

test.rs:18:1: warning: struct is never constructed: ‘T’
   18 | struct T;
      | ^

This is occurring as the dead-code scan does not account for QualifiedPaths

Meta
  • What version of Rust GCC were you using, git sha if possible. a1c87bfea6c5e2fd6b2d23b12b563fcaf5ec09a1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the provided Rust snippet and inspect the dead-code scan's handling of QualifiedPaths. Confirm that the scan incorrectly reports struct T as never constructed; done means the warning is no longer emitted for this example.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.