Skip to content

Commit

Permalink
Resolve dead_code and unused_variables warnings
Browse files Browse the repository at this point in the history
Summary:
Rust 1.79's dead code scanner is more precise than previous versions. `pub` is no longer sufficient to hide a data structure field from the lint. It actually looks at whether an unused pub field is reachable from outside the crate.

In the following example, the field `field` is considered dead code by Rust 1.79 and not by 1.78.

```lang=rust
mod module {
    pub struct Struct {
        pub field: i32,
    }

    impl Struct {
        pub fn new() -> Self {
            Struct { field: 0 }
        }
    }
}

pub fn repro() {
    let _ = Struct::new();
}
```

Reviewed By: zertosh, JakobDegen

Differential Revision: D59623034

fbshipit-source-id: 6a4e2fb6e5be410d5127b451704df74ecdd42bf0
  • Loading branch information
David Tolnay authored and facebook-github-bot committed Jul 11, 2024
1 parent 04bf55d commit d2be47a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/lockfile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::Paths;

#[derive(Deserialize, Debug)]
pub struct Lockfile {
#[allow(dead_code)]
pub version: Hopefully3,
#[serde(rename = "package")]
pub packages: Vec<LockfilePackage>,
Expand Down
6 changes: 6 additions & 0 deletions src/srcfiles.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,25 @@ pub struct Error {
#[derive(Debug)]
pub enum ErrorKind {
FileError {
#[allow(dead_code)]
source_path: PathBuf,
source: io::Error,
},
IncludeNotFound {
#[allow(dead_code)]
source_path: PathBuf,
},
ModuleNotFound {
#[allow(dead_code)]
default_path: PathBuf,
#[allow(dead_code)]
secondary_path: Option<PathBuf>,
},
ParserError {
#[allow(dead_code)]
source_path: PathBuf,
source: syn::Error,
#[allow(dead_code)]
line: usize,
},
}
Expand Down

0 comments on commit d2be47a

Please sign in to comment.