Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Public tuple structs give dead_code warnings on nightly #127735

Closed
djkato opened this issue Jul 14, 2024 · 5 comments
Closed

Public tuple structs give dead_code warnings on nightly #127735

djkato opened this issue Jul 14, 2024 · 5 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@djkato
Copy link

djkato commented Jul 14, 2024

Code

use serde::Serialize; // 1.0.203
#[derive(Serialize, Debug, Clone)]
#[serde(transparent)]
pub struct OrderCalculateTaxes(CheckoutCalculateTaxesResponse);

#[derive(Serialize, Debug, Clone)]
#[serde(transparent)]
pub struct ShippingListMethodsForCheckout(Vec<ShippingListMethodsForCheckoutVec>);

#[derive(Serialize, Debug, Clone)]
pub struct ShippingListMethodsForCheckoutVec {
    pub id: String,
    pub currency: String,
    pub maximum_delivery_days: Option<i32>,
}

#[derive(Serialize, Debug, Clone)]
pub struct CheckoutCalculateTaxesResponse {
    pub some_value: String,
}

Current output

warning: struct `OrderCalculateTaxes` is never constructed
 --> src/lib.rs:4:12
  |
4 | pub struct OrderCalculateTaxes(CheckoutCalculateTaxesResponse);
  |            ^^^^^^^^^^^^^^^^^^^
  |
  = note: `#[warn(dead_code)]` on by default

warning: struct `ShippingListMethodsForCheckout` is never constructed
 --> src/lib.rs:8:12
  |
8 | pub struct ShippingListMethodsForCheckout(Vec<ShippingListMethodsForCheckoutVec>);
  |            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

warning: `playground` (lib) generated 2 warnings
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.50s

Desired output

Compiling playground v0.0.1 (/playground)
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.72s

Rationale and extra context

https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=a317497cf4017ba3f7b5d963270b032e
Nightly version gives dead code errors on public tuple structs, and on stable it doesn't.

Other cases

No response

Rust Version

(master)> rustc --version --verbose
rustc 1.81.0-nightly (d8a38b000 2024-06-19)
binary: rustc
commit-hash: d8a38b00024cd7156dea4ce8fd8ae113a2745e7f
commit-date: 2024-06-19
host: x86_64-unknown-linux-gnu
release: 1.81.0-nightly
LLVM version: 18.1.7

AND

On playground https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=a317497cf4017ba3f7b5d963270b032e

Anything else?

Not sure where to put this issue, if I labelled baldy, then I'm sorry 🙏

@djkato djkato added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 14, 2024
@eggyal
Copy link
Contributor

eggyal commented Jul 14, 2024

Because the fields are private, the structs can't be constructed by downstream crates and therefore the compiler is correct about dead code.

If you make the fields public, the warning goes away: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=83d9eb9d0cf35ee0a919b61b17acb168

@workingjubilee
Copy link
Member

workingjubilee commented Jul 14, 2024

@djkato
Copy link
Author

djkato commented Jul 14, 2024

Ooh, thanks @eggyal & @workingjubilee for explaining. Sorry, my mistake! So this means nightly is actually the new correct warning and stable is not correct?

@workingjubilee
Copy link
Member

workingjubilee commented Jul 14, 2024

Yes, previously a combination of incorrect handling of tuple structs and the Clone implementations were suppressing the lint.

@workingjubilee
Copy link
Member

Closing due to "working as intended", but feel free to reopen if you find something else odd here!

@workingjubilee workingjubilee closed this as not planned Won't fix, can't repro, duplicate, stale Jul 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

3 participants