Skip to content

Better error message when attempting to instantiate tuple structs with private fields #58017

Closed
@estebank

Description

@estebank

Given

mod a {
    pub struct Error(usize);
}

fn main(){
    let x = a::Error(3);
}

we emit

error[E0603]: tuple struct `Error` is private
 --> src/main.rs:6:16
  |
6 |     let x = a::Error(3);
  |                ^^^^^

which is confusing and inconsistent with the same error in a regular struct:

error[E0451]: field `a` of struct `a::Error` is private
 --> src/main.rs:6:23
  |
6 |     let x = a::Error {a: 3};
  |                       ^^^^ field `a` is private

This has confused users in the past. CC #57951 and #52144, which are somewhat related.

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsD-papercutDiagnostics: An error or lint that needs small tweaks.P-highHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions