Skip to content

warn on align on fields to avoid breaking changes #143868

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jdonszelmann
Copy link
Contributor

@rustbot
Copy link
Collaborator

rustbot commented Jul 13, 2025

workingjubilee is currently at their maximum review capacity.
They may take a while to respond.

@rustbot rustbot added A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. labels Jul 13, 2025
@rust-log-analyzer

This comment has been minimized.

@jdonszelmann jdonszelmann force-pushed the fix-align-on-fields branch from e38322a to a5ab682 Compare July 13, 2025 06:26
Comment on lines +1947 to +1954
Target::Field => {
self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES,
hir_id,
attr_span,
AlignOnFields { span },
);
}
Copy link
Member

Choose a reason for hiding this comment

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

Question: do we already have test coverage for this case?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We have about 20 of these cases and to the best of my knowledge no test coverage for any :ferris clueless:

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't really have time to atm, am on holiday. Just knew how to fix this issue well

Copy link
Member

Choose a reason for hiding this comment

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

Yes, we may wish to land this and maybe open an issue about getting test coverage.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

feel free to assign me or @JonathanBrouwer (who I think was interested in this sort of thing)

@workingjubilee
Copy link
Member

I'm landing this to fix this right now on nightly, unsure if this is the right fix for beta.

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Jul 13, 2025

📌 Commit a5ab682 has been approved by workingjubilee

It is now in the queue for this repository.

@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-review Status: Awaiting review from the assignee but also interested parties. labels Jul 13, 2025
fmease added a commit to fmease/rust that referenced this pull request Jul 14, 2025
…r=workingjubilee

warn on align on fields to avoid breaking changes

r? `@workingjubilee`
bors added a commit that referenced this pull request Jul 14, 2025
Rollup of 16 pull requests

Successful merges:

 - #142885 (core: Add `BorrowedCursor::with_unfilled_buf`)
 - #143217 (Port #[link_ordinal] to the new attribute parsing infrastructure)
 - #143355 (wrapping shift: remove first bitmask and table)
 - #143448 (remote-test-client: Exit code `128 + <signal-number>` instead of `3`)
 - #143592 (UWP: link ntdll functions using raw-dylib)
 - #143681 (bootstrap/miri: avoid rebuilds for test builds)
 - #143710 (Updates to random number generation APIs)
 - #143724 (Tidy cleanup)
 - #143820 (Fixed a core crate compilation failure when enabling the `optimize_for_size` feature on some targets)
 - #143850 (Compiletest: Simplify {Html,Json}DocCk directive handling)
 - #143855 (Port `#[omit_gdb_pretty_printer_section]` to the new attribute parsing)
 - #143868 (warn on align on fields to avoid breaking changes)
 - #143875 (update issue number for `const_trait_impl`)
 - #143881 (Use zero for initialized Once state)
 - #143887 (Run bootstrap tests sooner in the `x test` pipeline)
 - #143893 (Don't require `eh_personality` lang item on targets that have a personality)

Failed merges:

 - #143878 (Port `#[pointee]` to the new attribute parsing infrastructure)
 - #143891 (Port `#[coverage]` to the new attribute system)

r? `@ghost`
`@rustbot` modify labels: rollup
jhpratt added a commit to jhpratt/rust that referenced this pull request Jul 14, 2025
…r=workingjubilee

warn on align on fields to avoid breaking changes

r? ``@workingjubilee``
bors added a commit that referenced this pull request Jul 14, 2025
Rollup of 17 pull requests

