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

Delay gensym creation for "underscore items" (`use foo as _`/`const _`) until name resolution #56392

Merged
merged 3 commits into from Dec 6, 2018

Conversation

Projects
None yet
7 participants
@petrochenkov
Copy link
Contributor

petrochenkov commented Nov 30, 2018

So they cannot be cloned by macros. See #56303 for the discussion.

Mostly fix cross-crate use of underscore items by inverting the "gensyms are lost in metadata" bug as described in #56303 (comment).
Fix unused import warnings for single-segment imports (first commit) and use crate_name as _ imports (as specified in #56303 (comment)).
Prohibit accidentally implemented static _: TYPE = EXPR; (cc #55983).
Add more tests for use foo as _ imports.

@rust-highfive

This comment has been minimized.

Copy link
Collaborator

rust-highfive commented Nov 30, 2018

r? @oli-obk

(rust_highfive has picked a reviewer for you, use r? to override)

Show resolved Hide resolved src/librustc_resolve/lib.rs
Show resolved Hide resolved src/librustc_resolve/resolve_imports.rs
let Export { ident, def, vis, span } = child;
// FIXME: We shouldn't create the gensym here, it should come from metadata,
// but metadata cannot encode gensyms currently, so we create it here.
// This is only a guess, two equivalent idents may incorrectly get different gensyms here.

This comment has been minimized.

@oli-obk

oli-obk Dec 1, 2018

Contributor

Is this even a hypothetical problem for _?

This comment has been minimized.

@petrochenkov

petrochenkov Dec 1, 2018

Contributor

I'm... not entirely sure.
I haven't found an example where it would caused observable problems so far (assuming gensym creation is delayed until name resolution).

This comment has been minimized.

@petrochenkov

petrochenkov Dec 1, 2018

Contributor

#56303 (comment) has an example of gensyms being created incorrectly internally, but it's not observable from the outside.

@@ -9,6 +9,5 @@
// except according to those terms.

const _: () = (); //~ ERROR is unstable
static _: () = (); //~ ERROR is unstable

This comment has been minimized.

@oli-obk

oli-obk Dec 1, 2018

Contributor

I understand this wasn't in the RFC, but I see no reason not to support it.

This comment has been minimized.

@Centril

Centril Dec 1, 2018

Contributor

const _: T = expr; was permitted because it has a reasonable generalization to irrefutable patterns (e.g. const (A, B) = (1, 2);) but does static also have that with the same-address notion?

This comment has been minimized.

@petrochenkov

petrochenkov Dec 1, 2018

Contributor

At least the motivation in rust-lang/rfcs#2526 does not apply to statics.
Constants don't even exist in MIR (AFAIK), so they can be used for compile-time asserts, while statics end up in the resulting executable/library, or need to be optimized away.

@petrochenkov

This comment has been minimized.

Copy link
Contributor

petrochenkov commented Dec 1, 2018

Updated with comments addressed.

petrochenkov added some commits Nov 30, 2018

Delay gensym creation for "underscore items" until name resolution
Prohibit `static _`
Fis unused import warnings for `use foo as _`
Add more tests for `use foo as _`

@petrochenkov petrochenkov force-pushed the petrochenkov:regensym branch from b5f441d to eb1d2e6 Dec 2, 2018

@oli-obk

This comment has been minimized.

Copy link
Contributor

oli-obk commented Dec 5, 2018

@bors r+

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Dec 5, 2018

📌 Commit eb1d2e6 has been approved by oli-obk

@bors

This comment has been minimized.

Copy link
Contributor

bors commented Dec 6, 2018

⌛️ Testing commit eb1d2e6 with merge 4bb5d35...

bors added a commit that referenced this pull request Dec 6, 2018

Auto merge of #56392 - petrochenkov:regensym, r=oli-obk
Delay gensym creation for "underscore items" (`use foo as _`/`const _`) until name resolution

So they cannot be cloned by macros. See #56303 for the discussion.

Mostly fix cross-crate use of underscore items by inverting the "gensyms are lost in metadata" bug as described in #56303 (comment).
Fix unused import warnings for single-segment imports (first commit) and `use crate_name as _` imports (as specified in #56303 (comment)).
Prohibit accidentally implemented `static _: TYPE = EXPR;` (cc #55983).
Add more tests for `use foo as _` imports.
@bors

This comment has been minimized.

Copy link
Contributor

bors commented Dec 6, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: oli-obk
Pushing 4bb5d35 to master...

@bors bors merged commit eb1d2e6 into rust-lang:master Dec 6, 2018

2 checks passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
homu Test successful
Details

@ehuss ehuss referenced this pull request Dec 8, 2018

Merged

Bump to 0.34.0 #6399

@pietroalbini

This comment has been minimized.

Copy link
Member

pietroalbini commented Jan 3, 2019

cc @rust-lang/compiler, this is needed to backport #57160.

@petrochenkov

This comment has been minimized.

Copy link
Contributor

petrochenkov commented Jan 3, 2019

cc @rust-lang/compiler, this is needed to backport #57160.

Clarification: not whole PR, but only the first commit (c658d73).
(It's also a prerequisite for #56759.)

@petrochenkov

This comment has been minimized.

Copy link
Contributor

petrochenkov commented Jan 10, 2019

c658d73 is included into #57483

@nikomatsakis

This comment has been minimized.

Copy link
Contributor

nikomatsakis commented Jan 10, 2019

I'm removing the beta-nominated tag here because this is rolled into #57483

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment