Skip to content

No warning for unread pub struct field in private module #119545

@tormeh

Description

@tormeh

I tried this code:

fn main() { let _ = foo::Bar1{baz: false}; let _ = foo::Bar2{baz: false}; } mod foo { pub struct Bar1 { pub baz: bool, } pub(crate) struct Bar2 { pub baz: bool, } }

I expected a "field baz is never read" warning for both Bar1 and Bar2 structs. Instead, I only got this warning for Bar2.

Meta

rustc --version --verbose:

rustc 1.75.0 (82e1608df 2023-12-21) binary: rustc commit-hash: 82e1608dfa6e0b5569232559e3d385fea5a93112 commit-date: 2023-12-21 host: x86_64-apple-darwin release: 1.75.0 LLVM version: 17.0.6 

Same behavior when running RUSTUP_TOOLCHAIN=nightly-2024-01-01-x86_64-apple-darwin cargo check

RUSTUP_TOOLCHAIN=nightly-2024-01-01-x86_64-apple-darwin rustc --version --verbose:

rustc 1.77.0-nightly (e51e98dde 2023-12-31) binary: rustc commit-hash: e51e98dde6a60637b6a71b8105245b629ac3fe77 commit-date: 2023-12-31 host: x86_64-apple-darwin release: 1.77.0-nightly LLVM version: 17.0.6 

Metadata

Metadata

Assignees

Labels

A-lintsArea: Lints (warnings about flaws in source code) such as unused_mut.A-visibilityArea: Visibility / privacyC-bugCategory: This is a bug.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