ruff/crates/ruff_db/src
Brent Westbrook e7f38fe74b
[red-knot] Detect semantic syntax errors (#17463)
Summary
--

This PR extends semantic syntax error detection to red-knot. The main
changes here are:

1. Adding `SemanticSyntaxChecker` and `Vec<SemanticSyntaxError>` fields
to the `SemanticIndexBuilder`
2. Calling `SemanticSyntaxChecker::visit_stmt` and `visit_expr` in the
`SemanticIndexBuilder`'s `visit_stmt` and `visit_expr` methods
3. Implementing `SemanticSyntaxContext` for `SemanticIndexBuilder`
4. Adding new mdtests to test the context implementation and show
diagnostics

(3) is definitely the trickiest and required (I think) a minor addition
to the `SemanticIndexBuilder`. I tried to look around for existing code
performing the necessary checks, but I definitely could have missed
something or misused the existing code even when I found it.

There's still one TODO around `global` statement handling. I don't think
there's an existing way to look this up, but I'm happy to work on that
here or in a separate PR. This currently only affects detection of one
error (`LoadBeforeGlobalDeclaration` or
[PLE0118](https://docs.astral.sh/ruff/rules/load-before-global-declaration/)
in ruff), so it's not too big of a problem even if we leave the TODO.

Test Plan
--

New mdtests, as well as new errors for existing mdtests

---------

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
2025-04-23 09:52:58 -04:00
..
diagnostic [red-knot] Detect semantic syntax errors (#17463) 2025-04-23 09:52:58 -04:00
files [internal]: Upgrade salsa (#16794) 2025-03-17 11:05:54 +01:00
system [red-knot] Use web-time instead of FileTime::now (#16967) 2025-03-25 13:03:30 +00:00
vendored Setup tracing and document tracing usage (#12730) 2024-08-08 06:28:40 +00:00
display.rs Upgrade Rust toolchain to 1.83 (#14677) 2024-11-29 12:05:05 +00:00
file_revision.rs [red-knot] Use web-time instead of FileTime::now (#16967) 2025-03-25 13:03:30 +00:00
files.rs [red-knot] Add 'Format document' to playground (#17217) 2025-04-07 09:26:03 +02:00
lib.rs [red-knot] Detect version-related syntax errors (#16379) 2025-04-17 14:00:30 -04:00
panic.rs [red-knot] Print non-string panic payloads and (sometimes) backtraces (#15363) 2025-01-08 18:12:16 -05:00
parsed.rs [red-knot] Detect version-related syntax errors (#16379) 2025-04-17 14:00:30 -04:00
source.rs [internal]: Upgrade salsa (#16794) 2025-03-17 11:05:54 +01:00
system.rs [red-knot] Use web-time instead of FileTime::now (#16967) 2025-03-25 13:03:30 +00:00
testing.rs [internal]: Upgrade salsa (#16794) 2025-03-17 11:05:54 +01:00
vendored.rs Upgrade Rust toolchain to 1.83 (#14677) 2024-11-29 12:05:05 +00:00