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

Misleading error message, privacy error reported as type error #64684

Open
gnzlbg opened this issue Sep 22, 2019 · 4 comments
Open

Misleading error message, privacy error reported as type error #64684

gnzlbg opened this issue Sep 22, 2019 · 4 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-visibility Area: Visibility / privacy C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@gnzlbg
Copy link
Contributor

gnzlbg commented Sep 22, 2019

mod foo {
    pub struct Foo {
        private: i32,
    }
}

use foo::Foo;

fn main() {
    let mut foo = Foo { private: 0_usize };
}

(Playground)

Errors:

   Compiling playground v0.0.1 (/playground)
error[E0308]: mismatched types
  --> src/main.rs:11:34
   |
11 |     let mut foo = Foo { private: 0_usize } ;
   |                                  ^^^^^^^ expected i32, found usize

error: aborting due to previous error

For more information about this error, try `rustc --explain E0308`.
error: Could not compile `playground`.

To learn more, run the command again with --verbose.

The error message here is incorrect. Whether the types match or not is irrelevant, because the field is private. The error should say something like this instead (playground):

 error[E0451]: field `private` of struct `foo::Foo` is private
  --> src/main.rs:10:25
   |
10 |     let mut foo = Foo { private: 0_i32 };
   |                         ^^^^^^^^^^^^^^ field `private` is private

error: aborting due to previous error
@jonas-schievink jonas-schievink added A-diagnostics Area: Messages for errors, warnings, and lints A-visibility Area: Visibility / privacy C-bug Category: This is a bug. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Sep 22, 2019
@TheSamsa
Copy link
Contributor

TheSamsa commented Sep 24, 2019

I would like to tackle this as a first timer, if that is okay and not too overly complicated for a first time issue ;)
A little pointer where to begin my trip would be awesome, thanks in advance!

@gnzlbg
Copy link
Contributor Author

gnzlbg commented Sep 24, 2019

cc @estebank

@witling
Copy link

witling commented Apr 29, 2021

I would like to tackle this as a first timer, if that is okay and not too overly complicated for a first time issue ;)
A little pointer where to begin my trip would be awesome, thanks in advance!

I don't believe that this is a good first time issue. Type checking is done before executing privacy checks. (see here)
Changing the order seems to have a negative performance impact in a lot of cases as type errors seem to be way more common. At least that is what my 20 minute code skim came up to.

@TheSamsa
Copy link
Contributor

I would like to tackle this as a first timer, if that is okay and not too overly complicated for a first time issue ;)
A little pointer where to begin my trip would be awesome, thanks in advance!

I don't believe that this is a good first time issue. Type checking is done before executing privacy checks. (see here)
Changing the order seems to have a negative performance impact in a lot of cases as type errors seem to be way more common. At least that is what my 20 minute code skim came up to.

Hi thank you for your insights!
I won't do it then, since my time is in short supply right now. It is better for someone else to step in.

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 A-visibility Area: Visibility / privacy C-bug Category: This is a bug. 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

4 participants