rust-lang / rust-lang/rust

Regression: false negative lint dead_code: dead code is not detected for struct if it implements FromStr

Open
#142,541 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-lints C-bug L-dead_code L-false-negative P-low regression-from-stable-to-stable T-compiler
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Code

I tried this code:

#![deny(dead_code)]

impl std::str::FromStr for Foo {
    type Err = ();
    fn from_str(_s: &str) -> Result<Self, Self::Err> {
        panic!();
    }
}

struct Foo;

fn main() {}

I expected to see this happen: compiler should report that struct Foo is never constructed

Instead, this happened: compiler didn't report this

Version it worked on

It most recently worked on: nightly-2019-08-27

Version with regression

nightly-2019-08-28

Notes

cargo-bisect-rustc reports that the following commits happened between these two versions:

get_commits_between returning commits, len: 5
commit[0] 2019-08-26: Auto merge of #63901 - estebank:unknown-receiver-type, r=zackmdavis
commit[1] 2019-08-27: Auto merge of #63926 - Centril:rollup-6kckn9n, r=Centril
commit[2] 2019-08-27: Auto merge of #63940 - Centril:rollup-47qe9gn, r=Centril
commit[3] 2019-08-27: Auto merge of #63639 - Mark-Simulacrum:rustdoc-clean-3, r=GuillaumeGomez
commit[4] 2019-08-27: Auto merge of #63922 - RalfJung:miri, r=nikomatsakis

@rustbot modify labels: +regression-from-stable-to-stable -regression-untriaged +A-lints +L-dead_code +L-false-negative

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

Reproduce the regression with the minimal Rust example using #![deny(dead_code)] and the FromStr implementation for Foo. Use cargo-bisect-rustc across nightly-2019-08-27 and nightly-2019-08-28, then inspect the five intervening commits. Done means the compiler reports that Foo is never constructed while retaining correct FromStr behavior.

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
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.