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

Forbid $crate in macro patterns #99447

Closed
wants to merge 1 commit into from

Conversation

CAD97
Copy link
Contributor

@CAD97 CAD97 commented Jul 19, 2022

Fixes #99037. This currently implements a hard error because it was convenient to reuse the existing error for other disallowed metavars in the macro pattern, but should maybe be a forward-compat lint instead. Or maybe a clean crater run would justify just landing this directly as a hard error.

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jul 19, 2022
@rust-highfive
Copy link
Collaborator

r? @jackh726

(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 Jul 19, 2022
@rust-log-analyzer

This comment has been minimized.

@jackh726
Copy link
Member

jackh726 commented Aug 2, 2022

Not sure who the right reviewer is for this. Likely not me.

r? rust-lang/compiler

@rust-highfive rust-highfive assigned fee1-dead and unassigned jackh726 Aug 2, 2022
@fee1-dead
Copy link
Member

r? rust-lang/compiler

@rust-highfive rust-highfive assigned estebank and unassigned fee1-dead Aug 3, 2022
@estebank
Copy link
Contributor

estebank commented Aug 3, 2022

The changes look reasonable to me, but 1) we should run crater and 2) @petrochenkov should take a look (it is a 3 line diff).

@bors try
@craterbot check

@craterbot
Copy link
Collaborator

🚨 Error: missing start toolchain

🆘 If you have any trouble with Crater please ping @rust-lang/infra!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@bors
Copy link
Contributor

bors commented Aug 3, 2022

⌛ Trying commit 8bb7a85 with merge ff47dd48ed0d02534055e0033cf766ce528f8ebc...

@petrochenkov
Copy link
Contributor

I think this is the right thing to do.

  • $ crate certainly shouldn't turn into glued kw::DollarCrate in macro LHS, it only supposed to do that in macro output, i.e. in the results of the macro work after the macro is expanded.
  • If $ any_arbitrary_ident was accepted in macro LHS and was interpreted as two tokens, then it would be fine to accept $ crate as two tokens too, but it's not accepted because it's considered "reserved" as a part of the $ name : kind syntax even if there's no : after it, so it's reasonable to reserve $ crate too.

@CAD97
Copy link
Contributor Author

CAD97 commented Aug 3, 2022

If the crater run comes back clean, I'd like to at least consider landing this as-is with the hard error. If it's not clean or that's too aggressive, I can switch this to a future-compatility lint.

Ultimately, I'd like if $crate went through the binder handling path as just a reserved binder name rather than eager gluing; this would also open up the door to other default binder names (e.g. I've previously proposed $mod or similar to get path-fragment-to-macro-definition-scope). Also, if there's a specific reason for expanding/gluing to kw::DollarCrate rather than a def-site crate (diagnostics? avoiding hygiene 2.0 reliance?) I didn't find it the last time I looked.

(Doing so has knock-on benefits to #99035/#99445 as well.)

That's only really a potential follow-up after we catch lhs $crate in the first place, though. (And perhaps the gluing/resolution behavior needs to stay on current editions and only change in future ones for compatibility.)

@petrochenkov
Copy link
Contributor

Also, if there's a specific reason for expanding/gluing to kw::DollarCrate rather than a def-site crate

I think it was just impossible before #51952, and after than nobody tried, I guess.

diagnostics? avoiding hygiene 2.0 reliance?

Probably the former.
Also $crate is special-cased in pretty-printing because people try to compile pretty-printed code in practice.
Someone need to try it and see what happens.

@bors
Copy link
Contributor

bors commented Aug 3, 2022

☀️ Try build successful - checks-actions
Build commit: ff47dd48ed0d02534055e0033cf766ce528f8ebc (ff47dd48ed0d02534055e0033cf766ce528f8ebc)

@estebank
Copy link
Contributor

estebank commented Aug 3, 2022

@craterbot check

@craterbot
Copy link
Collaborator

👌 Experiment pr-99447 created and queued.
🤖 Automatically detected try build ff47dd48ed0d02534055e0033cf766ce528f8ebc
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Aug 3, 2022
@craterbot
Copy link
Collaborator

🚧 Experiment pr-99447 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot
Copy link
Collaborator

🎉 Experiment pr-99447 is completed!
📊 987 regressed and 5 fixed (240453 total)
📰 Open the full report.

⚠️ If you notice any spurious failure please add them to the blacklist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-crater Status: Waiting on a crater run to be completed. labels Aug 11, 2022
@Mark-Simulacrum
Copy link
Member

Cc rust-lang/crater#663, seems like whatever is causing that happened here too (not entirely unexpectedly)

@CAD97
Copy link
Contributor Author

CAD97 commented Aug 13, 2022

Of the crater-reported root regressions

Legitimate

crate downloads results patch
combu 8202 build failure
ndarray 3668328 build failure rust-ndarray/ndarray#1195

So this needs to be future incompatibility at worst.

Spurious

crate opinion
gclark916.vulkano_examples looks spurious (shader validation)
gclark916.vulkano_tri1 looks spurious (shader validation)
bitrust-0.1.0 Access Denied
ledger-transport-zemu-0.10.0 Access Denied
Ayrx.binja-rs-hello-world binaryninjacore-sys; looks spurious
Ninja3047.load-symbols binaryninjacore-sys; looks spurious
etke.bff binaryninjacore-sys; looks spurious
knarkzel.katsu looks spurious (unclear)
stuartZhang.scaffold-wizard looks spurious (unclear)
catboost2-sys spurious (missing rustfmt)
catboost2 catboost2-sys; spurious (missing rustfmt)
openexr-sys spurious (C++ dependencies)

Those unlisted here are all rust-lang/crater#663.

@CAD97
Copy link
Contributor Author

CAD97 commented Aug 13, 2022

@rustbot author

I need to change this to a future-compat lint to not break ndarray

@rustbot rustbot 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-review Status: Awaiting review from the assignee but also interested parties. labels Aug 13, 2022
bors added a commit to rust-lang/crater that referenced this pull request Oct 12, 2022
Add catboost2-sys as flaky

[build failed](https://crater-reports.s3.amazonaws.com/pr-99447/try%23ff47dd48ed0d02534055e0033cf766ce528f8ebc/reg/catboost2-sys-0.1.1%2Bcatboost.1.0.5/log.txt) in rust-lang/rust#99447 (comment); build requires rustfmt.

I'm not sure if this is how best to note this, but I'm doing my part to try to help minimize spurious regressions.
est31 added a commit to est31/crater that referenced this pull request Oct 27, 2022
They occured in two crater runs of two independent PRs, both in:

rust-lang/rust#99447 (comment)

And in:

rust-lang/rust#103293 (comment)
est31 added a commit to est31/crater that referenced this pull request Oct 27, 2022
They occured in two crater runs of two independent PRs, both in:

rust-lang/rust#99447 (comment)

And in:

rust-lang/rust#103293 (comment)
est31 added a commit to est31/crater that referenced this pull request Oct 28, 2022
They occured in two crater runs of two independent PRs, both in:

rust-lang/rust#99447 (comment)

And in:

rust-lang/rust#103293 (comment)
est31 added a commit to est31/crater that referenced this pull request Oct 28, 2022
They occured in two crater runs of two independent PRs, both in:

rust-lang/rust#99447 (comment)

And in:

rust-lang/rust#103293 (comment)
est31 added a commit to est31/crater that referenced this pull request Oct 28, 2022
They occured in two crater runs of two independent PRs, both in:

rust-lang/rust#99447 (comment)

And in:

rust-lang/rust#103293 (comment)
est31 added a commit to est31/crater that referenced this pull request Oct 28, 2022
They occured in two crater runs of two independent PRs, both in:

rust-lang/rust#99447 (comment)

And in:

rust-lang/rust#103293 (comment)
bors added a commit to rust-lang/crater that referenced this pull request Oct 29, 2022
Add catboost2-sys as flaky

[build failed](https://crater-reports.s3.amazonaws.com/pr-99447/try%23ff47dd48ed0d02534055e0033cf766ce528f8ebc/reg/catboost2-sys-0.1.1%2Bcatboost.1.0.5/log.txt) in rust-lang/rust#99447 (comment); build requires rustfmt.

I'm not sure if this is how best to note this, but I'm doing my part to try to help minimize spurious regressions.
@Dylan-DPC
Copy link
Member

@CAD97 any updates on this?

@jyn514
Copy link
Member

jyn514 commented Apr 26, 2023

I'm going to close this for now - feel free to re-open later if you have time to work on it.

@jyn514 jyn514 closed this Apr 26, 2023
@jyn514 jyn514 added S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Apr 26, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-inactive Status: Inactive and waiting on the author. This is often applied to closed PRs. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

$crate in a macro pattern behaves oddly