Repository: astral-sh/ruff
File: crates/ty_ide/src/rename.rs (Rust)

Code before:
            )
            .build();

        // TODO(submodule-imports): this is incorrect, we should rename the `subpkg` int
        // and the RHS of the import statement (but *not* rename the LHS).
        //
        // However us being cautious here *would* be good as the rename will actually
        // result in a `subpkg` variable still existing in this code, as the import's LHS
        // `DefinitionKind::ImportFromSubmodule` would stop being overwritten by the RHS!
        assert_snapshot!(test.rename("mypkg"), @r"
        info[rename]: Rename symbol (found 1 locations)
         --> mypackage/__init__.py:4:5
          |
        2 | from .subpkg import subpkg
        3 |
        4 | x = subpkg
          |     ^^^^^^
          |
        ");
    }

    #[test]
    fn rename_overloaded_function() {
        let test = CursorTest::builder()
            .source(
                "lib.py",
                r#"
                from typing import overload, Any

                @overload
                def test<CURSOR>() -> None: ...
                @overload
                def test(a: str) -> str: ...
                @overload
                def test(a: int) -> int: ...

                def test(a: Any) -> Any:
                    return a
                "#,
            )
            .source(
                "main.py",
                r#"
                from lib2 import test

                test("test")
                "#,
            )
            .build();

        assert_snapshot!(test.rename("better_name"), @r"

Review comment (suggestion):
note that in `main.py` on line 1451/1450, we still import `test` from `lib2` (a module that doesn't exist), not `lib`. I don't know if that's intended or not. (I deliberately preserved that behaviour in https://github.com/astral-sh/ruff/pull/21810, because I wasn't sure if that was intended or not 😄)

Code after:
            )
            .build();

        // TODO(submodule-imports): this is incorrect, we should rename the `subpkg` int
        // and the RHS of the import statement (but *not* rename the LHS).
        //
        // However us being cautious here *would* be good as the rename will actually
        // result in a `subpkg` variable still existing in this code, as the import's LHS
        // `DefinitionKind::ImportFromSubmodule` would stop being overwritten by the RHS!
        assert_snapshot!(test.rename("mypkg"), @r"
        info[rename]: Rename symbol (found 1 locations)
         --> mypackage/__init__.py:4:5
          |
        2 | from .subpkg import subpkg
        3 |
        4 | x = subpkg
          |     ^^^^^^
          |
        ");
    }

    #[test]
    fn rename_overloaded_function() {
        let test = CursorTest::builder()
            .source(
                "lib.py",
                r#"
                from typing import overload, Any

                @overload
                def test<CURSOR>() -> None: ...
                @overload
                def test(a: str) -> str: ...
                @overload
                def test(a: int) -> int: ...

                def test(a: Any) -> Any:
                    return a
                "#,
            )
            .source(
                "main.py",
                r#"
                from lib import test

                test("test")
                "#,
            )
            .build();

        assert_snapshot!(test.rename("better_name"), @r#"