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

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

Closed
estebank opened this issue Jan 31, 2019 · 9 comments · Fixed by #65153
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints D-papercut Diagnostics: An error or lint that needs small tweaks. P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@estebank
Copy link
Contributor

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.

@estebank estebank added the A-diagnostics Area: Messages for errors, warnings, and lints label Jan 31, 2019
@Centril
Copy link
Contributor

Centril commented Jan 31, 2019

How about?:

error[E0451]: field `0` of tuple struct `a::Error` is private

@csmoe
Copy link
Member

csmoe commented Jan 31, 2019

in addition to @Centril 's proposal, it should locate the exact position of the private fields:

struct Foo(pub i32, i32, pub i32, i32);
                    ^^^           ^^^

@lnicola
Copy link
Member

lnicola commented Jan 31, 2019

Is there a good reason why the three test cases give completely different error messages?

@estebank
Copy link
Contributor Author

This is actually a regression from 1.16:

error[E0450]: cannot invoke tuple struct constructor with private fields
 --> <source>:6:13
  |
2 |     pub struct Error(usize);
  |                      ------ private field declared here
...
6 |     let x = a::Error(3);
  |             ^^^^^^^^ cannot construct with a private field

@estebank estebank added the regression-from-stable-to-stable Performance or correctness regression from one stable version to another. label Jan 31, 2019
@cramertj
Copy link
Member

cramertj commented Jul 8, 2019

ping on this, which still reproduces.

@estebank estebank added P-high High priority T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 12, 2019
@estebank
Copy link
Contributor Author

cc @petrochenkov as this overlaps with a lot of the work he's been doing.

@pnkfelix
Copy link
Member

pnkfelix commented Oct 3, 2019

triage: I personally don't think this should be P-high, as in I don't think it should be part of the triage docket for T-compiler every week.

But I won't downgrade it yet.

First, lets tag it as E-needs-mentor, and see if anyone steps up to provide instructions for a solution here.

@estebank estebank added the D-papercut Diagnostics: An error or lint that needs small tweaks. label Oct 4, 2019
@da-x
Copy link
Member

da-x commented Oct 6, 2019

Posted a PR to fix this - #65153.

@jonas-schievink
Copy link
Contributor

Duplicate of #39703

@jonas-schievink jonas-schievink marked this as a duplicate of #39703 Oct 6, 2019
@bors bors closed this as completed in 898f36c Oct 10, 2019
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 D-papercut Diagnostics: An error or lint that needs small tweaks. P-high High priority regression-from-stable-to-stable Performance or correctness regression from one stable version to another. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
8 participants