-
Notifications
You must be signed in to change notification settings - Fork 13k
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
trying to import a use
statement should not talk of privacy
#42909
Comments
I somewhat disagree. I think we shouldn't say that |
From the point of view of another crate what imports you have should not really be a visible detail. The problem is that the way imports are generally taught; |
However, if you're accidently importing a private name (say, a Changing this to not mentioning the privacy at all would make me wonder whether I mistyped some part of the path instead of wondering about the privacy. |
Yes, I am talking about importing a The point is to distinguish between the case where you typed the correct path but it is private, and you typed the wrong path but does exist as a private use statement. Currently the two give the same error, even though they are generally fixed in very different ways. |
I find this confusing as well. (JFYI I am planning on suggesting this issue for the upcoming "Boston rust hackathon" meetup.) |
Proposed output:
This would be shown only when a span is available, which is the only time when you can actually do something about it. When there's no span available, produce the output for nonexistent modules:
|
or we could emit a suggestion to |
@oli-obk that would only apply to use statements, but I agree. |
I think making a |
I've ran into a variant of this error by getting module name slightly wrong (playground): pub mod definer {
pub struct PubStruct;
}
mod user {
use crate::definer::PubStruct;
}
mod fail {
use crate::user::PubStruct;
// error[E0603]: struct `PubStruct` is private
} The problem was I've used I find this message misleading, because:
|
Closed #57619 as a dupe of this |
The error message is a bit better now. It still talks about privacy.
|
The current output follows #42909 (comment) and talks about the privacy intentionally. |
For some context, I've found this issue after looking for one when seeing the current error mentioned in https://internals.rust-lang.org/t/cautiously-consolidating-the-standard-library/14169. IMHO the current error message is still confusing in many cases. I guess it makes sense to talk about privacy if you try to import sth. that is not accessible within the same crate, and maybe also another crate in the same workspace. But for entirely out-of-tree stuff, I would never expect private |
I think the two improvements left to do are providing a structured suggestion for the new import, or at least changing the last span label to mention the ADT's full path, and maybe eliding the chain for external crates and just provide a "not found" and suggestion. That might be confusing to people that expect the reexport to be available, but when that happens in a separate crate the likelihood of the user dealing with both is low. Maybe we can get around that with slight rewording, maybe just a note saying "the path is available as a reexport but it is private" or something. |
I think swapping order of the error message and the note would improve it — instead of an error about privacy with a note about wrong path, make it an error about wrong path, with a note about privacy.
|
When encoutering a privacy error on an item through a re-export that is accessible in an alternative path, provide a structured suggestion with that path. ``` error[E0603]: module import `mem` is private --> $DIR/private-std-reexport-suggest-public.rs:4:14 | LL | use foo::mem; | ^^^ private module import | note: the module import `mem` is defined here... --> $DIR/private-std-reexport-suggest-public.rs:8:9 | LL | use std::mem; | ^^^^^^^^ note: ...and refers to the module `mem` which is defined here --> $SRC_DIR/std/src/lib.rs:LL:COL | = note: you could import this help: import `mem` through the re-export | LL | use std::mem; | ~~~~~~~~ ``` Fix rust-lang#42909.
On #118066:
|
…r=b-naber Structured `use` suggestion on privacy error When encoutering a privacy error on an item through a re-export that is accessible in an alternative path, provide a structured suggestion with that path. ``` error[E0603]: module import `mem` is private --> $DIR/private-std-reexport-suggest-public.rs:4:14 | LL | use foo::mem; | ^^^ private module import | note: the module import `mem` is defined here... --> $DIR/private-std-reexport-suggest-public.rs:8:9 | LL | use std::mem; | ^^^^^^^^ note: ...and refers to the module `mem` which is defined here --> $SRC_DIR/std/src/lib.rs:LL:COL | = note: you could import this help: import `mem` through the re-export | LL | use std::mem; | ~~~~~~~~ ``` Fix rust-lang#42909.
gives the error:
However, really, we don't consider
use std::mem
to be introducing a module, so it's confusing when we say that it's private. This gives off the impression that we typed the correct path, but the library author neglected to make it public.We should instead give an error that the module/type/etc does not exist, but perhaps note that there is a
use
statement that could be madepub use
if the error is from the same crate.The text was updated successfully, but these errors were encountered: