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

"auto trait" syntax gets accepted on stable in cfg-disabled code #116121

Closed
RalfJung opened this issue Sep 24, 2023 · 5 comments · Fixed by #116393
Closed

"auto trait" syntax gets accepted on stable in cfg-disabled code #116121

RalfJung opened this issue Sep 24, 2023 · 5 comments · Fixed by #116393
Labels
A-auto-traits Area: auto traits (e.g., `auto trait Send {}`) C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. F-auto_traits `#![feature(auto_traits)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.

Comments

@RalfJung
Copy link
Member

RalfJung commented Sep 24, 2023

The following code builds on stable without even a warning:

#[cfg(any())]
auto trait Foo {}

That is surprising since there was some effort recently to start ensuring that unstable syntax does not "leak" into stable Rust, so I expected at least a future-compatibility warning. (See e.g. #99935)

Cc @petrochenkov @CAD97

@rustbot rustbot added the needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. label Sep 24, 2023
@Noratrieb
Copy link
Member

from the code I'd expect a warning:

feature_warn(&visitor.sess.parse_sess, name, span, explain);

@Noratrieb
Copy link
Member

ah no, auto traits don't use that gating:

When parsing an auto trait in the parser, we need to gate it's span and then in the feature gating pass gate it too. This will look similar to, for example, trait_alias.

@Noratrieb Noratrieb added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. C-bug Category: This is a bug. A-auto-traits Area: auto traits (e.g., `auto trait Send {}`) and removed needs-triage This issue may need triage. Remove it if it has been sufficiently triaged. labels Sep 24, 2023
@CAD97
Copy link
Contributor

CAD97 commented Sep 24, 2023

#99935 was just for syntax which was previously attempted to reverse stabilization and had the gating code there but disabled. Now that the plumbing exists, using that as a template to add this syntax to the warning should be fairly straightforward.

It might make sense to go ahead and crater immediately making this a hard feature gate, though.

@Noratrieb
Copy link
Member

Noratrieb commented Sep 24, 2023

I can already tell you of one large regression, the PyO3 crate. We should do the feature gating normally as a warning and worry about making it an error later. Once it's a warning, people adding uses get warnings and we should be fine.

@Noratrieb
Copy link
Member

A bit unrelated, but I think it would be useful to have docs somewhere that show how to resolve this issue if you have the feature behind a cfg, the easiest solution being a macro_rules macro.

#[cfg(feature = "nightly")]
macro_rules! define {
  ($($tt:tt)*) => { $($tt)* }
}
#[cfg(not(feature = "nightly"))]
macro_rules! define {
  ($($tt:tt)*) => {}
}

define! { pub auto trait Uwu {} }

But that doesn't have to be fixed here.

@52 52 removed their assignment Oct 3, 2023
@fmease fmease added the F-auto_traits `#![feature(auto_traits)]` label Oct 3, 2023
@bors bors closed this as completed in 4ed2291 Oct 4, 2023
rust-timer added a commit to rust-lang-ci/rust that referenced this issue Oct 4, 2023
Rollup merge of rust-lang#116393 - compiler-errors:auto-bad, r=WaffleLapkin

Emit feature gate *warning* for `auto` traits pre-expansion

Auto traits were introduced before we were more careful about not stabilizing new syntax pre-expansion.

This is a more conservative step in the general direction we want to go in https://rust-lang.zulipchat.com/#narrow/stream/213817-t-lang/topic/Removal.20of.20.60auto.20trait.60.20syntax.

Fixes rust-lang#116121
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-auto-traits Area: auto traits (e.g., `auto trait Send {}`) C-bug Category: This is a bug. E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-mentor Call for participation: This issue has a mentor. Use #t-compiler/help on Zulip for discussion. F-auto_traits `#![feature(auto_traits)]` T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants