[ty] Only calculate information for unresolved-reference subdiagnostic if we know we'll emit the diagnostic (#18465)
Some checks are pending
CI / cargo clippy (push) Blocked by required conditions
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / mkdocs (push) Waiting to run
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks (push) Blocked by required conditions
[ty Playground] Release / publish (push) Waiting to run

## Summary

This optimizes some of the logic added in
https://github.com/astral-sh/ruff/pull/18444. In general, we only
calculate information for subdiagnostics if we know we'll actually emit
the diagnostic. The check to see whether we'll emit the diagnostic is
work we'll definitely have to do whereas the the work to gather
information for a subdiagnostic isn't work we necessarily have to do if
the diagnostic isn't going to be emitted at all.

This PR makes us lazier about gathering the information we need for the
subdiagnostic, and moves all the subdiagnostic logic into one function
rather than having some `unresolved-reference` subdiagnostic logic in
`infer.rs` and some in `diagnostic.rs`.

## Test Plan

`cargo test -p ty_python_semantic`
This commit is contained in:
Alex Waygood 2025-06-04 20:41:00 +01:00 committed by GitHub
parent 5a8cdab771
commit ce8b744f17
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 105 additions and 106 deletions

View file

@ -46,7 +46,7 @@ error[unresolved-reference]: Name `x` used when not defined
7 | class Foo:
8 | x: int = 1
|
info: An attribute `x` is available, consider using `self.x`
info: An attribute `x` is available: consider using `self.x`
info: rule `unresolved-reference` is enabled by default
```
@ -62,7 +62,7 @@ error[unresolved-reference]: Name `x` used when not defined
13 | class Foo:
14 | def __init__(self):
|
info: An attribute `x` is available, consider using `self.x`
info: An attribute `x` is available: consider using `self.x`
info: rule `unresolved-reference` is enabled by default
```
@ -76,7 +76,7 @@ error[unresolved-reference]: Name `x` used when not defined
19 | y = x
| ^
|
info: An attribute `x` is available, consider using `self.x`
info: An attribute `x` is available: consider using `self.x`
info: rule `unresolved-reference` is enabled by default
```