Diagnostic and cause
LinkProtocol implementation violates the orphan rule
- Family
- topaz
- Phase
- check
- Code
TPZ5520
Cause and conditions
Implementing the foreign Show protocol for the built-in int type is rejected with TPZ5520. Define a conforming record, enum, or newtype in the implementation's module.
Related rule: Protocol implementation violates the orphan ruleResponse
Place the implementation with the owning declaration, or define a local nominal wrapper for the external type.
Source evidence
- compiler/crates/topaz_diag/src/explain.rs at
151141d7bb44· 808-817 - compiler/crates/topaz_self_frontend/topaz/checker/protocols_methods.tpz at
151141d7bb44· 564-564 - compiler/crates/topaz_self_frontend/topaz/checker/protocols_methods.tpz at
151141d7bb44· 540-572
Compiler phase: check.
Compiler explanation: A protocol implementation tries to connect a protocol and type that this module does not own.
Message templates are Pending. The explanation above is not an observed CLI message.
Observed for the candidate in Topaz 5.21.3. Execution
- error[TPZ5520]: cannot implement foreign protocol
Showfor foreign typeint(orphan rule §4.2): the protocol or the type must be defined in this module
Implementing the foreign Show protocol for the built-in int type is rejected with TPZ5520. Define a conforming record, enum, or newtype in the implementation's module.
Protocol implementation violates the orphan rule
Implementing the foreign Show protocol for the built-in int type is rejected with TPZ5520. Define a conforming record, enum, or newtype in the implementation's module.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/protocols_methods.tpz at
151141d7bb44· 540-572
Response
LinkPlace the implementation with the owning declaration, or define a local nominal wrapper for the external type.
Reproduction and verification
LinkRejected program
Linkimpl Show<int> {function show(self) -> string { "value" }}
No stdout.
Expected result
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/protocols_methods.tpz at
151141d7bb44· 540-572
Repaired program
Linkrecord Item { value: int }impl Show<Item> {function show(value: Item) -> string { "item" }}
Expected result
Expected result
Checking accepts the program. Exit code 0.
Source evidence
- compiler/crates/topaz_self_frontend/topaz/checker/protocols_methods.tpz at
151141d7bb44· 540-572