{"record":{"id":"f639becd91528a2b","repo":"rust-lang/rust","slug":"can-t-have-a-type-error-relating-to-itself","errorCode":null,"errorMessage":"Can't have a type error relating to itself","messagePattern":"Can't have a type error relating to itself","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"compiler/rustc_borrowck/src/polonius/liveness_constraints.rs","lineNumber":26,"sourceCode":"\nuse super::{ConstraintDirection, PoloniusContext};\nuse crate::universal_regions::UniversalRegions;\n\nimpl PoloniusContext {\n    /// Record the variance of each region contained within the given value.\n    pub(crate) fn record_live_region_variance<'tcx>(\n        &mut self,\n        tcx: TyCtxt<'tcx>,\n        universal_regions: &UniversalRegions<'tcx>,\n        value: impl TypeVisitable<TyCtxt<'tcx>> + Relate<TyCtxt<'tcx>>,\n    ) {\n        let mut extractor = VarianceExtractor {\n            tcx,\n            ambient_variance: ty::Variance::Covariant,\n            directions: &mut self.live_region_variances,\n            universal_regions,\n        };\n        extractor.relate(value, value).expect(\"Can't have a type error relating to itself\");\n    }\n}\n\n/// Extracts variances for regions contained within types. Follows the same structure as\n/// `rustc_infer`'s `Generalizer`: we try to relate a type with itself to track and extract the\n/// variances of regions.\nstruct VarianceExtractor<'a, 'tcx> {\n    tcx: TyCtxt<'tcx>,\n    ambient_variance: ty::Variance,\n    directions: &'a mut BTreeMap<RegionVid, ConstraintDirection>,\n    universal_regions: &'a UniversalRegions<'tcx>,\n}\n\nimpl<'tcx> VarianceExtractor<'_, 'tcx> {\n    fn record_variance(&mut self, region: ty::Region<'tcx>, variance: ty::Variance) {\n        // We're only interested in the variance of vars and free regions.\n        //\n        // Note: even if we currently bail for two cases of unexpected region kinds here, missing","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/rust-lang/rust/blob/7088e4b63a9516ebfbfe2ab2d999cf01a528ac14/compiler/rustc_borrowck/src/polonius/liveness_constraints.rs#L8-L44","documentation":"This fires inside Polonius's `record_live_region_variance`, which extracts the variance (co/contra/invariant) of each region inside a type by relating the type with itself (`extractor.relate(value, value)`). Relating a type with itself should never produce a type error — identical types are always compatible. If it does, the compiler considers this a logic error in how the type or its regions were constructed.","triggerScenarios":"During Polonius analysis (`-Zpolonius=next`), when the variance extractor encounters a type that cannot be related to itself. This implies a malformed or internally inconsistent type — e.g., a type with opaque/hidden regions, inference variables that escaped their scope, or a type-rewrite bug in the MIR type-check pass feeding bad data to polonius.","commonSituations":"Nightly Rust with `-Zpolonius=next` on code using complex generics, associated types, opaque types, or GATs where a type's internal structure is subtly inconsistent. This is a compiler soundness-adjacent invariant; the panic indicates the variance data would be wrong, so the compiler aborts rather than emit incorrect borrow-check results.","solutions":["Remove `-Zpolonius=next` and use the default NLL borrow checker; this code path is exclusive to polonius.","Minimize the reproduction and file a bug with the type that triggers the self-relation error.","Update to the latest nightly; polonius variance extraction is under active development.","If contributing to rustc, inspect the `VarianceExtractor` in `liveness_constraints.rs` — the `relate` call may need to handle additional region kinds that are currently unexpected."],"exampleFix":"// before (complex GAT + opaque, triggers polonius variance ICE)\n#![feature(polonius)]\ntrait L { type Item<T>; }\nfn f<T>(x: <() as L>::Item<T>) { /* ... */ }\n\n// after (avoid polonius for this crate; remove the flag)\n// RUSTFLAGS='' cargo build  (uses default NLL)","handlingStrategy":"fallback","validationCode":"// This is a compiler-internal invariant. No user-level validation possible.\n// The fallback is to not use -Zpolonius=next:\n// unset RUSTFLAGS or ensure -Zpolonius=next is not present","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Don't use -Zpolonius=next on crates with complex GAT/opaque type interactions until polonius stabilizes.","Maintain a known-good nightly version for polonius testing.","Report the type that triggers self-relation failure to help fix the variance extractor.","Use default NLL borrow checker for production builds."],"tags":["rustc","borrowck","polonius","ice","variance","nightly","compiler-internal"],"backgroundTag":null,"analyzedSha":"7088e4b63a9516ebfbfe2ab2d999cf01a528ac14","analyzedAt":"2026-08-10T14:17:03.603Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}