rust-lang/rust · error

must be at least one segment

Error message

must be at least one segment

What it means

delegation/generics.rs:326 calls delegation.path.segments.last().expect("must be at least one segment") when collecting child generic args. A delegation path is required to have at least one path segment; an empty path is malformed and cannot name a callee.

Solutions

  1. File a rustc ICE with the minimized delegation source if triggered by real code.
  2. Ensure the delegation path names a real item (e.g. `reuse path::to::fn;`).
  3. If constructing the AST, always give the delegation path at least one segment.
  4. Bisect nightly regressions with cargo bisect-rustc.
Defensive patterns

Strategy: validation

Validate before calling

fn delegation_path_ok(delegation: &Delegation) -> bool {
    !delegation.path.segments.is_empty()
}

Prevention

When it happens

Trigger: A delegation (`reuse`) item whose path has zero segments, or a frontend/syntax-extension bug producing an empty delegation path.

Common situations: Malformed unstable delegation syntax; programmatic AST construction with an empty path; a parser regression.

Related errors


AI-assisted analysis of rust-lang/rust@7088e4b63a (2026-08-10). Data as JSON: /api/errors/bbb37a4030e94272. Report an issue: GitHub.

Appendix: source

Thrown at compiler/rustc_ast_lowering/src/delegation/generics.rs:326

                    .unwrap_or(ParentSegmentArgs::NotSpecified)
            } else {
                ParentSegmentArgs::Invalid
            }
        } else {
            ParentSegmentArgs::Invalid
        };

        Ok(GenericsResolution {
            parent_args,
            sig_parent_params,
            qself_is_none,
            qself_is_infer,
            free_to_trait_delegation,
            generate_self: free_to_trait_delegation && (qself_is_none || qself_is_infer),
            trait_impl: matches!(delegation_parent_kind, DefKind::Impl { of_trait: true }),
            sig_child_params: &tcx.generics_of(sig_id).own_params,
            child_args: self.get_user_args(
                delegation.path.segments.last().expect("must be at least one segment"),
            ),
        })
    }

    fn get_user_args<'a>(&self, segment: &'a PathSegment) -> Option<&'a AngleBracketedArgs> {
        let Some(args) = &segment.args else { return None };
        let GenericArgs::AngleBracketed(args) = args else {
            self.tcx().dcx().span_delayed_bug(
                segment.span(),
                "expected angle-bracketed generic args in delegation segment",
            );

            return None;
        };

        // Treat empty args `reuse foo::<> as bar` as `reuse foo as bar`,
        // the same logic applied when we call function `fn f<T>(t: T)`
        // like that `f::<>(())`, in HIR no `<>` will be generated.

View on GitHub (pinned to 7088e4b63a)