Skip to content

Error on bad pub(path) depends on module ordering #40066

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

Open
withoutboats opened this issue Feb 23, 2017 · 7 comments
Open

Error on bad pub(path) depends on module ordering #40066

withoutboats opened this issue Feb 23, 2017 · 7 comments
Labels
A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Name/path resolution done by `rustc_resolve` specifically C-bug Category: This is a bug. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-diagnostics Working group: Diagnostics

Comments

@withoutboats
Copy link
Contributor

withoutboats commented Feb 23, 2017

Which error message you get with a non-ancestral pub(path) visibility restriction depends on the ordering of module declarations.

These two struct declarations produce different errors;

mod foo {
    pub(in ::bar) struct Foo;
}

mod bar {
    pub(in ::foo) struct Bar;
}

The second produces the correct error:

error: visibilities can only be restricted to ancestor modules

The first produces this, incorrect error:

error[E0578]: cannot find module `bar` in the crate root

Presumably the pub(path) code is operating on the assumption the path, if real, has already been walked (because any correct path would have been walked), but this is not the case.

@petrochenkov petrochenkov added A-diagnostics Area: Messages for errors, warnings, and lints A-resolve Area: Name/path resolution done by `rustc_resolve` specifically labels Feb 23, 2017
@steveklabnik steveklabnik added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Mar 9, 2017
@est31
Copy link
Member

est31 commented Mar 21, 2017

I've stumbled across this problem earlier today, see my dupe report above. It was my first attempt at using that feature, and I wasn't aware that only ancestor modules are allowed, and this issue added to the confusion.

@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 26, 2017
@withoutboats
Copy link
Contributor Author

This bug still exists. The syntax of path visibilities has changed to require in, but updating the code sample to pub(in ::foo) and pub(in ::bar), the error message is still order dependent.

@withoutboats withoutboats reopened this Sep 19, 2017
@estebank
Copy link
Contributor

@withoutboats: thanks for reviewing, I'll write mentoring instructions then.

@estebank
Copy link
Contributor

Mentoring instructions:

Resolver::resolve_visibility() is the method responsible for raising visibility issues,
which calls Resolver::smart_resolve_path(), the method that raises E0578.

smart_resolve_path_fragment should be changed so it takes into consideration wether source is a PathSource::Visibility in report_errors so that instead of adding a UseError to use_injection (which are picked up by report_with_use_injections to suggest imports), we keep all the information needed to look for the (presumably) not yet seen mod and look for it after all checks have been performed (you probably would want to do it in report_errors). If you can find the mod, then raise an incorrect visibility restriction error, otherwise raise E0578 (You can keep around the original E0578 diagnostic and .cancel() it if you can find the mod afterwards, or emit it otherwise).

@estebank estebank added E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. WG-diagnostics Working group: Diagnostics labels Sep 21, 2017
@jethrogb
Copy link
Contributor

Bug still exists in 2018 edition but you have to write in crate::...

@estebank
Copy link
Contributor

Triage: no change.

@petrochenkov
Copy link
Contributor

#109657 is a duplicate of this issue and contains some explanation for the suboptimal diagnostics here.

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-resolve Area: Name/path resolution done by `rustc_resolve` specifically C-bug Category: This is a bug. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. WG-diagnostics Working group: Diagnostics
Projects
None yet
Development

No branches or pull requests

7 participants