# PR #26034 完整报告

- 仓库：`sgl-project/sglang`
- 标题：Fix SMG service discovery Clippy lint
- 合并时间：2026-05-22 10:51
- 原文链接：http://prhub.com.cn/sgl-project/sglang/pull/26034

---

## 执行摘要
PR #26034 修复了 issue #25294 引入的 IGW 模式选择器条件导致的 Clippy lint 失败。通过合并嵌套的 if 条件为一个复合布尔表达式，消除了 Clippy 警告，同时保持功能不变。

## 功能与动机
PR #25294 新增的 IGW 模式选择器条件引发了 Clippy lint 失败，如 CI 运行结果所示。此 PR 旨在修复该问题，确保 `cargo clippy --all-targets --all-features -- -D warnings` 检查通过。

## 实现拆解

1. **修改条件表达式**：在文件 `sgl-model-gateway/src/service_discovery.rs` 中，`PodInfo::should_include` 函数被修改。
2. **合并嵌套 if**：原来有两个嵌套的 if 语句用于检查 PD 模式下选择器是否为空，现在合并为一个复合条件：`config.prefill_selector.is_empty() && config.decode_selector.is_empty() && (!config.igw_mode || config.selector.is_empty())`。
3. **消除 Clippy 警告**：合并后消除了嵌套 if 导致的 Clippy lint 警告。
4. **功能等价**：行为逻辑完全等价，无任何功能变更。

### `sgl-model-gateway/src/service_discovery.rs`

修改了 should_include 函数中的条件逻辑，修复 Clippy lint 警告。

```rust
// sgl-model-gateway/src/service_discovery.rs
impl PodInfo {
    pub fn should_include(pod: &Pod, config: &ServiceDiscoveryConfig) -> bool {
        if config.pd_mode {
            // 原来嵌套的 if 合并为一个复合条件：当 prefill 和 decode 都为空
            // 且（非 IGW 模式 或 IGW 模式下 selector 为空）时发出警告并排除
            if config.prefill_selector.is_empty()
                && config.decode_selector.is_empty()
                && (!config.igw_mode || config.selector.is_empty())
            {
                warn!("PD mode enabled but both prefill_selector and decode_selector are empty");
                return false;
            }
            let matches_pd = Self::matches_selector(pod, &config.prefill_selector)
                || Self::matches_selector(pod, &config.decode_selector);
            // 在 IGW 模式下，也通过 selector 发现常规 worker
            let matches_regular = config.igw_mode
                && !config.selector.is_empty()
                && Self::matches_selector(pod, &config.selector);
            matches_pd || matches_regular
        } else {
            if config.selector.is_empty() {
                warn!("Regular mode enabled but selector is empty");
                return false;
            }
            Self::matches_selector(pod, &config.selector)
        }
    }
}

```

## 评论区精华
无 review 评论。

## 风险与影响
- **低风险**：变更仅涉及 Clippy lint 修复，逻辑等价性通过 CI 验证。
- **影响范围**：仅限 `sgl-model-gateway` 模块的 Rust 源码，对用户无感知。

## 关联脉络
- 关联 PR #25294：本 PR 修复了该 PR 引入的 Clippy lint 问题。