Skip to content

resolve: Fix variant namespacing#30882

Merged
bors merged 1 commit into
rust-lang:masterfrom
petrochenkov:varnamesp
Jan 22, 2016
Merged

resolve: Fix variant namespacing#30882
bors merged 1 commit into
rust-lang:masterfrom
petrochenkov:varnamesp

Conversation

@petrochenkov

Copy link
Copy Markdown
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
Copy Markdown
Contributor

r? @Aatch

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

@jonas-schievink

Copy link
Copy Markdown
Contributor

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

@alexcrichton

Copy link
Copy Markdown
Member

r? @nrc

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

nrc commented Jan 14, 2016

Copy link
Copy Markdown
Member

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

nrc commented Jan 15, 2016

Copy link
Copy Markdown
Member

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

@petrochenkov

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

nrc commented Jan 16, 2016

Copy link
Copy Markdown
Member

@brson could you crater this please?

@nrc

nrc commented Jan 16, 2016

Copy link
Copy Markdown
Member

@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

bors commented Jan 16, 2016

Copy link
Copy Markdown
Collaborator

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

@petrochenkov

Copy link
Copy Markdown
Contributor Author

Rebased.

@alexcrichton

Copy link
Copy Markdown
Member

Starting a crater run now

@alexcrichton

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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

nrc commented Jan 17, 2016

Copy link
Copy Markdown
Member

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

nrc commented Jan 17, 2016

Copy link
Copy Markdown
Member

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

@aturon

aturon commented Jan 17, 2016

Copy link
Copy Markdown
Contributor

I'm on board with future-proofing here.

@tailhook

Copy link
Copy Markdown

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

bors commented Jan 21, 2016

Copy link
Copy Markdown
Collaborator

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

@petrochenkov

Copy link
Copy Markdown
Contributor Author

Rebased.

@nrc

nrc commented Jan 21, 2016

Copy link
Copy Markdown
Member

@bors: r+

(discussed at lang team meeting today)

@bors

bors commented Jan 21, 2016

Copy link
Copy Markdown
Collaborator

📌 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

bors commented Jan 21, 2016

Copy link
Copy Markdown
Collaborator

⌛ Testing commit ff6b0aa with merge 54475e9...

@alexcrichton

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member

Ok, thanks @petrochenkov!

@mattyhall

Copy link
Copy Markdown
Contributor

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.