Skip to content

Commit b47ff52

Browse files
committed
Return empty list early for non-function child segments
Instead of computing self_ty during error recovery, skip generic args processing entirely when the child segment resolves to a non-function. The error (E0423) is already emitted elsewhere. Also rename test to remove ice- prefix and add needs-rustc-debug-assertions.
1 parent 88a9135 commit b47ff52

3 files changed

Lines changed: 7 additions & 15 deletions

File tree

compiler/rustc_hir_analysis/src/delegation.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,11 @@ fn get_delegation_user_specified_args<'tcx>(
596596
.as_slice()
597597
});
598598

599-
let child_args = info.child_args_segment_id.and_then(get_segment).map(|(segment, def_id)| {
599+
let child_args = info.child_args_segment_id.map(get_segment).map(|(segment, def_id)| {
600+
if !matches!(tcx.def_kind(def_id), DefKind::Fn | DefKind::AssocFn) {
601+
return &[][..];
602+
}
603+
600604
let parent_args = if let Some(parent_args) = parent_args {
601605
parent_args
602606
} else {
@@ -608,25 +612,13 @@ fn get_delegation_user_specified_args<'tcx>(
608612
}
609613
};
610614

611-
// Provide `self_ty` only when the child segment resolves to a non-function
612-
// item with Self (e.g. a Trait during error recovery). For trait methods
613-
// (AssocFn), `has_self` is true (inherited from parent trait) but Self
614-
// comes from `parent_args`, not `self_ty`.
615-
let self_ty = if !matches!(tcx.def_kind(def_id), DefKind::Fn | DefKind::AssocFn)
616-
&& tcx.generics_of(def_id).has_self
617-
{
618-
get_delegation_self_ty(tcx, delegation_id)
619-
} else {
620-
None
621-
};
622-
623615
let args = lowerer
624616
.lower_generic_args_of_path(
625617
segment.ident.span,
626618
def_id,
627619
parent_args,
628620
segment,
629-
self_ty,
621+
None,
630622
GenericArgPosition::Value,
631623
)
632624
.0;

tests/ui/delegation/ice-reuse-trait-path-with-empty-generics.rs renamed to tests/ui/delegation/reuse-trait-path-with-empty-generics.rs

File renamed without changes.

tests/ui/delegation/ice-reuse-trait-path-with-empty-generics.stderr renamed to tests/ui/delegation/reuse-trait-path-with-empty-generics.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error[E0423]: expected function, found trait `Trait`
2-
--> $DIR/ice-reuse-trait-path-with-empty-generics.rs:9:11
2+
--> $DIR/reuse-trait-path-with-empty-generics.rs:10:11
33
|
44
LL | reuse Trait::<> as bar4;
55
| ^^^^^^^^^ not a function

0 commit comments

Comments
 (0)