Repository: carbon-language/carbon-lang
File: toolchain/check/impl_validation.cpp (C++)

Code before:
    constexpr auto operator==(const InterfaceToImport& rhs) const
        -> bool = default;
    constexpr auto operator<=>(const InterfaceToImport& rhs) const -> auto {
      if (ir_id != rhs.ir_id) {
        return ir_id.index <=> rhs.ir_id.index;
      }
      return interface_id.index <=> rhs.interface_id.index;
    }
  };

  llvm::SmallVector<InterfaceToImport> interfaces_to_import;
  for (const auto& impl : context.impls().values()) {
    if (impl.witness_id == SemIR::ErrorInst::InstId) {
      continue;
    }
    auto impl_import_ir_id = GetIRId(context, impl.first_owning_decl_id);
    if (impl_import_ir_id.has_value()) {
      // Only import `impl`s of interfaces for which there is a local `impl` of
      // that that interface.
      continue;
    }

    auto interface_id = impl.interface.interface_id;
    const auto& interface = context.interfaces().Get(interface_id);
    auto interface_owning_decl_id = interface.first_owning_decl_id;
    if (!interface_owning_decl_id.has_value()) {
      continue;
    }
    const auto& import_ir_inst =
        GetCanonicalImportIRInst(context, interface.first_owning_decl_id);
    if (!import_ir_inst.ir_id().has_value()) {
      continue;
    }
    interfaces_to_import.push_back(
        {.ir_id = import_ir_inst.ir_id(),
         .interface_id =
             context.import_irs()
                 .Get(import_ir_inst.ir_id())
                 .sem_ir->insts()
                 .GetAs<SemIR::InterfaceDecl>(import_ir_inst.inst_id())
                 .interface_id});
  }

  llvm::sort(interfaces_to_import);
  llvm::unique(interfaces_to_import);

  struct ImplToImport {
    SemIR::ImportIRId ir_id;
    SemIR::ImplId import_impl_id;

    constexpr auto operator==(const ImplToImport& rhs) const -> bool = default;

Review comment (suggestion):
```suggestion
    if (!interface.first_owning_decl_id.has_value()) {
```

Code after:
    constexpr auto operator==(const InterfaceToImport& rhs) const
        -> bool = default;
    constexpr auto operator<=>(const InterfaceToImport& rhs) const -> auto {
      if (ir_id != rhs.ir_id) {
        return ir_id.index <=> rhs.ir_id.index;
      }
      return interface_id.index <=> rhs.interface_id.index;
    }
  };

  llvm::SmallVector<InterfaceToImport> interfaces_to_import;
  for (const auto& impl : context.impls().values()) {
    if (impl.witness_id == SemIR::ErrorInst::InstId) {
      continue;
    }
    auto impl_import_ir_id = GetIRId(context, impl.first_owning_decl_id);
    if (impl_import_ir_id.has_value()) {
      // Only import `impl`s of interfaces for which there is a local `impl` of
      // that that interface.
      continue;
    }

    auto interface_id = impl.interface.interface_id;
    const auto& interface = context.interfaces().Get(interface_id);
    if (!interface.first_owning_decl_id.has_value()) {
      continue;
    }
    const auto& import_ir_inst =
        GetCanonicalImportIRInst(context, interface.first_owning_decl_id);
    if (!import_ir_inst.ir_id().has_value()) {
      continue;
    }
    interfaces_to_import.push_back(
        {.ir_id = import_ir_inst.ir_id(),
         .interface_id =
             context.import_irs()
                 .Get(import_ir_inst.ir_id())
                 .sem_ir->insts()
                 .GetAs<SemIR::InterfaceDecl>(import_ir_inst.inst_id())
                 .interface_id});
  }

  llvm::sort(interfaces_to_import);
  llvm::unique(interfaces_to_import);

  struct ImplToImport {
    SemIR::ImportIRId ir_id;
    SemIR::ImplId import_impl_id;

    constexpr auto operator==(const ImplToImport& rhs) const -> bool = default;
    constexpr auto operator<=>(const ImplToImport& rhs) const -> auto {