Repository: astral-sh/ruff
File: crates/ruff_python_semantic/src/analyze/terminal.rs (Rust)

Code before:
use ruff_python_ast::helpers::map_callable;
use ruff_python_ast::{self as ast, ExceptHandler, Stmt};

use crate::model::SemanticModel;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Terminal {
    /// There is no known terminal.
    None,
    /// There is an implicit return (e.g., a path that doesn't return).
    Implicit,
    /// Every path through the function ends with a `raise` statement.
    Raise,
    /// Every path through the function ends with a `raise NotImplementedError` statement.
    RaiseNotImplemented,
    /// No path through the function ends with a `return` statement.
    Return,
    /// Every path through the function ends with a `return` or `raise` statement.
    RaiseOrReturn,
    /// At least one path through the function ends with a `return` statement.
    ConditionalReturn,
}

impl Terminal {
    /// Returns the [`Terminal`] behavior of the function, if it can be determined.
    pub fn from_function(function: &ast::StmtFunctionDef, semantic: &SemanticModel) -> Terminal {
        Self::from_body(&function.body, Some(semantic))
    }

    /// Returns `true` if the [`Terminal`] behavior includes at least one `return` path.
    pub fn has_any_return(self) -> bool {
        matches!(
            self,
            Self::Return | Self::RaiseOrReturn | Self::ConditionalReturn
        )
    }

    /// Returns `true` if the [`Terminal`] behavior includes at least one implicit `return` path.
    pub fn has_implicit_return(self) -> bool {
        matches!(self, Self::None | Self::Implicit | Self::ConditionalReturn)

Review comment (refactor):
Did you check if all of the other uses of `Terminal::Raise` should now be something like this?

```rust
matches!(terminal, Terminal::Raise | Terminal::RaiseNotImplemented)
```

It doesn't look like any other tests or ecosystem results are changing, but at least from a quick look, I would think these variants should be treated the same in some other rules. If so, it might be good to add a `Terminal::is_raise` helper method with a `matches!` like the one above.

Code after:
use ruff_python_ast::helpers::map_callable;
use ruff_python_ast::{self as ast, ExceptHandler, Stmt};

use crate::model::SemanticModel;

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Terminal {
    /// There is no known terminal.
    None,
    /// There is an implicit return (e.g., a path that doesn't return).
    Implicit,
    /// Every path through the function ends with a `raise` statement.
    Raise,
    /// Every path through the function ends with a `raise NotImplementedError` statement.
    RaiseNotImplemented,
    /// No path through the function ends with a `return` statement.
    Return,
    /// Every path through the function ends with a `return` or `raise` statement.
    RaiseOrReturn,
    /// At least one path through the function ends with a `return` statement.
    ConditionalReturn,
}

impl Terminal {
    /// Returns the [`Terminal`] behavior of the function, if it can be determined.
    pub fn from_function(function: &ast::StmtFunctionDef, semantic: &SemanticModel) -> Terminal {
        Self::from_body(&function.body, semantic)
    }

    /// Returns `true` if the [`Terminal`] behavior includes at least one `return` path.
    pub fn has_any_return(self) -> bool {
        matches!(
            self,
            Self::Return | Self::RaiseOrReturn | Self::ConditionalReturn
        )
    }

    /// Returns `true` if the [`Terminal`] behavior includes at least one implicit `return` path.
    pub fn has_implicit_return(self) -> bool {
        matches!(self, Self::None | Self::Implicit | Self::ConditionalReturn)