Skip to content

link-dead-code limitations (bad for code coverage) #39293

Open
@malbarbo

Description

@malbarbo

Consider a cargo project (dead) with this src/lib.rs file:

pub fn fun0() {}

pub fn fun1<T>() {}

pub trait Trait {
    fn fun2(&self);
    fn fun3(&self) {}
}

impl Trait for () {
    fn fun2(&self) {}
}

Running

cargo clean && RUSTFLAGS='-C link-dead-code' cargo test && cargo sym -C target/debug/dead* | grep dead::

outputs

0000000000015e60 dead::fun0::he72896c4e971b738
0000000000015e70 <() as dead::Trait>::fun2::h21fa8b5ef4270ce1
0000000000015e90 dead::__test::main::h824aaf01f68ecd0a

We can observe that that only fun0 and <() as Trait>::fun2 is included (also checked with nm and running kcov). Not including fun1 and Trait::fun2 makes code coverage inflates (using kcov).

I can see that fun1 and Trait::fun2 is not included because they need to be monomorphised. One partial solution would be to monomorphise the default methods implementations for every type that implements the trait, but I think this could blow the binary size and compilation time.

Would it be possible to add this symbols without monomorphisation? Or maybe creating a monomorphised version that just panics? (Could all generic paramaters be set to !?)

Metadata

Metadata

Assignees

No one assigned

    Labels

    -Clink-dead-codeLinkage option: -Clink-dead-codeC-feature-requestCategory: A feature request, i.e: not implemented / a PR.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions