Repository: astral-sh/ruff
File: crates/ruff_python_parser/src/semantic_errors.rs (Rust)

Code before:

    /// Represents a function parameter that is also declared as `global`.
    ///
    /// Declaring a parameter as `global` is invalid, since parameters are already
    /// bound in the local scope of the function. Using `global` on them introduces
    /// ambiguity and will result in a `SyntaxError`.
    GlobalParameter(String),

    /// Represents the use of alternative patterns in a `match` statement that bind different names.
    ///
    /// Python requires all alternatives in an OR pattern (`|`) to bind the same set of names.
    /// Using different names results in a `SyntaxError`.
    ///
    /// ## Example:
    ///
    /// ```python
    /// match 5:
    ///     case [x] | [y]:  # error
    ///         ...
    /// ```
    DifferentMatchPatternBindings,

    /// Represents a nonlocal statement for a name that has no binding in an enclosing scope.
    NonlocalWithoutBinding(String),

    ReturnInAsyncGenerator,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, get_size2::GetSize)]
pub enum AwaitOutsideAsyncFunctionKind {
    Await,
    AsyncFor,
    AsyncWith,
    AsyncComprehension,
}

impl Display for AwaitOutsideAsyncFunctionKind {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.write_str(match self {
            AwaitOutsideAsyncFunctionKind::Await => "`await`",
            AwaitOutsideAsyncFunctionKind::AsyncFor => "`async for`",
            AwaitOutsideAsyncFunctionKind::AsyncWith => "`async with`",
            AwaitOutsideAsyncFunctionKind::AsyncComprehension => "asynchronous comprehension",
        })
    }
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, get_size2::GetSize)]
pub enum YieldOutsideFunctionKind {
    Yield,
    YieldFrom,

Review comment (suggestion):
Could we add some docs here? I think it's especially important to capture the "with value" part since it's not in the name.

Code after:

    /// Represents a duplicate parameter name in a function or lambda expression.
    ///
    /// ## Examples
    ///
    /// ```python
    /// def f(x, x): ...
    /// lambda x, x: ...
    /// ```
    DuplicateParameter(String),

    /// Represents a nonlocal declaration at module level
    NonlocalDeclarationAtModuleLevel,

    /// Represents the same variable declared as both nonlocal and global
    NonlocalAndGlobal(String),

    /// Represents a type annotation on a variable that's been declared global
    AnnotatedGlobal(String),

    /// Represents a type annotation on a variable that's been declared nonlocal
    AnnotatedNonlocal(String),

    /// Represents the use of `yield from` inside an asynchronous function.
    YieldFromInAsyncFunction,

    /// Represents the use of `from <module> import *` outside module scope.
    NonModuleImportStar(String),

    /// Represents the use of more than one starred expression in an assignment.
    ///
    /// Python only allows a single starred target when unpacking values on the
    /// left-hand side of an assignment. Using multiple starred expressions makes
    /// the statement invalid and results in a `SyntaxError`.
    MultipleStarredExpressions,

    /// Represents the use of a `__future__` feature that is not defined.
    FutureFeatureNotDefined(String),

    /// Represents the use of a `break` statement outside of a loop.
    BreakOutsideLoop,

    /// Represents the use of a `continue` statement outside of a loop.
    ContinueOutsideLoop,

    /// Represents a function parameter that is also declared as `global`.
    ///
    /// Declaring a parameter as `global` is invalid, since parameters are already
    /// bound in the local scope of the function. Using `global` on them introduces
    /// ambiguity and will result in a `SyntaxError`.
    GlobalParameter(String),