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

libsyntax: Restrict where non-inline modules can appear (fixes #29765) #31534

Merged
merged 2 commits into from
Feb 16, 2016

Conversation

jseyfried
Copy link
Contributor

This PR disallows non-inline modules without path annotations that are either in a block or in an inline module whose containing file is not a directory owner (fixes #29765).
This is a [breaking-change].
r? @nikomatsakis

@jseyfried jseyfried force-pushed the restrict_noninline_mod branch 12 times, most recently from 6ce1e4d to 69f3a1b Compare February 11, 2016 00:58
@jseyfried
Copy link
Contributor Author

Disallowing non-inline modules in blocks broke librustc_back -- there was a macro defined and invoked inside a function that expanded to code that declared non-inline modules. I fixed it by moving the macro and its invocation out of the function.

This doesn't look like it is a common pattern, but it may be a good idea to do a crater run to be sure. We could continue allowing non-inline modules in blocks (unless the containing file is not a directory owner, which would still be enforced by my first commit) or make it a warning/lint. I don't have a strong opinion on this issue, but it looks like the consensus in #29765 was to disallow non-inline modules in blocks.

cc @aturon @matklad

@nikomatsakis
Copy link
Contributor

Should we do a crater run do you think?

@nikomatsakis
Copy link
Contributor

Or -- alternatively -- just start out with added a lint.

@nikomatsakis
Copy link
Contributor

(Seems like it's prob not needed here though.)

@nikomatsakis
Copy link
Contributor

OK well I kicked off a crater run just for kicks. This patch looks good though. r=me once the crater run is done.

@nikomatsakis nikomatsakis added relnotes Marks issues that should be documented in the release notes of the next release. T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Feb 11, 2016
@nikomatsakis
Copy link
Contributor

cc @brson -- this is a bug fix but a breaking change, I'm not sure what tags we were supposed to use but I added some :)

@nikomatsakis
Copy link
Contributor

I got one regression from a crater run: https://gist.github.com/nikomatsakis/f30f5a095b4576411201

(cargo)

@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Feb 12, 2016

📌 Commit 69f3a1b has been approved by nikomatsakis

@alexcrichton
Copy link
Member

:(

@jseyfried
Copy link
Contributor Author

I wrote a PR for cargo to fix the regression.

@bors
Copy link
Contributor

bors commented Feb 13, 2016

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

@jseyfried
Copy link
Contributor Author

@nikomatsakis rebased

@jseyfried
Copy link
Contributor Author

@nikomatsakis Do you still want to merge this?

@nikomatsakis
Copy link
Contributor

@jseyfried sorry, didn't see the problem, yes I would like to merge

@nikomatsakis
Copy link
Contributor

@alexcrichton

:(

I can't tell how to interpret this smiley...

@alexcrichton
Copy link
Member

Ah yes, I can clarify! I saw that only Cargo was mentioned, and that felt like Cargo got some sort of prize or something, so I felt compelled to comment. After seeing the prize it won, however, I deleted the half-written essay of acceptance and felt compelled to continue writing something, so I settled for an emoticon, and ":(" seemed appropriate at the time.

In other words, I wouldn't try to interpret :)

@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Feb 16, 2016

📌 Commit d21e908 has been approved by nikomatsakis

@bors
Copy link
Contributor

bors commented Feb 16, 2016

⌛ Testing commit d21e908 with merge 45652d9...

@alexcrichton
Copy link
Member

@bors: retry force

@bors
Copy link
Contributor

bors commented Feb 16, 2016

⌛ Testing commit d21e908 with merge 9658645...

bors added a commit that referenced this pull request Feb 16, 2016
This PR disallows non-inline modules without path annotations that are either in a block or in an inline module whose containing file is not a directory owner (fixes #29765).
This is a [breaking-change].
r? @nikomatsakis
@bors bors merged commit d21e908 into rust-lang:master Feb 16, 2016
@jseyfried jseyfried deleted the restrict_noninline_mod branch November 4, 2016 09:42
bors added a commit that referenced this pull request Nov 22, 2016
parser: simplify directory ownership semantics

This PR simplifies the semantics of "directory ownership". After this PR,
 - a non-inline module without a `#[path]` attribute (e.g. `mod foo;`) is allowed iff its parent module/block (whichever is nearer) is a directory owner,
 - an non-inline module is a directory owner iff its corresponding file is named `mod.rs` (c.f. [comment](#32401 (comment))),
 - a block is never a directory owner (c.f. #31534), and
 - an inline module is a directory owner iff either
   - its parent module/block is a directory owner (again, c.f. #31534), or
   - it has a `#[path]` attribute (c.f. #36789).

These semantics differ from today's in three orthogonal ways:
 - `#[path = "foo.rs"] mod foo;` is no longer a directory owner. This is a [breaking-change].
 - #36789 is generalized to apply to modules that are not directory owners in addition to blocks.
 - A macro-expanded non-inline module is only allowed where an ordinary non-inline module would be allowed. Today, we incorrectly allow macro-expanded non-inline modules in modules that are not directory owners (but not in blocks). This is a [breaking-change].

Fixes #32401.
r? @nikomatsakis
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. T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Non-inline module is allowed inside other items
4 participants