Successful merges:

 - #142885 (core: Add `BorrowedCursor::with_unfilled_buf`)
 - #143217 (Port #[link_ordinal] to the new attribute parsing infrastructure)
 - #143355 (wrapping shift: remove first bitmask and table)
 - #143448 (remote-test-client: Exit code `128 + <signal-number>` instead of `3`)
 - #143681 (bootstrap/miri: avoid rebuilds for test builds)
 - #143710 (Updates to random number generation APIs)
 - #143724 (Tidy cleanup)
 - #143738 (Move several float tests to floats/mod.rs)
 - #143820 (Fixed a core crate compilation failure when enabling the `optimize_for_size` feature on some targets)
 - #143850 (Compiletest: Simplify {Html,Json}DocCk directive handling)
 - #143855 (Port `#[omit_gdb_pretty_printer_section]` to the new attribute parsing)
 - #143868 (warn on align on fields to avoid breaking changes)
 - #143875 (update issue number for `const_trait_impl`)
 - #143881 (Use zero for initialized Once state)
 - #143887 (Run bootstrap tests sooner in the `x test` pipeline)
 - #143893 (Don't require `eh_personality` lang item on targets that have a personality)
 - #143901 (Region constraint nits)

Failed merges:

 - #143878 (Port `#[pointee]` to the new attribute parsing infrastructure)
 - #143891 (Port `#[coverage]` to the new attribute system)

r? `@ghost`
`@rustbot` modify labels: rollup
Comment on lines +1947 to +1954
Target::Field => {
self.tcx.emit_node_span_lint(
UNUSED_ATTRIBUTES,
hir_id,
attr_span,
AlignOnFields { span },
);
}
Copy link
Member

@jieyouxu jieyouxu Jul 14, 2025

Choose a reason for hiding this comment

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

Question: wait hold on, what does this PR intend to do? If the intention was to not error on #[align] in various positions where we previously did not do, then this PR doesn't do that, because #142507 is a breaking change even if #[align] is an unstable built-in attribute, because unstable built-in attributes still participate in name resolution, and thus will still cause the ambiguity. This PR additionally produces another warning (i.e. unused_attributes) but does not prevent the name resolution ambiguity error from happening, cf. #134963.

Counter-example (I tried this test which fails on master, and also the commit from this PR, ignoring the irrelevant unstable fn_align feature gate warnings):

// tests/ui/whatever_subdir/test.rs

//@ proc-macro: my_derive.rs
//@ edition: 2024

use my_derive::MyDerive;

#[derive(MyDerive)]
#[align]
//~^ ERROR `align` is ambiguous
pub struct Foo;

fn main() {}
// tests/ui/whatever_subdir/auxiliary/my_derive.rs

//@ edition: 2024

extern crate proc_macro;
use proc_macro::{Span, TokenStream};

#[proc_macro_derive(
    MyDerive,
    attributes(
        align
    )
)]
pub fn derive_custom(_item: TokenStream) -> TokenStream {
    TokenStream::new()
}

I think if we wanted to prevent that ambiguity error from happening entirely, we'd need to pick one of the following options (or more) or some alternative solution:

  1. Have to fix how built-in attributes are resolved versus user attributes
  2. Revert use #[align] attribute for fn_align #142507
  3. Rename #[align] to something less common.

Copy link
Member

Choose a reason for hiding this comment

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

(That is, I think this PR itself is correct, but doesn't address #143834.)

samueltardieu added a commit to samueltardieu/rust that referenced this pull request Jul 14, 2025
…r=workingjubilee

warn on align on fields to avoid breaking changes

r? `@workingjubilee`
bors added a commit that referenced this pull request Jul 14, 2025
Rollup of 8 pull requests

Successful merges:

 - #141809 (Don't call WSACleanup on process exit)
 - #143710 (Updates to random number generation APIs)
 - #143848 (Rename `stable_mir` and `rustc_smir`)
 - #143855 (Port `#[omit_gdb_pretty_printer_section]` to the new attribute parsing)
 - #143868 (warn on align on fields to avoid breaking changes)
 - #143870 ([COMPILETEST-UNTANGLE 6/N] Use `TestSuite` enum instead of stringly-typed test suites)
 - #143901 (Region constraint nits)
 - #143903 (Fix typos in documentation files)

r? `@ghost`
`@rustbot` modify labels: rollup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-attributes Area: Attributes (`#[…]`, `#![…]`) S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

6 participants