Skip to content

Conversation

@ChayimFriedman2
Copy link
Contributor

Also known as E0747 and E0107.

And by the way, rewrite how we lower generic arguments and deduplicate it between paths and method calls. The new version is taken almost straight from rustc.

This commit also changes the binders of generic_defaults(), to only include the binders of the arguments up to (and not including) the current argument. This make it easier to handle it in the rewritten lowering of generic args. It's also how rustc does it.

This is a step towards #17590, the next step will be to add a quickfix to the count mismatch diagnostic that adds new parameters. Since this became somewhat big I separated the steps.

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Mar 30, 2025
@ChayimFriedman2 ChayimFriedman2 force-pushed the generic-mismatch branch 4 times, most recently from 107dbaa to 8de5777 Compare April 14, 2025 08:57
Comment on lines +3232 to +3262

/// This function find the AST fragment that corresponds to an `AssociatedTypeBinding` in the HIR.
pub fn hir_assoc_type_binding_to_ast(
segment_args: &ast::GenericArgList,
binding_idx: u32,
) -> Option<ast::AssocTypeArg> {
segment_args
.generic_args()
.filter_map(|arg| match arg {
ast::GenericArg::AssocTypeArg(it) => Some(it),
_ => None,
})
.filter(|binding| binding.param_list().is_none() && binding.name_ref().is_some())
.nth(binding_idx as usize)
}

/// This function find the AST generic argument from the one in the HIR. Does not support the `Self` argument.
pub fn hir_generic_arg_to_ast(
args: &ast::GenericArgList,
arg_idx: u32,
has_self_arg: bool,
) -> Option<ast::GenericArg> {
args.generic_args()
.filter(|arg| match arg {
ast::GenericArg::AssocTypeArg(_) => false,
ast::GenericArg::LifetimeArg(arg) => arg.lifetime().is_some(),
ast::GenericArg::ConstArg(_) | ast::GenericArg::TypeArg(_) => true,
})
.nth(arg_idx as usize - has_self_arg as usize)
}
Copy link
Member

Choose a reason for hiding this comment

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

Naming nit (also the location for them seems unrelated), these don't touch anything hir related

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The hir is against the ast: it finds the AST for the HIR lowered.

@Veykril
Copy link
Member

Veykril commented Apr 21, 2025

#19624 will probably collide with this once merged

@ChayimFriedman2
Copy link
Contributor Author

#19624 will probably collide with this once merged

I'm fine with waiting until it's merged, I don't want to make @jackh726's life any harder.

… and another for mismatch in their kind

Also known as E0747 and E0107.

And by the way, rewrite how we lower generic arguments and deduplicate it between paths and method calls. The new version is taken almost straight from rustc.

This commit also changes the binders of `generic_defaults()`, to only include the binders of the arguments up to (and not including) the current argument. This make it easier to handle it in the rewritten lowering of generic args. It's also how rustc does it.
@ChayimFriedman2
Copy link
Contributor Author

Alright, rebased and addressed comments.

@Veykril Veykril enabled auto-merge April 22, 2025 11:56
@Veykril Veykril added this pull request to the merge queue Apr 22, 2025
Merged via the queue into rust-lang:master with commit 9632b38 Apr 22, 2025
14 checks passed
@ChayimFriedman2 ChayimFriedman2 deleted the generic-mismatch branch April 22, 2025 12:22
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