Repository: astral-sh/ruff
File: crates/ty_project/src/glob/include.rs (Rust)

Code before:
impl IncludeFilterBuilder {
    pub(crate) fn new() -> Self {
        Self {
            set: GlobSetBuilder::new(),
            original_pattern: Vec::new(),
            regexes: Vec::new(),
        }
    }

    /// Adds an include pattern to the filter.
    pub(crate) fn add(
        &mut self,
        input: &AbsolutePortableGlobPattern,
    ) -> Result<&mut Self, globset::Error> {
        let mut glob_pattern = input.absolute();

        let mut only_directory = false;

        // A pattern ending with a `/` should only match directories. E.g. `src/` only matches directories
        // whereas `src` matches both files and directories.
        // We need to remove the `/` to ensure that a path missing the trailing `/` matches.
        if let Some(after) = glob_pattern.strip_suffix('/') {
            // Escaped `/` or `\` aren't allowed. `portable_glob::parse` will error
            only_directory = true;
            glob_pattern = after;
        }

        // If regex ends with `/**`, only push that one glob and regex
        // Otherwise, push two regex, one for `/**` and one for without
        let glob = GlobBuilder::new(glob_pattern)
            .literal_separator(true)
            // No need to support Windows-style paths, so the backslash can be used a escape.
            .backslash_escape(true)
            .build()?;
        self.original_pattern.push(input.relative().to_string());

        // `lib` is the same as `lib/**`
        // Add a glob that matches `lib` exactly, change the glob to `lib/**`.
        if glob_pattern.ends_with("**") {
            self.push_prefix_regex(&glob);
            self.set.add(glob);
        } else {
            let prefix_glob = GlobBuilder::new(&format!("{glob_pattern}/**"))
                .literal_separator(true)
                // No need to support Windows-style paths, so the backslash can be used a escape.
                .backslash_escape(true)
                .build()?;

            self.push_prefix_regex(&prefix_glob);
            self.set.add(prefix_glob);


Review comment (suggestion):
```suggestion
```

I desperately want this to be loadbearing somehow

Code after:
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        f.debug_list().entries(&self.original_patterns).finish()
    }
}

impl PartialEq for IncludeFilter {
    fn eq(&self, other: &Self) -> bool {
        self.original_patterns == other.original_patterns
    }
}

impl Eq for IncludeFilter {}

#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub(crate) enum MatchFile {
    No,
    /// The file path matches the glob literally exactly. This is only the case for globs
    /// that don't use any wildcards.
    Literal,

    /// The file path matches the glob pattern.
    Pattern,
}

impl MatchFile {}

#[derive(Debug)]
pub(crate) struct IncludeFilterBuilder {
    set: GlobSetBuilder,
    set_len: usize,
    original_patterns: Vec<Box<str>>,
    regexes: Vec<String>,
    /// Indices of literal patterns (contain no meta characters).
    literal_pattern_indices: Vec<usize>,
}

impl IncludeFilterBuilder {
    pub(crate) fn new() -> Self {
        Self {
            literal_pattern_indices: Vec::new(),
            set: GlobSetBuilder::new(),
            set_len: 0,
            original_patterns: Vec::new(),
            regexes: Vec::new(),
        }
    }

    /// Adds an include pattern to the filter.
    pub(crate) fn add(
        &mut self,
        input: &AbsolutePortableGlobPattern,