rust-lang/rust · error
`Self` generic param is not found while expected
Error message
`Self` generic param is not found while expected
What it means
Internal delegation-feature invariant (delegation/generics.rs:219). find_self_param() searches the HIR generic params for one named SelfUpper and expects to find it. It only runs when the delegation resolver decided a Self param should be generated (free-context delegation into a trait). A panic means the expected uplifted Self param is missing from the parent's HIR generics.
Solutions
- File a rustc ICE with the minimized delegation repro (this is an unstable feature).
- Avoid the delegation syntax that targets trait methods from free context; delegate to inherent/method fns instead.
- Try a different nightly; bisect with cargo bisect-rustc.
- Remove explicit generic args on the delegation path to simplify resolution.
Defensive patterns
Strategy: validation
Prevention
- This is an ICE in the unstable delegation feature; avoid delegating to trait methods from free context.
- File a rustc issue with the minimized delegation repro.
- Bisect with cargo bisect-rustc and pin to a working nightly.
- Prefer delegating to inherent methods until the feature stabilizes.
When it happens
Trigger: Using the unstable `reuse`/delegation syntax where a free-standing delegate targets a trait method and generate_self is true, but the lowered parent generics lack a Self param.
Common situations: Experimental nightly code using fn delegation; a compiler bug in the delegation lowering pass; mixing delegation with unusual generic contexts.
Related errors
- must be at least one segment
- must contain self type as `SelfTy` propagation kind is…
- alt layout should always work
- alt layout should have a niche like the regular one
- arg must exist for infer
AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10).
Data as JSON: /api/errors/c8ace451f9978498.
Report an issue: GitHub.
Appendix: source
Thrown at compiler/rustc_ast_lowering/src/delegation/generics.rs:219
pub(super) fn is_trait_impl(&self) -> bool {
match self {
HirOrTyGenerics::Ty(ty) => ty.trait_impl,
HirOrTyGenerics::Hir(hir) => hir.trait_impl,
}
}
pub(super) fn find_self_param(&self) -> &'hir hir::GenericParam<'hir> {
match self {
HirOrTyGenerics::Ty(_) => {
bug!("accessed ty-level generics while searching for uplifted `Self` param")
}
HirOrTyGenerics::Hir(hir) => hir
.data
.params
.iter()
.find(|p| p.name.ident().name == kw::SelfUpper)
.expect("`Self` generic param is not found while expected"),
}
}
pub(crate) fn pos(&self) -> GenericsPosition {
match self {
HirOrTyGenerics::Ty(ty) => ty.pos,
HirOrTyGenerics::Hir(hir) => hir.pos,
}
}
}
impl<'hir> GenericsGenerationResult<'hir> {
fn new(generics: DelegationGenerics<TyGenerics<'hir>>) -> GenericsGenerationResult<'hir> {
GenericsGenerationResult {
generics: HirOrTyGenerics::Ty(generics),
args_segment_id: HirId::INVALID,
use_for_sig_inheritance: false,
}View on GitHub (pinned to 7088e4b63a)