-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
resolve: Scale back hard-coded extern prelude additions on 2015 edition #54671
Conversation
r? @nikomatsakis |
cc @rust-lang/lang |
src/librustc_resolve/lib.rs
Outdated
extern_prelude.insert(Symbol::intern("core")); | ||
extern_prelude.insert(Symbol::intern("std")); | ||
extern_prelude.insert(Symbol::intern("meta")); | ||
if session.rust_2018() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we not doing the logic in 2015 in 2018 as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- In 2018 crates outside of extern prelude are in disadvantage (they have to use
crate::my_crate
), so this would make life harder for#[no_std]
people optionally usingstd
under a feature (std-using paths work just fine in 2018 edition #![no_std] #53166 (comment)), unless something Addextern crate
items to extern prelude #54658 -like is implemented. - For 2018 we still have enough time, while for 2015 extern prelude is already stabilized on beta.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd happily do this for 2018 as well despite 1.
if it were urgent, since it's the most conservative variant.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re. 2) -- the current beta becomes stable on 2018-10-26 so we should have time to wait with merging this until the next lang meeting (2018-10-04) right?
Re. 1) it is my understanding that given crate::my_crate
, then the path segment my_crate
will always refer to an item defined or use
d in the root of the current crate. Is that right?
It would be good if someone (not me) could write down all the rules for the module system in Rust 2015 and Rust 2018 somewhere so that it becomes a bit more easy to judge various changes; mainly it would be good since there have been so many small changes that it is hard reason about things.
As for people conditionally using std
wouldn't they just write as @Nemo157 wrote in #54658?:
#![cfg_attr(not(feature = "std"), no_std)]
use core::mem;
#[cfg(feature = "std")]
use std::boxed::Box;
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re. 2)
Sure.
Re. 1) it is my understanding that given crate::my_crate, then the path segment my_crate will always refer to an item defined or used in the root of the current crate. Is that right?
Yes.
As for people conditionally using std wouldn't they just write as @Nemo157 wrote in #54658?:
Yes, conditional #[no_std]
would work if behavior on both edition is reset to what this PR does.
But perhaps it's impractical for some reasons? Need to ask people actually writing libraries.
As I understand, the motivation described in #53166 (comment) came from a lang-team meeting, so perhaps you remember something from that?
(As I said, I'd personally be totally okay with applying this PR to both edition.)
(P.S. I have to leave now and will be available only in couple of days.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
so perhaps you remember something from that?
Sorry, afraid not; but we'll know in a few days :)
src/librustc_resolve/lib.rs
Outdated
if !attr::contains_name(&krate.attrs, "no_std") { | ||
extern_prelude.insert(Symbol::intern("std")); | ||
extern_prelude.insert(Symbol::intern("core")); | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems like a weird way to write it?
extern_prelude.insert(Symbol::intern("core"));
if !attr::contains_name(&krate.attrs, "no_std") {
extern_prelude.insert(Symbol::intern("std"));
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh. Well, yes.
I've just reverted to the old version of code an it had that.
Will fix.
☔ The latest upstream changes (presumably #54650) made this pull request unmergeable. Please resolve the merge conflicts. |
@petrochenkov what is this a relationship of this PR to #54658 ? |
I don't really want to encourage people to start using |
@scottmcm |
This PR removes some names from prelude, #54658 gives a way to re-add them explicitly. Generally, it could make sense to make this change after #54658 is done, but for 2015 edition
|
So I feel that we should do #54658 but with the change we agreed on in #54658 (comment), so the full behavior (end state) should I think be:
We only provide Furthermore, due to usage of ...However, me and @nikomatsakis are not sure why we'd use the extern prelude set at all on 2015. |
This is an interesting question - whether the stabilization of I think it would be better to enable extern prelude on 2015 edition.
|
Minor point regarding |
Hmm, perhaps I am confused. My impression was that we were enforcing a lack of ambiguity in order to retain forwards compatibility with universal paths -- so e.g. if there is a module Some testing :) |
In that case, I guess we don't really need to alter the behavior between Rust 2018 and Rust 2015, right? We may wish to just exclude In which case it would be something like:
It seems like it's worth excluding |
Everything looks correct in #54671 (comment). |
The scheme in #54671 (comment) is what I'd want to see implemented as well. |
OK, I'm inclined to say that @petrochenkov if you update the PR to that scheme, I would r+. I think this reflects the rough consensus we arrived at in the @rust-lang/lang meeting (in particular, that |
Argh, looks like recently merged #54650 broke everything. |
@petrochenkov: though frustrating that change is for the better, isn’t it? |
80cf164
to
894a8d5
Compare
@nikomatsakis |
@bors r+ |
📌 Commit 894a8d5 has been approved by |
resolve: Scale back hard-coded extern prelude additions on 2015 edition #54404 stabilized `feature(extern_prelude)` on 2015 edition, including the hard-coded parts not passed with `--extern`. First of all, I'd want to confirm that this is intended stabilization, rather than a part of the "extended beta" scheme that's going to be reverted before releasing stable. (EDIT: to clarify - this is a question, I'm \*asking\* for confirmation, rather than give it.) Second, on 2015 edition extern prelude is not so fundamentally tied to imports and is a mere convenience, so this PR scales them back to the uncontroversial subset. The "uncontroversial subset" means that if libcore is injected it brings `core` into prelude, if libstd is injected it brings `std` and `core` into prelude. On 2015 edition this can be implemented through the library prelude (rather than hard-coding in the compiler) right now, I'll do it in a follow-up PR. UPDATE: The change is done for both 2015 and 2018 editions now as discussed below. Closes #53166
☀️ Test successful - status-appveyor, status-travis |
Discussed at compiler team meeting. beta-accepted. |
[beta] Rollup backports Merged and approved: * #54300: Updated RELEASES.md for 1.30.0 * #54939: rustdoc: don't prefer dynamic linking in doc tests * #54671: resolve: Scale back hard-coded extern prelude additions on 2015 edition * #55102: resolve: Do not skip extern prelude during speculative resolution r? @ghost
I think this might have broken futures-core-preview when the std feature is enabled (which it is by default).
I bisected the problem to between bef62cc and 1dceadd. futures-core is |
@tikue Yup, that's expected fallout. I'll issue a new release ASAP. |
Cool, thanks @cramertj ! |
hmm, I'm trying to do some embedded development on Cortex-M0 and well - I'm getting |
@vhnatyk |
Seems like I still have to use Xargo (because of |
#54404 stabilized
feature(extern_prelude)
on 2015 edition, including the hard-coded parts not passed with--extern
.First of all, I'd want to confirm that this is intended stabilization, rather than a part of the "extended beta" scheme that's going to be reverted before releasing stable.
(EDIT: to clarify - this is a question, I'm *asking* for confirmation, rather than give it.)
Second, on 2015 edition extern prelude is not so fundamentally tied to imports and is a mere convenience, so this PR scales them back to the uncontroversial subset.
The "uncontroversial subset" means that if libcore is injected it brings
core
into prelude, if libstd is injected it bringsstd
andcore
into prelude.On 2015 edition this can be implemented through the library prelude (rather than hard-coding in the compiler) right now, I'll do it in a follow-up PR.
UPDATE: The change is done for both 2015 and 2018 editions now as discussed below.
Closes #53166