ruff/crates
Charlie Marsh f16e780e0a
Add an implicit concatenation flag to string and bytes constants (#6512)
## Summary

Per the discussion in
https://github.com/astral-sh/ruff/discussions/6183, this PR adds an
`implicit_concatenated` flag to the string and bytes constant variants.
It's not actually _used_ anywhere as of this PR, but it is covered by
the tests.

Specifically, we now use a struct for the string and bytes cases, along
with the `Expr::FString` node. That struct holds the value, plus the
flag:

```rust
#[derive(Clone, Debug, PartialEq, is_macro::Is)]
pub enum Constant {
    Str(StringConstant),
    Bytes(BytesConstant),
    ...
}

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct StringConstant {
    /// The string value as resolved by the parser (i.e., without quotes, or escape sequences, or
    /// implicit concatenations).
    pub value: String,
    /// Whether the string contains multiple string tokens that were implicitly concatenated.
    pub implicit_concatenated: bool,
}

impl Deref for StringConstant {
    type Target = str;
    fn deref(&self) -> &Self::Target {
        self.value.as_str()
    }
}

#[derive(Clone, Debug, PartialEq, Eq)]
pub struct BytesConstant {
    /// The bytes value as resolved by the parser (i.e., without quotes, or escape sequences, or
    /// implicit concatenations).
    pub value: Vec<u8>,
    /// Whether the string contains multiple string tokens that were implicitly concatenated.
    pub implicit_concatenated: bool,
}

impl Deref for BytesConstant {
    type Target = [u8];
    fn deref(&self) -> &Self::Target {
        self.value.as_slice()
    }
}
```

## Test Plan

`cargo test`
2023-08-14 13:46:54 +00:00
..
flake8_to_ruff Bump version to 0.0.284 (#6453) 2023-08-09 13:32:33 -05:00
ruff Add an implicit concatenation flag to string and bytes constants (#6512) 2023-08-14 13:46:54 +00:00
ruff_benchmark Remove lex and parsing from formatter benchmark (#6547) 2023-08-14 10:25:37 +02:00
ruff_cache Error on zero tab width (#6429) 2023-08-08 16:51:37 -04:00
ruff_cli Bump version to 0.0.284 (#6453) 2023-08-09 13:32:33 -05:00
ruff_dev Use a faster diffing library for the formatter ecosystem checks (#6497) 2023-08-11 15:51:54 +02:00
ruff_diagnostics Skip partial duplicates when applying multi-edit fixes (#6144) 2023-07-29 12:11:57 +00:00
ruff_formatter Override fmt_dangling_comments for frequent nodes (#6551) 2023-08-14 15:29:05 +02:00
ruff_index Add unreachable code rule (#5384) 2023-07-04 14:27:23 +00:00
ruff_macros Remove parser dependency from ruff-python-ast (#6096) 2023-07-26 17:47:22 +02:00
ruff_python_ast Add an implicit concatenation flag to string and bytes constants (#6512) 2023-08-14 13:46:54 +00:00
ruff_python_codegen Add an implicit concatenation flag to string and bytes constants (#6512) 2023-08-14 13:46:54 +00:00
ruff_python_formatter Override fmt_dangling_comments for frequent nodes (#6551) 2023-08-14 15:29:05 +02:00
ruff_python_index Avoid detecting continuations at non-start-of-line (#6219) 2023-08-01 00:20:29 -04:00
ruff_python_literal Remove allow(pedantic) from formatter (#6549) 2023-08-14 14:02:06 +02:00
ruff_python_parser Add an implicit concatenation flag to string and bytes constants (#6512) 2023-08-14 13:46:54 +00:00
ruff_python_resolver Replace .map_or(false, $closure) with .is_some_and(closure) (#6244) 2023-08-01 19:29:42 +02:00
ruff_python_semantic Remove SemanticModel#find_binding (#6546) 2023-08-14 00:09:05 -04:00
ruff_python_stdlib Replace .map_or(false, $closure) with .is_some_and(closure) (#6244) 2023-08-01 19:29:42 +02:00
ruff_python_trivia Remove allow(pedantic) from formatter (#6549) 2023-08-14 14:02:06 +02:00
ruff_shrinking Use Jupyter mode while parsing Notebook files (#5552) 2023-08-05 00:32:07 +00:00
ruff_source_file Skip BOM when determining Locator's line starts (#6159) 2023-07-29 11:47:13 +00:00
ruff_text_size Pull in RustPython parser (#6099) 2023-07-27 09:29:11 +00:00
ruff_wasm Set a default on PythonVersion (#6446) 2023-08-09 15:19:27 +00:00