Skip to content

E4xxx: Generic and trait errors ​

This page is generated by scripts/docs/gen-error-code-docs.py from the define_codes! registry in src/util/diagnostic/codes/ and locales/en.json. Do not edit it by hand. Change the wording in locales/*.json, change the code table in define_codes!, then rerun python scripts/docs/gen-error-code-docs.py.

Errors related to generic constraints, the trait system, and constant evaluation.

This family holds 15 codes, all registered in the define_codes! registry, with the category Generic. See the error code index for the complete inventory.

Code Overview ​

CodeNameCategoryspan exemptTemplateEmission sites
E4001Generic constraint violationGenericNotype '{type}' does not satisfy trait constraint '{trait}'✅ 1 site
E4002Trait not foundGenericNotrait '{trait}' not found⚠ Not yet emitted
E4003Trait implementation missingGenericNotype '{type}' is missing implementation for trait '{trait}'⚠ Not yet emitted
E4004Conflicting trait implementationsGenericNoConflicting implementations for trait '{trait}'⚠ Not yet emitted
E4005Associated type not foundGenericNoAssociated type '{assoc_type}' not found in '{container}'⚠ Not yet emitted
E4010Constant division by zeroGenericNoDivision by zero in constant expression✅ 3 sites
E4011Constant overflowGenericNoConstant expression overflow✅ 5 sites
E4012Constant recursion too deepGenericNoConstant evaluation exceeds the maximum recursion depth {limit}✅ 1 site
E4014Constant evaluation failedGenericYesUnable to evaluate constant expression: {reason}✅ 11 sites
E4018Refinement predicate violationGenericYesRefinement predicate violated: {constraint}{counterexample}✅ 6 sites
E4019Type equality does not holdGenericNoType equality does not hold: expected {expected}, found {found}✅ 1 site
E4020Proof function requiredGenericNoA proof function is required to verify the constraint✅ 2 sites
E4021Loop termination cannot be automatically provenGenericNoLoop termination cannot be automatically proven: no valid decreasing metric was found✅ 1 site
E4022Measure does not holdGenericNoMeasure does not hold: this call site cannot prove that the measure strictly decreases Counterexample: {counterexample}✅ 1 site
E4023Cannot be proven within the kernelGenericNoCannot prove: {proposition} ({reason})✅ 1 site

Code Details ​

E4001: Generic constraint violation ​

  • Category: Generic
  • span exempt: No
  • Constructor: ErrorCodeDefinition::trait_bound_not_satisfied(type_, trait_)
  • Template: type '{type}' does not satisfy trait constraint '{trait}'
  • Message: type does not satisfy generic constraint
  • Help: ensure the type satisfies all required trait bounds
  • Emission sites: src/frontend/core/sema/inference/bounds.rs:64
  • Source comment name: 类型不满足特质约束

E4002: Trait not found ​

  • Category: Generic
  • span exempt: No
  • Constructor: ErrorCodeDefinition::trait_not_found(trait_)
  • Template: trait '{trait}' not found
  • Message: referenced trait does not exist
  • Help: check the trait name or import the correct trait
  • Emission site: ⚠ Not yet emitted (the registry retains the code, but non-test code never calls it, so users cannot trigger it)
  • Source comment name: 特质未找到

E4003: Trait implementation missing ​

  • Category: Generic
  • span exempt: No
  • Constructor: ErrorCodeDefinition::missing_trait_impl(trait_, type_)
  • Template: type '{type}' is missing implementation for trait '{trait}'
  • Message: type does not implement required trait
  • Help: add a trait implementation for this type
  • Emission site: ⚠ Not yet emitted (the registry retains the code, but non-test code never calls it, so users cannot trigger it)
  • Source comment name: 特质实现缺失

E4004: Conflicting trait implementations ​

  • Category: Generic
  • span exempt: No
  • Constructor: ErrorCodeDefinition::conflicting_trait_impls(trait_)
  • Template: Conflicting implementations for trait '{trait}'
  • Message: Conflicting trait implementations
  • Help: Resolve the conflicting implementations
  • Emission site: ⚠ Not yet emitted (the registry retains the code, but non-test code never calls it, so users cannot trigger it)
  • Source comment name: 特质实现冲突

E4005: Associated type not found ​

  • Category: Generic
  • span exempt: No
  • Constructor: ErrorCodeDefinition::associated_type_not_found(assoc_type, container)
  • Template: Associated type '{assoc_type}' not found in '{container}'
  • Message: The referenced associated type does not exist in the container
  • Help: Check the associated type name and container definition
  • Emission site: ⚠ Not yet emitted (the registry retains the code, but non-test code never calls it, so users cannot trigger it)
  • Source comment name: 关联类型未找到

E4010: Constant division by zero ​

  • Category: Generic
  • span exempt: No
  • Constructor: ErrorCodeDefinition::const_division_by_zero()
  • Template: Division by zero in constant expression
  • Help: Ensure that the divisor in the constant expression is not zero.
  • Emission sites: src/frontend/core/types/eval/const_eval.rs:704, src/frontend/core/types/eval/const_eval.rs:711, src/frontend/core/types/eval/const_eval.rs:716
  • Source comment name: 常量除零

E4011: Constant overflow ​

  • Category: Generic
  • span exempt: No
  • Constructor: ErrorCodeDefinition::const_overflow()
  • Template: Constant expression overflow
  • Help: The result of the constant expression exceeds the range of the type.
  • Emission sites: src/frontend/core/types/eval/const_eval.rs:735, src/frontend/core/types/eval/const_eval.rs:740, src/frontend/core/types/eval/const_eval.rs:745 and 5 more sites
  • Source comment name: 常量溢出

E4012: Constant recursion too deep ​

  • Category: Generic
  • span exempt: No
  • Constructor: ErrorCodeDefinition::const_recursion_too_deep(limit)
  • Template: Constant evaluation exceeds the maximum recursion depth {limit}
  • Help: Simplify the constant expression to reduce recursion.
  • Emission sites: src/frontend/core/types/eval/const_eval.rs:912
  • Source comment name: 常量递归过深

E4014: Constant evaluation failed ​

  • Category: Generic
  • span exempt: Yes
  • Constructor: ErrorCodeDefinition::const_eval_failed(reason)
  • Template: Unable to evaluate constant expression: {reason}
  • Help: Ensure that the expression can be evaluated at compile-time.
  • Emission sites: src/frontend/core/types/eval/const_eval.rs:643, src/frontend/core/types/eval/const_eval.rs:647, src/frontend/core/types/eval/const_eval.rs:668 and 11 more sites
  • Source comment name: 常量求值失败

E4018: Refinement predicate violation ​

  • Category: Generic
  • span exempt: Yes
  • Constructor: ErrorCodeDefinition::refinement_violated(constraint)
  • Template: Refinement predicate violated: {constraint}{counterexample}
  • Message: Refinement type constraint falsified
  • Help: Predicate falsified — there exists an assignment that makes the constraint false. Please check variable values or relax the constraint.
  • Emission sites: src/frontend/proof_execution.rs:116, src/frontend/proof_execution.rs:128, src/frontend/proof_execution.rs:243 and 6 more sites
  • Source comment name: 精化谓词违反

E4019: Type equality does not hold ​

  • Category: Generic
  • span exempt: No
  • Constructor: ErrorCodeDefinition::type_mismatch_in_proof(expected, found)
  • Template: Type equality does not hold: expected {expected}, found {found}
  • Message: Type equality falsified within the proof pipeline
  • Help: Check the type computation of the components or provide a proof function.
  • Emission sites: src/frontend/core/sema/proof/verdict.rs:229
  • Source comment name: 类型等式不成立(证明管道内)

E4020: Proof function required ​

  • Category: Generic
  • span exempt: No
  • Constructor: ErrorCodeDefinition::proof_function_required()
  • Template: A proof function is required to verify the constraint
  • Message: The constraint cannot be proven at compile-time; a proof function must be provided
  • Help: Add a proof function or provide a runtime check
  • Emission sites: src/frontend/core/sema/checker/refinement.rs:972, src/frontend/core/sema/proof/verdict.rs:397
  • Source comment name: 需要证明函数来验证约束

E4021: Loop termination cannot be automatically proven ​

  • Category: Generic
  • span exempt: No
  • Constructor: ErrorCodeDefinition::loop_termination_unproven()
  • Template: Loop termination cannot be automatically proven: no valid decreasing metric was found
  • Message: The compiler cannot synthesize a decreasing metric for this loop and cannot automatically prove its termination
  • Help: This is a coverage boundary of the compiler's automatic reasoning, not a program error. Rewrite the loop with an explicit decreasing variable (for example, a bounded counter that decreases by one each iteration), or refer to RFC-027 §7 for the metric strategies and coverage scope.
  • Emission sites: src/frontend/core/sema/proof/verdict.rs:393
  • Source comment name: 循环终止性无法自动证明

E4022: Measure does not hold ​

  • Category: Generic
  • span exempt: No
  • Constructor: ErrorCodeDefinition::measure_not_decreasing(counterexample)
  • Template: Measure does not hold: this call site cannot prove that the measure strictly decreases Counterexample: {counterexample}
  • Message: The measure at this recursive call site does not strictly decrease, so recursion termination cannot be proved (a counterexample is attached)
  • Help: This is a termination obligation of refinement type propositions: for recursive functions annotated with the Terminates measure, every recursive call site must prove that the measure strictly decreases. The counterexample provides a set of values for which the decrease does not hold. Please check whether the measure is appropriate, or add branch guards so that the decrease holds on recursive paths. See RFC-027a.
  • Emission sites: src/frontend/core/sema/proof/verdict.rs:214
  • Source comment name: 测度不成立(RFC-027a §义务生成)

E4023: Cannot be proven within the kernel ​

  • Category: Generic
  • span exempt: No
  • Constructor: ErrorCodeDefinition::unproven_general(proposition, reason)
  • Template: Cannot prove: {proposition} ({reason})
  • Message: The compiler could not prove this obligation within the given resources and inference rules (this does not mean the proposition is false)
  • Help: This is a boundary of the compiler's reasoning, not a program error. Supply compile-time-known arguments or evidence, or rewrite the obligation into a form the kernel can decide (for example, give the type argument's value explicitly). See RFC-027 Section 12.3.
  • Emission sites: src/frontend/core/sema/proof/verdict.rs:372
  • Source comment name: 一般性「无法证明」(t64 / RFC-027 §12.3)