ruff/crates/ruff_db/src
Brent Westbrook 9c47b6dbb0
[red-knot] Detect version-related syntax errors (#16379)
## Summary
This PR extends version-related syntax error detection to red-knot. The
main changes here are:

1. Passing `ParseOptions` specifying a `PythonVersion` to parser calls
2. Adding a `python_version` method to the `Db` trait to make this
possible
3. Converting `UnsupportedSyntaxError`s to `Diagnostic`s
4. Updating existing mdtests  to avoid unrelated syntax errors

My initial draft of (1) and (2) in #16090 instead tried passing a
`PythonVersion` down to every parser call, but @MichaReiser suggested
the `Db` approach instead
[here](https://github.com/astral-sh/ruff/pull/16090#discussion_r1969198407),
and I think it turned out much nicer.

All of the new `python_version` methods look like this:

```rust
fn python_version(&self) -> ruff_python_ast::PythonVersion {
    Program::get(self).python_version(self)
}
```

with the exception of the `TestDb` in `ruff_db`, which hard-codes
`PythonVersion::latest()`.

## Test Plan

Existing mdtests, plus a new mdtest to see at least one of the new
diagnostics.
2025-04-17 14:00:30 -04:00
..
diagnostic [red-knot] Detect version-related syntax errors (#16379) 2025-04-17 14:00:30 -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