Repository: astral-sh/ruff
File: crates/ruff_db/src/parsed.rs (Rust)

Code before:
}

pub fn parsed_string_annotation(
    source: &str,
    string: &StringLiteral,
) -> Result<Parsed<ModExpression>, ParseError> {
    let expr = parse_string_annotation(source, string)?;

    // We need the sub-ast of the string annotation to be indexed
    indexed::ensure_indexed(&expr, string.node_index().load()).map_err(|err| {
        let message = match err {
            NodeIndexError::NoParent => {
                "internal error: string annotation's parent had no NodeIndex".to_owned()
            }
            NodeIndexError::TooNested => "too many levels of nested string annotations, remove the redundant nested quotes".to_owned(),
            NodeIndexError::OverflowedIndices => {
                "file too long for string annotations, either break up the file or don't use string annotations".to_owned()
            }
            NodeIndexError::OverflowedSubIndices => {
                "file too long for nested string annotations, remove the redundant nested quotes".to_owned()
            }
            NodeIndexError::ExhaustedSubIndices => {
                "string annotation is too long, consider introducing type aliases to simplify".to_owned()
            }
            NodeIndexError::ExhaustedSubSubIndices => {
                "nested string annotation is too long, remove the redundant nested quotes".to_owned()
            }
        };

        ParseError {
            error: ParseErrorType::OtherError(message),
            location: string.range,
        }
    })?;

    Ok(expr)
}

/// A wrapper around a parsed module.
///
/// This type manages instances of the module AST. A particular instance of the AST
/// is represented with the [`ParsedModuleRef`] type.
#[derive(Clone, get_size2::GetSize)]
pub struct ParsedModule {
    file: File,
    #[get_size(size_fn = arc_swap_size)]
    inner: Arc<ArcSwapOption<indexed::IndexedModule>>,
}

impl ParsedModule {
    pub fn new(file: File, parsed: Parsed<ModModule>) -> Self {

Review comment (refactor):
```suggestion
                "file too long for nested string annotations; remove the redundant nested quotes".to_owned()
            }
            NodeIndexError::ExhaustedSubIndices => {
                "string annotation is too long: consider introducing type aliases to simplify".to_owned()
            }
            NodeIndexError::ExhaustedSubSubIndices => {
                "nested string annotation is too long; remove the redundant nested quotes".to_owned()
```

Code after:
}

pub fn parsed_string_annotation(
    source: &str,
    string: &StringLiteral,
) -> Result<Parsed<ModExpression>, ParseError> {
    let expr = parse_string_annotation(source, string)?;

    // We need the sub-ast of the string annotation to be indexed
    indexed::ensure_indexed(&expr, string.node_index().load()).map_err(|err| {
        let message = match err {
            NodeIndexError::NoParent => {
                "internal error: string annotation's parent had no NodeIndex".to_owned()
            }
            NodeIndexError::TooNested => "too many levels of nested string annotations; remove the redundant nested quotes".to_owned(),
            NodeIndexError::OverflowedIndices => {
                "file too long for string annotations; either break up the file or don't use string annotations".to_owned()
            }
            NodeIndexError::OverflowedSubIndices => {
                "file too long for nested string annotations; remove the redundant nested quotes".to_owned()
            }
            NodeIndexError::ExhaustedSubIndices => {
                "string annotation is too long; consider introducing type aliases to simplify".to_owned()
            }
            NodeIndexError::ExhaustedSubSubIndices => {
                "nested string annotation is too long; remove the redundant nested quotes".to_owned()
            }
        };

        ParseError {
            error: ParseErrorType::OtherError(message),
            location: string.range,
        }
    })?;

    Ok(expr)
}

/// A wrapper around a parsed module.
///
/// This type manages instances of the module AST. A particular instance of the AST
/// is represented with the [`ParsedModuleRef`] type.
#[derive(Clone, get_size2::GetSize)]
pub struct ParsedModule {
    file: File,
    #[get_size(size_fn = arc_swap_size)]
    inner: Arc<ArcSwapOption<indexed::IndexedModule>>,
}

impl ParsedModule {
    pub fn new(file: File, parsed: Parsed<ModModule>) -> Self {