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

parser: simplify directory ownership semantics #37602

Merged
merged 4 commits into from
Nov 22, 2016

Conversation

jseyfried
Copy link
Contributor

@jseyfried jseyfried commented Nov 5, 2016

This PR simplifies the semantics of "directory ownership". After this PR,

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].
  • Allow more non-inline modules in blocks #36789 is generalized to apply to modules that are not directory owners in addition to blocks.
  • A macro-expanded out of line module is only allowed where an ordinary out of line module would be allowed. Today, we incorrectly allow macro-expanded out of line modules in modules that are not directory owners (but not in blocks). This is a [breaking-change].

Fixes #32401.
r? @nikomatsakis

@jseyfried
Copy link
Contributor Author

cc @rust-lang/lang @matklad

@nikomatsakis
Copy link
Contributor

Started a crater run.

@nikomatsakis
Copy link
Contributor

nikomatsakis commented Nov 8, 2016

Results: https://gist.github.com/nikomatsakis/ad150e91da19d7a86d8501a11f2b0a0c

  • 6760 crates tested: 4753 working / 1638 broken / 25 regressed / 2 fixed / 342 unknown.

Root regressions to be investigated:

@nikomatsakis
Copy link
Contributor

@jseyfried so at least a few of those are real regr. We have to decide now: to warning period or what.

cc @rust-lang/lang -- this PR makes some changes to rationalize various aspects of when a module "has a directory" and not (i.e., when you can do mod foo;). It breaks some libraries. What to do?

@brson
Copy link
Contributor

brson commented Nov 8, 2016

@nikomatsakis the openssl errors are rust-lang/cargo#3268

@aturon
Copy link
Member

aturon commented Nov 8, 2016

@nikomatsakis This looks like a good case for applying the general guidelines. In general I'm 👍 going forward with these changes. How hard is a warning period to do in this case? If it's relatively easy, we should do it.

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

brson commented Nov 8, 2016

I'd encourage you to make any breakage here a transitionary warning. We must continue to do our utmost to reduce breakage pain for users. Small breakage adds up.

@jseyfried
Copy link
Contributor Author

It looks like all the breakage is due to #[path = "foo.rs"] mod foo; no longer being a directory owner (i.e. #32401 (comment)). A warning cycle for this is straightforward to implement.

@nikomatsakis
Copy link
Contributor

Definitely we should do a warning period.

@jseyfried jseyfried force-pushed the directory_ownership branch 3 times, most recently from 19030ba to 0b060ac Compare November 14, 2016 10:52
@jseyfried
Copy link
Contributor Author

jseyfried commented Nov 14, 2016

I started a warning cycle in the above commit. Since it's not easy to lint from the parser, it is just an ordinary warning with a note about future compatibility.

if paths.path_exists {
if legacy_warn {
err.note(
"this was erroneously allowed and will become a hard error in a future release"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm. I think we could do an actual lint here -- can't we leave a little note on the AST or something and then issue the lint later, in the lint pass?

At minimum, though, can you open a "forward compat" issue with the appropriate labels and structure and mention it in this message? Roughly follow the protocol described in RFC 1589

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I'll make it a real lint.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@nikomatsakis
Copy link
Contributor

ping @jseyfried -- still planning to make it a real lint?

@jseyfried
Copy link
Contributor Author

@nikomatsakis just fininshed (got sidetracked by some higher-priority stuff)

@petrochenkov
Copy link
Contributor

The lint is temporary, but still could you rename it to follow lint naming conventions?
Names are supposed to look good in allow/deny attributes, like deny(deprecated_directory_ownership), but not deny(directory_ownership).

@jseyfried
Copy link
Contributor Author

@petrochenkov yeah, renamed to legacy_directory_ownership.

@bors
Copy link
Contributor

bors commented Nov 21, 2016

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

@nikomatsakis
Copy link
Contributor

@jseyfried r=me after rebase

@jseyfried
Copy link
Contributor Author

@bors r=nikomatsakis

@bors
Copy link
Contributor

bors commented Nov 22, 2016

📌 Commit fa8c53b has been approved by nikomatsakis

@bors
Copy link
Contributor

bors commented Nov 22, 2016

⌛ Testing commit fa8c53b with merge 1c11ea3...

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
@bors bors merged commit fa8c53b into rust-lang:master Nov 22, 2016
@briansmith
Copy link
Contributor

Sorry, I don't understand what I need to do to change in ring here. I don't want to name all the modules' files mod.rs because it's ridiculous to have dozens of files with the same name in one project. Of course some of them have submodules. What's the alternative?

@eddyb
Copy link
Member

eddyb commented Nov 29, 2016

@briansmith You can declare the module hierarchy recursively, even the entire crate's modules in lib.rs, and the nesting matches the directory structure. Some (older?) rustc crates do this, if you need examples.
I believe you can also use #[path = "foo.rs"] mod foo; to manually enforce your own hierarchy.

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.

8 participants