{"record":{"id":"c8c6e1cc85717210","repo":"rust-lang/rust","slug":"item-kind-cannot-be-converted","errorCode":null,"errorMessage":"Item kind `{:?}` cannot be converted","messagePattern":"Item kind `(.+?)` cannot be converted","errorType":"validation","errorClass":"bridge::Error","httpStatus":null,"severity":"error","filePath":"compiler/rustc_public/src/mir/mono.rs","lineNumber":237,"sourceCode":"                Ok(context.mono_instance(def_id))\n            } else {\n                Err(bridge::Error::new(\"Item requires monomorphization\".to_string()))\n            }\n        })\n    }\n}\n\n/// Try to convert an instance into a crate item.\n/// Only user defined instances can be converted.\nimpl TryFrom<Instance> for CrateItem {\n    type Error = crate::Error;\n\n    fn try_from(value: Instance) -> Result<Self, Self::Error> {\n        with(|context| {\n            if value.kind == InstanceKind::Item && context.has_body(value.def.def_id()) {\n                Ok(CrateItem(context.instance_def_id(value.def)))\n            } else {\n                Err(bridge::Error::new(format!(\"Item kind `{:?}` cannot be converted\", value.kind)))\n            }\n        })\n    }\n}\n\nimpl From<Instance> for MonoItem {\n    fn from(value: Instance) -> Self {\n        MonoItem::Fn(value)\n    }\n}\n\nimpl From<StaticDef> for MonoItem {\n    fn from(value: StaticDef) -> Self {\n        MonoItem::Static(value)\n    }\n}\n\nimpl From<StaticDef> for CrateItem {","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/compiler/rustc_public/src/mir/mono.rs#L219-L255","documentation":"Thrown by `impl TryFrom<Instance> for CrateItem` (mono.rs:234) when converting an `Instance` back into a `CrateItem`. Only `InstanceKind::Item` instances that also have a body convert; intrinsics, virtual functions, LLVM intrinsics, and compiler shims are rejected because they do not map to a user-defined crate item.","triggerScenarios":"Calling `CrateItem::try_from(instance)` / `instance.try_into()` on an instance whose `kind` is `Intrinsic`, `LlvmIntrinsic`, `Virtual`, or `Shim`, or an `Item` instance that has no MIR body.","commonSituations":"Tooling that iterates `MonoItem`s and converts every instance to a `CrateItem`; handling intrinsic fallback bodies; converting vtable-resolved virtual instances obtained from a dispatch table.","solutions":["Guard on `instance.kind == InstanceKind::Item` (and `instance.has_body()`) before converting.","For intrinsics, use `instance.intrinsic_name()` and handle the intrinsic path separately.","Skip shims/virtuals when your consumer only deals with source-level items."],"exampleFix":"// before\nlet item: CrateItem = instance.try_into()?;\n\n// after\nlet item: CrateItem = match instance.kind {\n    InstanceKind::Item if instance.has_body() => instance.try_into()?,\n    _ => continue, // skip non-convertible instances\n};","handlingStrategy":"type-guard","validationCode":null,"typeGuard":"fn is_user_item_with_body(inst: &Instance) -> bool {\n    matches!(inst.kind, InstanceKind::Item) && inst.has_body()\n}","tryCatchPattern":"match CrateItem::try_from(instance) {\n    Ok(item) => item,\n    Err(_) => {\n        // intrinsic/shim/virtual: handle separately or skip\n        continue;\n    }\n}","preventionTips":["Check InstanceKind before converting; only Item is convertible.","Use has_body() to also rule out bodyless item instances."],"tags":["rustc-public","instance","crate-item","mir"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}