-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
Fix split index calculation in check_type_alias_where_clause_location
#138037
base: master
Are you sure you want to change the base?
Conversation
This comment has been minimized.
This comment has been minimized.
895a31f
to
a78592e
Compare
check_type_alias_where_clause_location
check_type_alias_where_clause_location
check_type_alias_where_clause_location
Some changes occurred in src/tools/rustfmt cc @rust-lang/rustfmt |
before_with_attr_count: before_where_clause | ||
.predicates | ||
.iter() | ||
.filter(|p| !p.attrs.is_empty()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Filtering things which have attributes applied to them isn't really correct because it's not necessarily the case that all cfg
d where clauses will be removed during macro expansion, e.g.
#![feature(where_clause_attrs, cfg_boolean_literals, lazy_type_alias)]
#![expect(incomplete_features)]
struct Foo;
trait Trait {}
impl Trait for Foo {}
type MixedWhereBounds
where
#[cfg(true)]
Foo: Trait,
= Foo
where
(): Sized;
Here we have a where clause before the =
that has an attribute applied to it, yet the where clause will still be present after macro expansion.
If you run the compiler on this example with your changes, and then remove the cfg
, you'll get different diagnostics output even though post-expansion it'll be the same set of where clauses. That's caused by this before_with_attr_count
being 1
and then when we split the where clauses into before/after you wind up splitting at 0
so both clauses end up in the "after" bucket.
Can you add both version as a test (with/without cfg(true)
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not really sure what the correct way to implement this is 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your detailed explanation, I will add a few tests first.
a78592e
to
ba719b9
Compare
Fix the calculation of the split index in
check_type_alias_where_clause_location
by ignoring before-equals-sign-clauses with attributes.Fix #138010.
cc @frank-king.