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

Fix split index calculation in check_type_alias_where_clause_location #138037

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

Conversation

stuuupidcat
Copy link

@stuuupidcat stuuupidcat commented Mar 5, 2025

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.

@rustbot
Copy link
Collaborator

rustbot commented Mar 5, 2025

r? @BoxyUwU

rustbot has assigned @BoxyUwU.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added 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 Mar 5, 2025
@rust-log-analyzer

This comment has been minimized.

@stuuupidcat stuuupidcat marked this pull request as draft March 5, 2025 07:46
@stuuupidcat stuuupidcat changed the title Fix split calculation in type alias where clauses Fix split calculation in check_type_alias_where_clause_location Mar 5, 2025
@stuuupidcat stuuupidcat changed the title Fix split calculation in check_type_alias_where_clause_location Fix split index calculation in check_type_alias_where_clause_location Mar 5, 2025
@stuuupidcat stuuupidcat marked this pull request as ready for review March 5, 2025 10:06
@rustbot
Copy link
Collaborator

rustbot commented Mar 5, 2025

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())
Copy link
Member

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 cfgd 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))?

Copy link
Member

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 🤔

Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

ICE: mid > len
4 participants