rust-lang/rust · critical
until inherent methods are supported
Error message
until inherent methods are supported
What it means
unreachable! in delegation lowering when the resolved callee path is a hir::QPath::TypeRelative. The delegation feature currently only supports path-resolved (Resolved) callees — delegating through inherent methods on a type (TypeRelative) is intentionally unsupported, so this branch is marked unreachable until that support lands.
Source
Thrown at compiler/rustc_ast_lowering/src/delegation/mod.rs:416
let ty = match generics.self_ty_propagation_kind {
Some(hir::DelegationSelfTyPropagationKind::SelfParam) => {
let self_param = generics.parent.generics.find_self_param();
let path = self.create_generic_arg_path(self_param);
let kind = hir::TyKind::Path(path);
let ty = match ty {
Some(ty) => hir::Ty { kind, ..ty.clone() },
None => hir::Ty { kind, hir_id: self.next_id(), span },
};
Some(&*self.arena.alloc(ty))
}
_ => ty,
};
hir::QPath::Resolved(ty, self.arena.alloc(new_path))
}
hir::QPath::TypeRelative(..) => unreachable!("until inherent methods are supported"),
};
if let Some(hir::DelegationSelfTyPropagationKind::SelfTy(id)) =
generics.self_ty_propagation_kind.as_mut()
{
*id = match new_path {
hir::QPath::Resolved(ty, _) => {
ty.expect("must contain self type as `SelfTy` propagation kind is specified")
}
hir::QPath::TypeRelative(ty, _) => ty,
}
.hir_id;
}
let callee_path = self.arena.alloc(self.mk_expr(hir::ExprKind::Path(new_path), span));
let args = self.arena.alloc_from_iter(args);
let call = self.mk_expr(hir::ExprKind::Call(callee_path, args), span);
View on GitHub (pinned to 22057b88b0)
Solutions
- Restructure the delegation so the callee resolves to a fully-qualified path: `reuse Trait::method as ...;` instead of an inherent or type-relative form.
- If you need inherent-method delegation, track/follow the rust-lang/delegation RFC and wait for inherent-method support before using that form.
- Replace `reuse` with an explicit forwarding fn in the meantime.
- Report the use case on the delegation tracking issue so it informs the inherent-method support design.
Example fix
// before (type-relative path — unsupported by delegation)
#![feature(delegation)]
impl S { reuse S::inherent_method as alias; }
// after — delegate via a trait path or write a forwarder manually
impl S {
fn alias(&self) { self.inherent_method() }
} Defensive patterns
Strategy: fallback
Validate before calling
// QPath::TypeRelative in a delegation target is explicitly unsupported
// (inherent methods on type-relative paths). Detect the shape statically:
fn is_typ_relative(qpath: &hir::QPath<'_>) -> bool {
matches!(qpath, hir::QPath::TypeRelative(..))
}
if is_typ_relative(&delegation_qpath) {
return Err("delegation to an inherent method via a type-relative path is not yet supported");
} Type guard
fn delegation_target_supported(qpath: &hir::QPath<'_>) -> bool {
matches!(qpath, hir::QPath::Resolved(..))
} Try / catch
let lowered = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| lower_delegation_qpath(qpath)));
match lowered {
Ok(p) => p,
Err(_) => {
// Fallback: rewrite the delegation as an explicit method call.
return synthesize_explicit_method_call(&delegation);
}
} Prevention
- Do not delegate to inherent methods reached through a `<Type as Trait>::method` or `Type::method` type-relative path; delegation currently only supports Resolved paths.
- Route inherent-method delegation through a trait: define a trait with the method, implement it, and delegate to the trait method instead.
- As a fallback, replace the `delegate` item with a hand-written forwarding fn whose body calls `self.inherent_method(...)` — functionally equivalent until inherent delegation stabilizes.
- Track the nightly feature flag `delegation` and re-test the unsupported case each toolchain bump; the unreachable! may be lifted.
When it happens
Trigger: Triggered with #![feature(delegation)] when a `reuse` item resolves to a type-relative path such as `reuse <Ty>::method` or `reuse Ty::method` where the lowering yields QPath::TypeRelative rather than QPath::Resolved. Indicates an unsupported (but syntactically accepted) delegation form reached lowering.
Common situations: Delegating through an inherent method or a type-relative path on nightly with `delegation`; this is a known unimplemented case. Users on stable never see it. Often hit when porting trait-delegation patterns that rely on inherent methods.
Related errors
- `Self` generic param is not found while expected
- must be at least one segment
- must contain self type as `SelfTy` propagation kind is speci
- arg must exist for infer
- processing delegation
AI-assisted analysis of rust-lang/rust@22057b88b0 (2026-08-03).
Data as JSON: /data/errors/b40f7b87b48844b0.json.
Report an issue: GitHub.