Skip to content
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: Fix variant namespacing #30882

Merged
merged 1 commit into from
Jan 22, 2016
Merged

Conversation

petrochenkov
Copy link
Contributor

Tuple and unit variants from other crates weren't put into type namespace.
Now variant namespacing is aligned with struct namespacing and is not affected by the variant's crate of origin (struct -> type, tuple/unit -> type/value).
Additionally, struct variants from other crates are put into value namespace (struct variants from local crate were already in it). This is not a necessity, but a future proofing measure.

This fix can result in some new shadowing errors in cross-crate scenarios, crater reports three regressions.
[breaking-change]

@rust-highfive
Copy link
Collaborator

r? @Aatch

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

@jonas-schievink
Copy link
Contributor

cc me (this might fix a bug I've encountered)

@alexcrichton
Copy link
Member

r? @nrc

@rust-highfive rust-highfive assigned nrc and unassigned Aatch Jan 14, 2016
@nrc
Copy link
Member

nrc commented Jan 14, 2016

I wonder if it is worth leaving struct variants in the value namespace? I don't suppose we'll ever need it, but it is future-proofing (e.g., if we someday get named arguments for functions, then we could make struct variants generate functions like other variants).

@nrc nrc added the S-waiting-on-crater Status: Waiting on a crater run to be completed. label Jan 15, 2016
@nrc
Copy link
Member

nrc commented Jan 15, 2016

Should probably decide on the behaviour before we give it a crater run, but it will need one before landing

@petrochenkov
Copy link
Contributor Author

Adding struct variants into the value namespace (including cross-crate) will give us the "maximum breakage mode", best suited for evaluation with crater. I'll add a second commit doing this.

@petrochenkov
Copy link
Contributor Author

Regarding keeping struct variants in the value namespace in the long term, I'm mildly against it.
Correspondence between behavior of {}-structs and {}-variants feels important (especially if variants become types) and we can't put {}-structs into value namespace now.

The pattern

struct S { fields: Fields }
fn S(args: Args) -> S { ... } // Constructor

is not especially idiomatic, but it exists and disallowing it would (presumably) break too much code.
If functions with named arguments become a thing someday, it would be strange to generate them for variants, but not for structs (but maybe it could be considered a "best-effort").

@petrochenkov
Copy link
Contributor Author

Updated with all variants in both namespaces.

bors added a commit that referenced this pull request Jan 16, 2016
Also add tests for use of empty structs in cross-crate scenarios

Some tests are commented out, they depend on fixes from  #30882
@nrc
Copy link
Member

nrc commented Jan 16, 2016

@brson could you crater this please?

@nrc
Copy link
Member

nrc commented Jan 16, 2016

@petrochenkov we often have this issue - do we want to be consistent between structs and struct variants or struct variants and other variants? I don't have an opinion in this case, but if we can get away with leaving our options open, I would like that.

@bors
Copy link
Contributor

bors commented Jan 16, 2016

☔ The latest upstream changes (presumably #30896) made this pull request unmergeable. Please resolve the merge conflicts.

@petrochenkov
Copy link
Contributor Author

Rebased.

@alexcrichton
Copy link
Member

Starting a crater run now

@alexcrichton
Copy link
Member

Looks like there are three regressions (legitimate ones I believe)

@alexcrichton alexcrichton removed the S-waiting-on-crater Status: Waiting on a crater run to be completed. label Jan 17, 2016
@petrochenkov
Copy link
Contributor Author

pnet_macros_plugin-0.1.0 - conflict of struct-struct syntax::ast::Delimited and tuple-variant syntax::ast::TokenTree::Delimited in type namespace (this crate doesn't seem to work on stable).

rotor-http-0.4.0 - conflict of struct-struct server::request::Head and unit-variant hyper::method::Method::Head in type namespace (this crate works on stable).

tiled-0.1.4 - conflict of struct-struct std::io::Error and tuple-variant xml::reader::events::XmlEvent::Error in type namespace (this crate seems to work on stable).

Zero regressions due to future-proofing of struct-variants suggested by @nrc

cc @mrmonday @tailhook @mattyhall

@mrmonday
Copy link
Contributor

Hi, feel free to ping me about the pnet_macros_plugin failure - I don't know what you need from me specifically.

@petrochenkov, you are correct, pnet_macros_plugin will only work on nightly - it's an optional dependency of libpnet, which is only pulled in when the nightly feature is enabled. It is literally a wrapper around pnet_macros but with plugin = true added to the Cargo.toml. By default, libpnet uses syntex, rather than the plugin (I keep it around because build times are 3x faster when using plugins directly rather than syntex).

@nrc
Copy link
Member

nrc commented Jan 17, 2016

cc @rust-lang/lang

I'd be happy to take this and submit PRs to the breaking crates above. What do the rest of the team think?

@nrc
Copy link
Member

nrc commented Jan 17, 2016

note: I do think of this as qualifying as a bug fix

@aturon
Copy link
Member

aturon commented Jan 17, 2016

I'm on board with future-proofing here.

@tailhook
Copy link

Thanks to @brson, the bug in rotor-http is fixed now. This case looks more like an oversight rather than a valid use case. And I'm happy that compiler catches it now.

@brson brson added the relnotes Marks issues that should be documented in the release notes of the next release. label Jan 20, 2016
@bors
Copy link
Contributor

bors commented Jan 21, 2016

☔ The latest upstream changes (presumably #31010) made this pull request unmergeable. Please resolve the merge conflicts.

@petrochenkov
Copy link
Contributor Author

Rebased.

@nrc
Copy link
Member

nrc commented Jan 21, 2016

@bors: r+

(discussed at lang team meeting today)

@bors
Copy link
Contributor

bors commented Jan 21, 2016

📌 Commit ff6b0aa has been approved by nrc

bors added a commit that referenced this pull request Jan 21, 2016
Tuple and unit variants from other crates weren't put into type namespace.
Now variant namespacing is aligned with struct namespacing and is not affected by the variant's crate of origin (struct -> type, tuple/unit -> type/value).
Additionally, struct variants from other crates are put into value namespace (struct variants from local crate were already in it). This is not a necessity, but a future proofing measure.

This fix can result in some new shadowing errors in cross-crate scenarios, crater reports [three regressions](#30882 (comment)).
[breaking-change]
@bors
Copy link
Contributor

bors commented Jan 21, 2016

⌛ Testing commit ff6b0aa with merge 54475e9...

@alexcrichton
Copy link
Member

Just ran a crate report against nightly, and I wanted to confirm, but the regression of the tiled crate was expected, here, right? This didn't intend to add support to ensure it kept compiling?

@petrochenkov
Copy link
Contributor Author

Yes, this is an expected regression.
A fix to this crate was merged in February, but the published version still isn't updated.

@alexcrichton
Copy link
Member

Ok, thanks @petrochenkov!

@mattyhall
Copy link

I've pushed the new version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
relnotes Marks issues that should be documented in the release notes of the next release.
Projects
None yet
Development

Successfully merging this pull request may close these issues.