{"id":"bbb37a4030e94272","repo":"rust-lang/rust","slug":"must-be-at-least-one-segment","errorCode":null,"errorMessage":"must be at least one segment","messagePattern":"must be at least one segment","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"compiler/rustc_ast_lowering/src/delegation/generics.rs","lineNumber":326,"sourceCode":"                    .unwrap_or(ParentSegmentArgs::NotSpecified)\n            } else {\n                ParentSegmentArgs::Invalid\n            }\n        } else {\n            ParentSegmentArgs::Invalid\n        };\n\n        Ok(GenericsResolution {\n            parent_args,\n            sig_parent_params,\n            qself_is_none,\n            qself_is_infer,\n            free_to_trait_delegation,\n            generate_self: free_to_trait_delegation && (qself_is_none || qself_is_infer),\n            trait_impl: matches!(delegation_parent_kind, DefKind::Impl { of_trait: true }),\n            sig_child_params: &tcx.generics_of(sig_id).own_params,\n            child_args: self.get_user_args(\n                delegation.path.segments.last().expect(\"must be at least one segment\"),\n            ),\n        })\n    }\n\n    fn get_user_args<'a>(&self, segment: &'a PathSegment) -> Option<&'a AngleBracketedArgs> {\n        let Some(args) = &segment.args else { return None };\n        let GenericArgs::AngleBracketed(args) = args else {\n            self.tcx().dcx().span_delayed_bug(\n                segment.span(),\n                \"expected angle-bracketed generic args in delegation segment\",\n            );\n\n            return None;\n        };\n\n        // Treat empty args `reuse foo::<> as bar` as `reuse foo as bar`,\n        // the same logic applied when we call function `fn f<T>(t: T)`\n        // like that `f::<>(())`, in HIR no `<>` will be generated.","sourceCodeStart":308,"sourceCodeEnd":344,"githubUrl":"https://github.com/rust-lang/rust/blob/22057b88b091743bc0fd8d592a9264f0a6951403/compiler/rustc_ast_lowering/src/delegation/generics.rs#L308-L344","documentation":"expect panic in delegation generics resolution when calling delegation.path.segments.last(). The path is assumed to always have at least one segment (any path through the resolver yields a final segment for the method name), so .last() is wrapped in expect(\"must be at least one segment\"). Hitting it means the delegation's callee path arrived empty — an upstream invariant violation in path construction.","triggerScenarios":"Triggered only with #![feature(delegation)] when a reuse/delegation item references a callee path with zero segments, e.g. `reuse  as foo;` or a path produced by a proc-macro that emits an empty Path. Resolver/AST invariants normally forbid empty paths, so this implies a malformed AST.","commonSituations":"Nightly regressions in the delegation resolver; proc-macros generating `reuse` items with empty or malformed paths; experimental `delegation` code where a macro erases the path. Not reachable on stable Rust.","solutions":["Report the ICE to rust-lang/rust, attaching the delegation macro invocation and the nightly commit.","If using a proc-macro to emit `reuse`, verify each generated path has at least one segment (e.g. `Trait::method`).","Rewrite the delegation as a direct path literal `reuse Foo::bar as baz;` to avoid the empty-path case.","Disable the `delegation` feature temporarily and use manual forwarding methods."],"exampleFix":"// before (macro emits a path with no segments)\nreuse  as new_name;\n// after\nreuse Foo::method as new_name;","handlingStrategy":"validation","validationCode":"// delegation path must have at least one segment; an empty path crashes\n// path.segments.last().expect(...). Validate before resolution:\nfn nonempty_path(path: &ast::Path) -> Result<&[ast::PathSegment]> {\n    if path.segments.is_empty() {\n        Err(\"delegation path must have at least one segment\")\n    } else {\n        Ok(&path.segments)\n    }\n}\nlet segments = nonempty_path(&delegation.path)?;","typeGuard":"fn has_segments(path: &ast::Path) -> bool {\n    !path.segments.is_empty()\n}","tryCatchPattern":"let last = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| delegation.path.segments.last().expect(\"must be at least one segment\")));\nmatch last {\n    Some(seg) => seg,\n    None => return Err(\"delegation path is empty\"),\n}","preventionTips":["Always specify a concrete target in `delegate`/`pub delegate` — never an empty path or a path that resolves to nothing.","In proc-macros generating delegation items, assert the synthesized path has at least one segment and a valid span before emitting the item.","Avoid delegating to macro-expanded paths that may expand to nothing; expand the path first and check its segment count.","Lint for `delegate {}` blocks whose body contains an item with an empty/placeholder path before codegen."],"tags":["rustc","ice","delegation","path","resolver","nightly"],"analyzedSha":"22057b88b091743bc0fd8d592a9264f0a6951403","analyzedAt":"2026-08-03T08:09:25.915Z","schemaVersion":2}