-
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
Importing an enum variant can create a conflict with a new prelude type #127738
Comments
@petrochenkov do you know whether this is possible? (I suspect the people in the compiler meeting will not know) |
@Nilstrieb It is a part of the "time travel prevention" machinery in macro/import resolution that ensures that resolution results are independent of things like order of items in the crate, or some specific expansion order used by the compiler. In the specific example above, I don't think the error can be avoided. |
@petrochenkov I really appreciate the pointer to that writeup, thank you. I think I understand why we restrict shadowing in that case. So, if I'm understanding correctly, the ordering problem is roughly:
Is that an accurate description? And, in the case where we don't have a I understand that we can't fix the fully general case of that. Would it be possible to mitigate this issue in the common case of a |
Yes.
|
Only if
|
It may be possible to amend macro expansion algorithm with "immediate expansion" attempts. If we see a macro invocation (that includes In practice most Not sure how viable this idea is, someone needs to try prototyping. |
On a second thought, results of a probing like this are going depend on the specific expansion order, and that's what we are trying to avoid now. |
That sounds potentially feasible, and seems unlikely to create conflicts. I'd be genuinely surprised if anything in the ecosystem is overriding the name |
I've re-read the code in
In general I'd personally not want to go this way, the "macrofication" of What is the root motivation for this in the first place? |
I wasn't aware of that; thanks for that context. Is there no reasonable low-friction way to keep the macro-based If that would still be too much of a hack, we can work around it. In any case I appreciate you considering the possibilities, thank you.
The point is to make it less of a major decision. There are many names that we may want to add to the prelude, and if it's possible to do so incrementally without waiting for an edition that would make it a smaller impact. It'd also reduce the amount of burden at edition time; anything we can make not require an edition means the edition becomes less work, and we've already had long conversations about how to make the edition less work. Even with this limitation, we can still potentially add prelude types without an edition, if we do a crater run. And the fact that the conflict only occurs with the combination of a derive and an import of a macro variant means it's unlikely to arise often. I'm trying to find out if there's any reasonable step we can take to further reduce the likelihood of such problems. If not, then we can document this limitation and work around it with additional care when extending the prelude. |
We discussed this in today's @rust-lang/lang meeting for information's sake, and came to the conclusion that while we'd like to be able to make this situation more robust, we didn't have an obvious third option to suggest, and we don't want to place substantially more complexity on the compiler. So, if the compiler team feels this would add too much complexity, we'll have to continue leaving this in the realm of "be careful and check crater" for libs-api. |
The experiment in #125107 uncovered an interesting source of version breakage, which occurs if the standard library prelude attempts to introduce an additional type.
Suppose
std
adds the typeCell
to the prelude. This will break code that looks like this:Per the comment at #125107 (comment) , this generates an error of the form:
This makes it a potentially breaking change to add new types to the prelude. We could still potentially add types that create no actual breakage (e.g. because no extant Rust code declares its own conflicting type), but this nonetheless introduces a potential source of breakage that could block introducing new types until an edition boundary (and creates one more thing people have to deal with when migrating to the new edition).
It seems worth exploring whether we can, or should, attempt to fix this, such as by allowing the type to shadow in this case. Note that it does properly shadow if there's no
derive
on the enum.Nominating for lang discussion on the "should we" question: should we consider doing something to eliminate or mitigate this source of conflict? This kind of conflict applies both to the current problem with the standard library prelude, as well as any potential future features for letting other libraries have preludes.
Nominating for compiler discussion on the "can we" question: to find out how feasible it would be to deprioritize standard library prelude types and make them lower priority than local enums in this case, or to otherwise mitigate the issue that seems to specifically arise when using a
derive
macro on such types.The text was updated successfully, but these errors were encountered: