Skip to content

Incoming breakage: Use new auto trait syntax#1

Open
fmease wants to merge 1 commit intoarcnmx:masterfrom
fmease-extra:new-auto-trait-syntax
Open

Incoming breakage: Use new auto trait syntax#1
fmease wants to merge 1 commit intoarcnmx:masterfrom
fmease-extra:new-auto-trait-syntax

Conversation

@fmease
Copy link
Copy Markdown

@fmease fmease commented Mar 28, 2026

Hello there 👋, I'm a member of the Rust compiler team.

Your crate is using the syntax impl Trait for .. {} (unsafe impl Unaligned for .. { }) that was declared obsolete back in 2017 (~8.5 years ago) in PR rust-lang/rust#45247.

Since your use of this default impl is behind a cfg (#[cfg(feature = "oibit")]) and feature optin_builtin_traits (removed in 1.50, released 2021) wasn't protected by a so-called pre-expansion feature gate similar to a few other legacy features, to this day rustc doesn't raise an error if Cargo feature oibit isn't enabled.

We'd obviously like to fully remove this syntax from rustc's parser but we can't do so without breaking a small set of crates in the ecosystem which includes yours (found thanks to crater: rust-lang/rust#121072 (comment)).

While by default your crate still compiles under the latest version of rustc, under Cargo feature oibit it no longer compiles since at least 1.50 (2021). That's because (1) impl Trait for .. {} leads to a hard error (2) feature optin_builtin_traits no longer exists having been replaced by features auto_traits and negative_impls leading to another error.

In this PR, I've migrated the obsolete syntax to the "new" auto trait Trait {} and have wrapped unstable syntax (auto traits & negative impls) in a cfg-dependent macro invocation to future-proof your crate against situations like this and the planned pre-expansion feature gates for auto_traits and negative_impls (ones that error "even if the syntax is behind a cfg", roughly).

I've verified that your crate compiles on 1.37 stable (2019), 1.50 stable (2021), 1.94.1 stable (2026), 2026-03-19 nightly with and without Cargo feature oibit.

This is all part of the following tracking issue: rust-lang/rust#154045. Thanks a lot in advance for your understanding and apologies for the inconvenience. Feel free to ask me any questions.

@fmease fmease force-pushed the new-auto-trait-syntax branch from 245ce65 to a16bf2c Compare March 28, 2026 15:47
@fmease fmease marked this pull request as ready for review March 28, 2026 15:47
Comment thread src/lib.rs
/// contain only members of these types.
pub unsafe trait Unaligned { }
macro_rules! define_marker_trait_unaligned {
([$($auto:ident)?] $($impl:item)*) => {
Copy link
Copy Markdown
Author

@fmease fmease Mar 28, 2026

Choose a reason for hiding this comment

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

I'm using the Kleene ? out of convenience. However, that sets the minimum supported Rust version (MSRV) to 1.37 (2019). I could replace it with Kleene * to potentially lower the MSRV if you'd like me to. I haven't investigated the MSRV of the master branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant