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

Incorrect suggestion given private function #64711

Open
ChrisJefferson opened this issue Sep 23, 2019 · 3 comments
Open

Incorrect suggestion given private function #64711

ChrisJefferson opened this issue Sep 23, 2019 · 3 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. A-visibility Area: Visibility / privacy. C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@ChrisJefferson
Copy link
Contributor

In constants.rs I have a private method: fn defaultConfig() -> bool { ... }.

If I import all members into another file using: use crate::constants::*, then call defaultConfig, I get the following error:

error[E0425]: cannot find function `defaultConfig` in this scope
  --> src/playgame.rs:28:18
   |
28 |     let config = defaultConfig();
   |                  ^^^^^^^^^^^^^ not found in this scope
help: possible candidate is found in another module, you can import it into scope
   |
4  | use crate::constants::defaultConfig;
   |

However, the suggested fix won't help. Adding use crates::constants::defaultConfig suggests adding pub to defaultConfig. Suggesting crates::constants::defaultConfig isn't useful when we already have crates::constants::*, so should go straight to the suggestion about adding pub?

@jonas-schievink jonas-schievink added A-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. 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 23, 2019
@estebank estebank added the A-diagnostics Area: Messages for errors, warnings, and lints label Sep 23, 2019
@estebank estebank added the D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. label Oct 5, 2019
@compiler-errors
Copy link
Member

compiler-errors commented Jan 7, 2023

I'm pretty sure we take visibility into account when considering use suggestions. Couldn't reproduce this anyways.

@compiler-errors
Copy link
Member

Actually, I guess we could suggest adding pub on the item, like so:

mod A {
    use crate::B::*;
    
    fn foo() {
        b();
    }
}

pub mod B {
    // Could suggest use
    fn b() {}
}

@ChrisJefferson
Copy link
Contributor Author

Just to say, I went back to the original code, and indeed behaviour has changed -- now the presence of use crates::constants::* makes no difference to the error message.

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-suggestion-diagnostics Area: Suggestions generated by the compiler applied by `cargo fix`. A-visibility Area: Visibility / privacy. C-bug Category: This is a bug. D-invalid-suggestion Diagnostics: A structured suggestion resulting in incorrect code. 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