Skip to content

Conversation

Jarcho
Copy link
Contributor

@Jarcho Jarcho commented Aug 31, 2025

This replaces the many exported functions that used to exist with a single spanless_eq function. The macros implementing this would be derives, but that's not possible so nearly copying the struct/enum definitions is required.

The new implementation has full exhaustiveness checking on both fields and variants. This way any changes made to the AST in rustc will require changes here.

changelog: none

@rustbot
Copy link
Collaborator

rustbot commented Aug 31, 2025

r? @Alexendoo

rustbot has assigned @Alexendoo.
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 the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Aug 31, 2025
Comment on lines 1 to 3
//! Utilities for manipulating and extracting information from `rustc_ast::ast`.
//!
//! - The `eq_foobar` functions test for semantic equality but ignores `NodeId`s and `Span`s.
Copy link
Member

Choose a reason for hiding this comment

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

Module docs could do with an update now

(@unequal $($val:tt)*) => { $($val)? };
}

/// Impls for structs which will be implemented matching the variant and comparing
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/// Impls for structs which will be implemented matching the variant and comparing
/// Impls for enums which will be implemented matching the variant and comparing

Comment on lines +547 to +577
$(
(
$name::$vname { $($fname: $lname),*},
$name::$vname { $($fname: $rname),*}
) => {
$(on_unequal!(@$unequal return false);)?
$(eq_enum_field!($(@$unordered)? cx $lname $rname) &&)* true
},
)*
Copy link
Member

Choose a reason for hiding this comment

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

Could we use ${concat} here to allow a similar syntax to the struct definitions?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I ran into hygiene issues when I tried it the first time, but it might be a thing I can work around.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Tried some other options. The feature is just not implemented enough currently to work.

Copy link
Contributor Author

@Jarcho Jarcho Sep 3, 2025

Choose a reason for hiding this comment

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

concat doesn't work in nested repetitions and pushing the concat into an inner macro means the generated identifier can only the inner macro can access the name due to hygiene rules. Basically neither of these work:

// with repetitions: ice
$(
  (
    $var { $($name: ${concat(l, $name)}),*  },
    $var { $($name: ${concat(r, $name)}),*  },
  ) => $(eq!(${concat(l, $name)} ${concat(r, $name)}))&&*,
)*

// with inner: binding names can't be used outside the `name` macro
$(
  (
    $var { $($name: name!(l, $name)),*  },
    $var { $($name: name!(r, $name)),*  },
  ) => $(eq!($name))&&*,
)*

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants