Skip to content

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

Closed

Description

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

No one assigned

    Labels

    A-diagnosticsArea: Messages for errors, warnings, and lintsC-enhancementCategory: An issue proposing an enhancement or a PR with one.D-confusingDiagnostics: Confusing error or lint that should be reworked.D-newcomer-roadblockDiagnostics: Confusing error or lint; hard to understand for new users.D-papercutDiagnostics: An error or lint that needs small tweaks.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions