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 #99193

Closed

Conversation

c410-f3r
Copy link
Contributor

@c410-f3r c410-f3r commented Jul 12, 2022

Fixes #99035 by simply denying the usage of $$crate. Future decisions about how $$crate should behave (if it should) won't be a breaking change and I am out of a better idea.

cc @rust-lang/lang (Responsible team)
cc @petrochenkov (Reviewed most of the implementation)
cc @CAD97 (Created the issue)
cc @Mark-Simulacrum (Nominated the issue)

@rust-highfive
Copy link
Collaborator

r? @cjgillot

(rust-highfive has picked a reviewer for you, use r? to override)

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jul 12, 2022
@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 12, 2022
@CAD97
Copy link
Contributor

CAD97 commented Jul 12, 2022

Can we add a test that this is forbidden even through macro indirection? E.g. smth like

macro dollar_dollar_crate($d:tt) {
    $d $d crate
}

macro use_it() {
    use dollar_dollar_crate!($$);
}

use_it!()

Edit: also the same, but putting crate behind a tt/ident metavar

@c410-f3r c410-f3r force-pushed the yet-yet-yet-yet-another-macro branch from 9e9b542 to e2995e6 Compare July 12, 2022 22:57
Comment on lines 157 to 163
macro_rules! dollar_dollar_crate {
($d:tt) => {
const _: usize = $d$d crate::IDX;
//~^ ERROR expected expression, found `$`
};
}
dollar_dollar_crate!($);
Copy link
Contributor

Choose a reason for hiding this comment

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

This isn't quite the test I had in mind. Instead,

Suggested change
macro_rules! dollar_dollar_crate {
($d:tt) => {
const _: usize = $d$d crate::IDX;
//~^ ERROR expected expression, found `$`
};
}
dollar_dollar_crate!($);
macro_rules! dollar_dollar_crate {
($d:tt) => {
const _: usize = $d$d crate::IDX;
//~^ ERROR expected expression, found `$`
};
}
macro_rules! dollar_dollar_use {
($d:tt) => {
dollar_dollar_crate!($d);
}
}
dollar_dollar_use!($);

The fact that the current error message is "expected expression, found $" and not "$$crate is not allowed" makes me worried that this actually will work i.e. $$crate is insufficiently gated.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed as requested

Copy link
Contributor

Choose a reason for hiding this comment

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

Is this resolved? There is still no error on the indirect $$crate.

@apiraino
Copy link
Contributor

apiraino commented Jul 13, 2022

I think this PR is meant to reach stable, right? (i.e. the alternate implementation of $$crate will take longer than 1.63 milestone). If yes I hope it's correct to label this revert to be mentioned in the release notes.

@rustbot label relnotes T-lang

@rustbot rustbot 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 Jul 13, 2022
@c410-f3r
Copy link
Contributor Author

c410-f3r commented Jul 13, 2022

I think this PR is meant to reach stable, right? (i.e. the alternate implementation of $$crate will take longer than 1.63 milestone). If yes I hope it's correct to label this revert to be mentioned in the release notes.

@rustbot label relnotes T-lang

Everything is a best effort to solve a problem. It is not clear if the feature will be removed from 1.63 or if this PR can be back-ported .

EDIT: The feature will actually be reverted as described in #99035 (comment)

@c410-f3r c410-f3r force-pushed the yet-yet-yet-yet-another-macro branch from e2995e6 to f4f3913 Compare July 18, 2022 18:58
@c410-f3r
Copy link
Contributor Author

Is the lang-team going to merge this PR? Perhaps some other strategy will be used? Perhaps try another compiler reviewer?

Its been 6 days and it would be a shame to miss 1.64 for whatever reason.

@Mark-Simulacrum Mark-Simulacrum added the beta-nominated Nominated for backporting to the compiler in the beta channel. label Jul 18, 2022
@Mark-Simulacrum
Copy link
Member

beta-nominating -- partially to get eyes on this from T-compiler (who should do the code review), and partially because we do need to beta backport either this PR or a full revert of the original PR. (Either is fine, but if it's the latter someone needs to do the legwork).

@CAD97
Copy link
Contributor

CAD97 commented Jul 18, 2022

Mechanical revert available at #99435

@Mark-Simulacrum Mark-Simulacrum removed the beta-nominated Nominated for backporting to the compiler in the beta channel. label Jul 18, 2022
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jul 19, 2022
…=Mark-Simulacrum

Revert "Stabilize $$ in Rust 1.63.0"

This mechanically reverts commit 9edaa76, the one commit from rust-lang#95860.

rust-lang#99035; the behavior of `$$crate` is potentially unexpected and not ready to be stabilized. rust-lang#99193 attempts to forbid `$$crate` without also destabilizing `$$` more generally.

`@rustbot` modify labels +T-compiler +T-lang +P-medium +beta-nominated +relnotes

(applying the labels I think are accurate from the issue and alternative partial revert)

cc `@Mark-Simulacrum`
ehuss pushed a commit to ehuss/rust that referenced this pull request Jul 22, 2022
…=Mark-Simulacrum

Revert "Stabilize $$ in Rust 1.63.0"

This mechanically reverts commit 9edaa76, the one commit from rust-lang#95860.

rust-lang#99035; the behavior of `$$crate` is potentially unexpected and not ready to be stabilized. rust-lang#99193 attempts to forbid `$$crate` without also destabilizing `$$` more generally.

`@rustbot` modify labels +T-compiler +T-lang +P-medium +beta-nominated +relnotes

(applying the labels I think are accurate from the issue and alternative partial revert)

cc `@Mark-Simulacrum`
token.span,
&format!("unexpected token: {}", pprust::token_to_string(token))
);
sess.span_diagnostic.note_without_error("`$$crate` is not allowed in any context");
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not directly span_err on this message? Should we point to the two $ tokens too?

Comment on lines 157 to 163
macro_rules! dollar_dollar_crate {
($d:tt) => {
const _: usize = $d$d crate::IDX;
//~^ ERROR expected expression, found `$`
};
}
dollar_dollar_crate!($);
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this resolved? There is still no error on the indirect $$crate.

@cjgillot cjgillot 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 Jul 24, 2022
@c410-f3r
Copy link
Contributor Author

Sorry, all the obstacles imposed by different actors in different fronts made me lost the motivation/energy to keep coding this PR. Closing.

@c410-f3r c410-f3r closed this Jul 25, 2022
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. S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. 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.

$$crate unexpectedly fails to defer which crate $crate refers to
7 participants