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

Private tuple struct field causes confusing error message in cross-crate usage #57951

Closed
lnicola opened this issue Jan 28, 2019 · 4 comments
Closed
Labels
A-diagnostics Area: Messages for errors, warnings, and lints C-enhancement Category: An issue proposing an enhancement or a PR with one. D-confusing Diagnostics: Confusing error or lint that should be reworked. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@lnicola
Copy link
Member

lnicola commented Jan 28, 2019

Related to, but not a duplicate of #52144.

use headers::SetCookie;

fn main() {
    let _ = SetCookie(vec![]);
}
[package]
name = "e0423-test"
version = "0.1.0"
edition = "2018"

[dependencies]
headers = "0.2.0"
    Checking e0423-test v0.1.0 (/home/grayshade/e0423-test)
error[E0423]: expected function, found struct `SetCookie`
 --> src/main.rs:4:13
  |
4 |     let _ = SetCookie(vec![]);
  |             ^^^^^^^^^ did you mean `SetCookie { /* fields */ }`?

error: aborting due to previous error

Interestingly, the following code:

mod cookie {
    pub struct HeaderValue;
    
    pub struct SetCookie(Vec<HeaderValue>);
}

use cookie::SetCookie;

fn main() {
    let _ = SetCookie(vec![]);
}

Gives a better, but still confusing error message:

error[E0423]: expected function, found struct `SetCookie`
  --> src/main.rs:10:13
   |
10 |     let _ = SetCookie(vec![]);
   |             ^^^^^^^^^ constructor is not visible here due to private fields
help: possible better candidate is found in another module, you can import it into scope
   |
7  | use crate::cookie::SetCookie;
   |

error: aborting due to previous error

Tested in rustc 1.34.0-nightly (c1c3c4e95 2019-01-29).

@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jan 28, 2019
@cramertj
Copy link
Member

cramertj commented Jul 8, 2019

cc @estebank

@estebank estebank added D-confusing Diagnostics: Confusing error or lint that should be reworked. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. D-papercut Diagnostics: An error or lint that needs small tweaks. labels Jan 6, 2020
@crlf0710 crlf0710 added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jun 11, 2020
@vext01
Copy link
Contributor

vext01 commented Jan 27, 2021

I was about to raise an issue for this too.

Yesterday a colleague and I spent 20 minutes trying to figure out what had gone wrong with our code. In the end it was a simple as adding pub to a field, but the error message really confused us!

@vext01
Copy link
Contributor

vext01 commented Jan 27, 2021

Note also that the error message has changed slightly since this issue was raised:

error[E0423]: expected function, tuple struct or tuple variant, found struct `SetCookie`
  --> src/main.rs:4:17
   |
4  |         let _ = SetCookie(vec![]);
   |                 ^^^^^^^^^^^^^^^^^ help: use struct literal syntax instead: `SetCookie { 0: val }`
   | 
  ::: /home/vext01/.cargo/registry/src/github.com-1ecc6299db9ec823/headers-0.2.3/src/common/set_cookie.rs:56:1
   |
56 | pub struct SetCookie(Vec<::HeaderValue>);
   | ----------------------------------------- `SetCookie` defined here

@WaffleLapkin
Copy link
Member

WaffleLapkin commented Oct 12, 2022

Since the last comment the output has changed again:

error[E0423]: cannot initialize a tuple struct which contains private fields
  --> src/main.rs:4:13
   |
4  |     let _ = SetCookie(vec![]);
   |             ^^^^^^^^^
   |
note: constructor is not visible here due to private fields
  --> /home/waffle/.cargo/registry/src/github.com-1ecc6299db9ec823/headers-0.2.3/src/common/set_cookie.rs:56:22
   |
56 | pub struct SetCookie(Vec<::HeaderValue>);
   |                      ^^^^^^^^^^^^^^^^^^ private field

I think that the output is basically perfect, so this issue can be closed 😄

I believe this diagnostic was updated by #78401.

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 C-enhancement Category: An issue proposing an enhancement or a PR with one. D-confusing Diagnostics: Confusing error or lint that should be reworked. D-newcomer-roadblock Diagnostics: Confusing error or lint; hard to understand for new users. D-papercut Diagnostics: An error or lint that needs small tweaks. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

No branches or pull requests

7 participants