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

Code before:
            .cloned()
            .collect()
    }

    fn module_type_symbols_initial(
        _db: &dyn Db,
        _id: salsa::Id,
    ) -> smallvec::SmallVec<[ast::name::Name; 8]> {
        smallvec::SmallVec::default()
    }

    /// Returns an iterator over all implicit module global symbols and their types.
    ///
    /// This is used for completions in the global scope of a module. It returns
    /// the correct types for special-cased symbols like `__file__` (which is `str`
    /// for the current module, not `str | None`).
    pub(crate) fn all_implicit_module_globals(
        db: &dyn Db,
    ) -> impl Iterator<Item = (Name, Type<'_>)> + '_ {
        // Special-cased implicit globals that are not in `module_type_symbols`
        let special_cased = [
            Name::new_static("__builtins__"),
            Name::new_static("__debug__"),
            Name::new_static("__warningregistry__"),
        ]
        .into_iter();

        // All symbols from ModuleType (already includes `__file__`, `__name__`, etc.)
        let module_type_syms = module_type_symbols(db).iter().cloned();

        // Combine and map to (name, type) pairs
        special_cased
            .chain(module_type_syms)
            .filter_map(move |name| {
                let place = module_type_implicit_global_symbol(db, name.as_str());
                // Only include bound symbols (not undefined or possibly-undefined)
                place.place.ignore_possibly_undefined().map(|ty| (name, ty))
            })
    }

    #[cfg(test)]
    mod tests {
        use super::*;
        use crate::db::tests::setup_db;

        #[test]
        fn module_type_symbols_includes_declared_types_but_not_referenced_types() {
            let db = setup_db();
            let symbol_names = module_type_symbols(&db);

            let dunder_name_symbol_name = ast::name::Name::new_static("__name__");

Review comment (bug):
```suggestion
        let special_cased = ["__builtins__", "__debug__", "__warningregistry__"]
            .into_iter()
            .map(Name::new_static);
```

Code after:
            .cloned()
            .collect()
    }

    fn module_type_symbols_initial(
        _db: &dyn Db,
        _id: salsa::Id,
    ) -> smallvec::SmallVec<[ast::name::Name; 8]> {
        smallvec::SmallVec::default()
    }

    /// Returns an iterator over all implicit module global symbols and their types.
    ///
    /// This is used for completions in the global scope of a module. It returns
    /// the correct types for special-cased symbols like `__file__` (which is `str`
    /// for the current module, not `str | None`).
    pub(crate) fn all_implicit_module_globals(
        db: &dyn Db,
    ) -> impl Iterator<Item = (Name, Type<'_>)> + '_ {
        // Special-cased implicit globals that are not in `module_type_symbols`
        let special_cased = ["__builtins__", "__debug__", "__warningregistry__"]
            .into_iter()
            .map(Name::new_static);

        // All symbols from ModuleType (already includes `__file__`, `__name__`, etc.)
        let module_type_syms = module_type_symbols(db).iter().cloned();

        // Combine and map to (name, type) pairs
        special_cased
            .chain(module_type_syms)
            .filter_map(move |name| {
                let place = module_type_implicit_global_symbol(db, name.as_str());
                // Only include bound symbols (not undefined or possibly-undefined)
                place.place.ignore_possibly_undefined().map(|ty| (name, ty))
            })
    }

    #[cfg(test)]
    mod tests {
        use super::*;
        use crate::db::tests::setup_db;

        #[test]
        fn module_type_symbols_includes_declared_types_but_not_referenced_types() {
            let db = setup_db();
            let symbol_names = module_type_symbols(&db);

            let dunder_name_symbol_name = ast::name::Name::new_static("__name__");
            assert!(symbol_names.contains(&dunder_name_symbol_name));

            let property_symbol_name = ast::name::Name::new_static("property");