Skip to content

Commit 3d5bd95

Browse files
Fix ICE Caused by Incorrectly Delaying E0107
1 parent b58ce4e commit 3d5bd95

File tree

2 files changed

+32
-14
lines changed

2 files changed

+32
-14
lines changed

compiler/rustc_hir/src/hir.rs

+5
Original file line numberDiff line numberDiff line change
@@ -3689,6 +3689,11 @@ impl<'hir> OwnerNode<'hir> {
36893689
}
36903690
}
36913691

3692+
/// Check if node is an impl block.
3693+
pub fn is_impl_block(&self) -> bool {
3694+
matches!(self, OwnerNode::Item(Item { kind: ItemKind::Impl(_), .. }))
3695+
}
3696+
36923697
expect_methods_self! {
36933698
expect_item, &'hir Item<'hir>, OwnerNode::Item(n), n;
36943699
expect_foreign_item, &'hir ForeignItem<'hir>, OwnerNode::ForeignItem(n), n;

compiler/rustc_hir_analysis/src/hir_ty_lowering/generics.rs

+27-14
Original file line numberDiff line numberDiff line change
@@ -552,21 +552,34 @@ pub(crate) fn check_generic_arg_count(
552552
synth_provided,
553553
}
554554
} else {
555-
let num_missing_args = expected_max - provided;
555+
// Check if associated type bounds are incorrectly written in impl block header like:
556+
// ```
557+
// trait Foo<T> {}
558+
// impl Foo<T: Default> for u8 {}
559+
// ```
560+
let parent_is_impl_block = cx
561+
.tcx()
562+
.hir()
563+
.parent_owner_iter(seg.hir_id)
564+
.next()
565+
.is_some_and(|(_, owner_node)| owner_node.is_impl_block());
566+
if parent_is_impl_block {
567+
let constraint_names: Vec<_> =
568+
gen_args.constraints.iter().map(|b| b.ident.name).collect();
569+
let param_names: Vec<_> = gen_params
570+
.own_params
571+
.iter()
572+
.filter(|param| !has_self || param.index != 0) // Assumes `Self` will always be the first parameter
573+
.map(|param| param.name)
574+
.collect();
575+
if constraint_names == param_names {
576+
// We set this to true and delay emitting `WrongNumberOfGenericArgs`
577+
// to provide a succinct error for cases like issue #113073
578+
all_params_are_binded = true;
579+
};
580+
}
556581

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

571584
GenericArgsInfo::MissingTypesOrConsts {
572585
num_missing_args,

0 commit comments

Comments
 (0)