Skip to content

Commit

Permalink
Fix ICE Caused by Incorrectly Delaying E0107
Browse files Browse the repository at this point in the history
  • Loading branch information
veera-sivarajan committed Jul 30, 2024
1 parent b58ce4e commit 3d5bd95
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 14 deletions.
5 changes: 5 additions & 0 deletions compiler/rustc_hir/src/hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3689,6 +3689,11 @@ impl<'hir> OwnerNode<'hir> {
}
}

/// Check if node is an impl block.
pub fn is_impl_block(&self) -> bool {
matches!(self, OwnerNode::Item(Item { kind: ItemKind::Impl(_), .. }))
}

expect_methods_self! {
expect_item, &'hir Item<'hir>, OwnerNode::Item(n), n;
expect_foreign_item, &'hir ForeignItem<'hir>, OwnerNode::ForeignItem(n), n;
Expand Down
41 changes: 27 additions & 14 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -552,21 +552,34 @@ pub(crate) fn check_generic_arg_count(
synth_provided,
}
} else {
let num_missing_args = expected_max - provided;
// Check if associated type bounds are incorrectly written in impl block header like:
// ```
// trait Foo<T> {}
// impl Foo<T: Default> for u8 {}
// ```
let parent_is_impl_block = cx
.tcx()
.hir()
.parent_owner_iter(seg.hir_id)
.next()
.is_some_and(|(_, owner_node)| owner_node.is_impl_block());
if parent_is_impl_block {
let constraint_names: Vec<_> =
gen_args.constraints.iter().map(|b| b.ident.name).collect();
let param_names: Vec<_> = gen_params
.own_params
.iter()
.filter(|param| !has_self || param.index != 0) // Assumes `Self` will always be the first parameter
.map(|param| param.name)
.collect();
if constraint_names == param_names {
// We set this to true and delay emitting `WrongNumberOfGenericArgs`
// to provide a succinct error for cases like issue #113073
all_params_are_binded = true;
};
}

let constraint_names: Vec<_> =
gen_args.constraints.iter().map(|b| b.ident.name).collect();
let param_names: Vec<_> = gen_params
.own_params
.iter()
.filter(|param| !has_self || param.index != 0) // Assumes `Self` will always be the first parameter
.map(|param| param.name)
.collect();
if constraint_names == param_names {
// We set this to true and delay emitting `WrongNumberOfGenericArgs`
// to provide a succinct error for cases like issue #113073
all_params_are_binded = true;
};
let num_missing_args = expected_max - provided;

GenericArgsInfo::MissingTypesOrConsts {
num_missing_args,
Expand Down

0 comments on commit 3d5bd95

Please sign in to comment.