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

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

estebank opened this issue Jan 31, 2019 · 9 comments · Fixed by #65153

Comments

@estebank
Copy link
Contributor

@estebank estebank commented Jan 31, 2019

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.

@Centril

This comment has been minimized.

Copy link
Member

@Centril Centril commented Jan 31, 2019

How about?:

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

This comment has been minimized.

Copy link
Member

@csmoe 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

This comment has been minimized.

Copy link
Contributor

@lnicola lnicola commented Jan 31, 2019

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

@estebank

This comment has been minimized.

Copy link
Contributor Author

@estebank estebank commented Jan 31, 2019

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
@cramertj

This comment has been minimized.

Copy link
Member

@cramertj cramertj commented Jul 8, 2019

ping on this, which still reproduces.

@estebank

This comment has been minimized.

Copy link
Contributor Author

@estebank estebank commented Jul 16, 2019

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

@pnkfelix

This comment has been minimized.

Copy link
Member

@pnkfelix 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.

@da-x

This comment has been minimized.

Copy link
Member

@da-x da-x commented Oct 6, 2019

Posted a PR to fix this - #65153.

@jonas-schievink

This comment has been minimized.

Copy link
Member

@jonas-schievink jonas-schievink commented Oct 6, 2019

Duplicate of #39703

@jonas-schievink jonas-schievink marked this as a duplicate of #39703 Oct 6, 2019
@bors bors closed this in 898f36c Oct 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
8 participants
You can’t perform that action at this time.