Repository: astral-sh/ruff
File: crates/ty_python_semantic/src/types/signatures.rs (Rust)

Code before:
        }

        match type_mapping {
            TypeMapping::Specialization(specialization) => {
                Self::from_overloads(self.overloads.iter().flat_map(|signature| {
                    if let Some((prefix, paramspec)) =
                        signature.parameters.find_paramspec_from_args_kwargs(db)
                        && let Some(value) = specialization.get(db, paramspec)
                        && let Some(result) = try_apply_type_mapping_for_paramspec(
                            db,
                            signature,
                            prefix,
                            value,
                            type_mapping,
                            tcx,
                            visitor,
                        )
                    {
                        result.overloads
                    } else {
                        smallvec_inline![signature.apply_type_mapping_impl(
                            db,
                            type_mapping,
                            tcx,
                            visitor
                        )]
                    }
                }))
            }
            TypeMapping::PartialSpecialization(partial) => {
                Self::from_overloads(self.overloads.iter().flat_map(|signature| {
                    if let Some((prefix, paramspec)) =
                        signature.parameters.find_paramspec_from_args_kwargs(db)
                        && let Some(value) = partial.get(db, paramspec)
                        && let Some(result) = try_apply_type_mapping_for_paramspec(
                            db,
                            signature,
                            prefix,
                            value,
                            type_mapping,
                            tcx,
                            visitor,
                        )
                    {
                        result.overloads
                    } else {
                        smallvec_inline![signature.apply_type_mapping_impl(
                            db,
                            type_mapping,
                            tcx,
                            visitor

Review comment (suggestion):
If I'm reading the [docs](https://docs.rs/smallvec/latest/smallvec/macro.smallvec_inline.html) right, `smallvec_inline!` only works here because `result.overloads` happens to be a `SmallVec` with 1 stack-reserved element. If we were to change the type of `result.overloads`, or even the size of the `SmallVec`, this would not work anymore. Is it worth using something more future-proof, like wrapping in `Either`? `flat_map` just needs to return an iterator.

```rust
Either::Right([signature.apply_type_mapping_impl(
    db,
    type_mapping,
    tcx,
    visitor,
)]
```


Code after:
                _ => None,
            }
        }

        if let TypeMapping::ApplySpecialization(specialization) = type_mapping {
            Self::from_overloads(self.overloads.iter().flat_map(|signature| {
                if let Some((prefix, paramspec)) =
                    signature.parameters.find_paramspec_from_args_kwargs(db)
                    && let Some(value) = specialization.get(db, paramspec)
                    && let Some(result) = try_apply_type_mapping_for_paramspec(
                        db,
                        signature,
                        prefix,
                        value,
                        type_mapping,
                        tcx,
                        visitor,
                    )
                {
                    result.overloads
                } else {
                    smallvec_inline![signature.apply_type_mapping_impl(
                        db,
                        type_mapping,
                        tcx,
                        visitor
                    )]
                }
            }))
        } else {
            Self::from_overloads(
                self.overloads.iter().map(|signature| {
                    signature.apply_type_mapping_impl(db, type_mapping, tcx, visitor)
                }),
            )
        }
    }

    pub(crate) fn find_legacy_typevars_impl(
        &self,
        db: &'db dyn Db,
        binding_context: Option<Definition<'db>>,
        typevars: &mut FxOrderSet<BoundTypeVarInstance<'db>>,
        visitor: &FindLegacyTypeVarsVisitor<'db>,
    ) {
        for signature in &self.overloads {
            signature.find_legacy_typevars_impl(db, binding_context, typevars, visitor);
        }
    }

    /// Binds the first (presumably `self`) parameter of this signature. If a `self_type` is