Skip to content

“cannot initialize a tuple struct which contains private fields” with no tuple struct involved #148919

@kpreid

Description

@kpreid

Code

struct Foo {}
struct Bar {}

impl Foo {
    fn into_bar(self) -> Bar {
        Bar(self)
    }
}

Current output

error[E0423]: cannot initialize a tuple struct which contains private fields
 --> src/lib.rs:6:9
  |
6 |         Bar(self)
  |         ^^^
  |
  = note: constructor is not visible here due to private fields

Desired output

error[E0423]: expected function, tuple struct or tuple variant, found struct `Bar`
 --> src/lib.rs:6:9
  |
6 |         Bar(self)
  |         ^^^

Rationale and extra context

The message is incorrect in two ways:

  • Bar is not a tuple struct
  • Bar has no private fields

It appears that something is making too many assumptions about why a tuple struct constructor might not be visible at a specific call site.

Other cases

The incorrect diagnostic only occurs for Bar(self), and not when a normal variable is used in place of self. It also seems like sometimes the correct error is printed, nondeterministically, but I have not found consistent reproduction conditions.

Rust Version

rustc 1.93.0-nightly (01867557c 2025-11-12)
binary: rustc
commit-hash: 01867557cd7dbe256a031a7b8e28d05daecd75ab
commit-date: 2025-11-12
host: aarch64-apple-darwin
release: 1.93.0-nightly
LLVM version: 21.1.5

Anything else?

@rustbot label +regression-from-stable-to-nightly

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsI-prioritizeIssue: Indicates that prioritization has been requested for this issue.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-nightlyPerformance or correctness regression from stable to nightly.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions