mirror of
https://github.com/astral-sh/ruff
synced 2026-01-22 22:10:48 -05:00
## Summary The resulting type when multiplying a string literal by an integer literal is one of two types: - `StringLiteral`, in the case where it is a reasonably small resulting string (arbitrarily bounded here to 4096 bytes, roughly a page on many operating systems), including the fully expanded string. - `LiteralString`, matching Pyright etc., for strings larger than that. Additionally: - Switch to using `Box<str>` instead of `String` for the internal value of `StringLiteral`, saving some non-trivial byte overhead (and keeping the total number of allocations the same). - Be clearer and more accurate about which types we ought to defer to in `StringLiteral` and `LiteralString` member lookup. ## Test Plan Added a test case covering multiplication times integers: positive, negative, zero, and in and out of bounds. --------- Co-authored-by: Alex Waygood <alex.waygood@gmail.com> Co-authored-by: Carl Meyer <carl@astral.sh>