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

Add deprecation lint for duplicated macro_exports #50143

Merged
merged 1 commit into from
Jun 9, 2018

Conversation

petrochenkov
Copy link
Contributor

@rust-highfive
Copy link
Collaborator

r? @nikomatsakis

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

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 21, 2018
@petrochenkov
Copy link
Contributor Author

cc @rust-lang/lang

Needs check-only crater run before proceeding.
ping @rust-lang/infra

@petrochenkov petrochenkov added the S-waiting-on-crater Status: Waiting on a crater run to be completed. label Apr 21, 2018
@kennytm
Copy link
Member

kennytm commented Apr 21, 2018

@bors try

@bors
Copy link
Contributor

bors commented Apr 21, 2018

⌛ Trying commit eaebec0 with merge a314612...

bors added a commit that referenced this pull request Apr 21, 2018
@bors
Copy link
Contributor

bors commented Apr 21, 2018

☀️ Test successful - status-travis
State: approved= try=True

@Mark-Simulacrum
Copy link
Member

Crater run commenced, check-only, ETA ~3 days.

@pietroalbini pietroalbini removed the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Apr 21, 2018
Copy link
Contributor

@nikomatsakis nikomatsakis left a comment

Choose a reason for hiding this comment

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

r=me from the technical perspective. I'm not 100% sure about the policy decision, but I guess let's see what the crater run has to say.

@@ -887,14 +887,24 @@ impl<'a, 'b:'a> ImportResolver<'a, 'b> {
// Since import resolution is finished, globs will not define any more names.
*module.globs.borrow_mut() = Vec::new();

let report_already_exported = |this: &mut Self, ident, span, prev_span| {
let msg = format!("a macro named `{}` has already been exported", ident);
this.session.struct_span_err(span, &msg)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm ok with a hard error, but it seems like there is a defined semantics, right? (Shadowing) We could always issue warnings, in other words.

@Mark-Simulacrum
Copy link
Member

@alexcrichton
Copy link
Member

Legitimate regressions

The lsio and fixed-hash regressions seemed to transitively affect a lot of other dependencies.

Sounds like this may want to start out as a warning?

@durka
Copy link
Contributor

durka commented Apr 25, 2018

What would be the motivation for a break here? The whole #[macro_export] system is going to be deprecated anyway, right?

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Apr 26, 2018
@petrochenkov
Copy link
Contributor Author

petrochenkov commented Apr 26, 2018

@nikomatsakis

it seems like there is a defined semantics, right? (Shadowing)

The exact problem is that there's no defined semantics.
This "shadowing" works over the whole crate, not a single module, and macros are "shadowed" in whatever unspecified order in which the resolution/expansion algorithm processes the crate (#35896 (comment)).

@durka
While the whole Macro 1.0 system is a large widely used part of the language that's going to be supported forever even if deprecated, the macro_export duplication is a corner case that's more on the "kill it with fire" territory due to undefined semantics.

Since there's breakage, I'd prefer to turn this into a preferably deny-by-default lint so dependent crates are not affected and send PRs to crates with root regressions.

@durka
Copy link
Contributor

durka commented Apr 26, 2018

I realize that it got accidentally "defined" to work the way it does, but since it does work and it's not unsound or anything, it seems unfortunate to do the breaking change.

@nikomatsakis
Copy link
Contributor

@petrochenkov I would have expected the order to be DFS, since that is significant to other parts of macro expansion. I'm surprised that is complex to achieve, but I'm probably not thinking especially clearly about it. Do you have an example where a problem might arise, or just a bad feeling? I see you wrote this:

The order is generally determined by depth-first search, but I suspect things can become more complex with macro expansion.

Can you point at the relevant code?

(This walk is occurring at the end of expansion.)

@nikomatsakis
Copy link
Contributor

(At minimum, some kind of active deprecation definitely makes sense -- and perhaps a hard error in Edition 2018.)

@petrochenkov
Copy link
Contributor Author

@nikomatsakis

Do you have an example where a problem might arise, or just a bad feeling?

Here, for example, foo (1) will "shadow" foo (2) for other crates due to expansion algorithm order.
At the same time, foo (2) will shadow foo (1) locally because it's defined later in the module.

macro_rules! generate_foo {
    () => {
        #[macro_export]
        macro_rules! foo { (1) => {} }
    }
}

generate_foo!();

#[macro_export]
macro_rules! foo { (2) => {} }

foo!(2); // Local use, OK

@petrochenkov
Copy link
Contributor Author

I've replaced the error with a deprecation lint.

@petrochenkov petrochenkov added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 30, 2018
@nikomatsakis nikomatsakis added A-macros-2.0 Area: Declarative macros 2.0 (#39412) I-nominated T-lang Relevant to the language team, which will review and decide on the PR/issue. and removed A-macros-2.0 Area: Declarative macros 2.0 (#39412) labels Apr 30, 2018
@bors
Copy link
Contributor

bors commented May 19, 2018

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

@rfcbot
Copy link

rfcbot commented May 21, 2018

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot rfcbot added final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. and removed proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. labels May 21, 2018
@petrochenkov
Copy link
Contributor Author

Rebased.

@rfcbot
Copy link

rfcbot commented May 31, 2018

The final comment period, with a disposition to merge, as per the review above, is now complete.

@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this PR / Issue. and removed final-comment-period In the final comment period and will be merged soon unless new substantive objections are raised. labels May 31, 2018
@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Jun 8, 2018

📌 Commit 11c283c has been approved by nikomatsakis

@bors
Copy link
Contributor

bors commented Jun 8, 2018

🌲 The tree is currently closed for pull requests below priority 1, this pull request will be tested once the tree is reopened

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-team Status: Awaiting decision from the relevant subteam (see the T-<team> label). labels Jun 8, 2018
Mark-Simulacrum added a commit to Mark-Simulacrum/rust that referenced this pull request Jun 8, 2018
@bors
Copy link
Contributor

bors commented Jun 8, 2018

🔒 Merge conflict

@bors bors added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Jun 8, 2018
bors added a commit that referenced this pull request Jun 8, 2018
Rollup of 13 pull requests

Successful merges:

 - #50143 (Add deprecation lint for duplicated `macro_export`s)
 - #51099 (Fix Issue 38777)
 - #51276 (Dedup auto traits in trait objects.)
 - #51298 (Stabilize unit tests with non-`()` return type)
 - #51360 (Suggest parentheses when a struct literal needs them)
 - #51391 (Use spans pointing at the inside of a rustdoc attribute)
 - #51394 (Use scope tree depths to speed up `nearest_common_ancestor`.)
 - #51396 (Make the size of Option<NonZero*> a documented guarantee.)
 - #51401 (Warn on `repr` without hints)
 - #51412 (Avoid useless Vec clones in pending_obligations().)
 - #51427 (compiletest: autoremove duplicate .nll.* files (#51204))
 - #51436 (Do not require stage 2 compiler for rustdoc)
 - #51437 (rustbuild: generate full list of dependencies for metadata)

Failed merges:
@bors bors merged commit 11c283c into rust-lang:master Jun 9, 2018
@petrochenkov petrochenkov deleted the mexuniq branch June 5, 2019 16:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disposition-merge This issue / PR is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this PR / Issue. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.