ruff/crates/ruff_python_ast/src
Micha Reiser 8ea5b08700
refactor: Use `QualifiedName` for `Imported::call_path` (#10214)
## Summary

When you try to remove an internal representation leaking into another
type and end up rewriting a simple version of `smallvec`.

The goal of this PR is to replace the `Box<[&'a str]>` with
`Box<QualifiedName>` to avoid that the internal `QualifiedName`
representation leaks (and it gives us a nicer API too). However, doing
this when `QualifiedName` uses `SmallVec` internally gives us all sort
of funny lifetime errors. I was lost but @BurntSushi came to rescue me.
He figured out that `smallvec` has a variance problem which is already
tracked in https://github.com/servo/rust-smallvec/issues/146

To fix the variants problem, I could use the smallvec-2-alpha-4 or
implement our own smallvec. I went with implementing our own small vec
for this specific problem. It obviously isn't as sophisticated as
smallvec (only uses safe code), e.g. it doesn't perform any size
optimizations, but it does its job.

Other changes:

* Removed `Imported::qualified_name` (the version that returns a
`String`). This can be replaced by calling `ToString` on the qualified
name.
* Renamed `Imported::call_path` to `qualified_name` and changed its
return type to `&QualifiedName`.
* Renamed `QualifiedName::imported` to `user_defined` which is the more
common term when talking about builtins vs the rest/user defined
functions.


## Test plan

`cargo test`
2024-03-06 09:55:59 +01:00
..
visitor Remove `Expr` postfix from `ExprNamed`, `ExprIf`, and `ExprGenerator` (#10229) 2024-03-04 12:55:01 +01:00
all.rs Remove `Expr` postfix from `ExprNamed`, `ExprIf`, and `ExprGenerator` (#10229) 2024-03-04 12:55:01 +01:00
comparable.rs Remove `Expr` postfix from `ExprNamed`, `ExprIf`, and `ExprGenerator` (#10229) 2024-03-04 12:55:01 +01:00
docstrings.rs Move Python whitespace utilities into new `ruff_python_whitespace` crate (#4993) 2023-06-10 00:59:57 +00:00
expression.rs Remove `Expr` postfix from `ExprNamed`, `ExprIf`, and `ExprGenerator` (#10229) 2024-03-04 12:55:01 +01:00
hashable.rs Pull in RustPython parser (#6099) 2023-07-27 09:29:11 +00:00
helpers.rs Remove `Expr` postfix from `ExprNamed`, `ExprIf`, and `ExprGenerator` (#10229) 2024-03-04 12:55:01 +01:00
identifier.rs Update to Rust 1.74 and use new clippy lints table (#8722) 2023-11-16 18:12:46 -05:00
imports.rs Use Rust 1.75 toolchain (#9437) 2024-01-08 18:03:16 +01:00
int.rs Include radix base prefix in large number representation (#7700) 2023-09-28 20:38:06 +00:00
lib.rs Split `CallPath` into `QualifiedName` and `UnqualifiedName` (#10210) 2024-03-04 09:06:51 +00:00
name.rs refactor: Use `QualifiedName` for `Imported::call_path` (#10214) 2024-03-06 09:55:59 +01:00
node.rs Remove `Expr` postfix from `ExprNamed`, `ExprIf`, and `ExprGenerator` (#10229) 2024-03-04 12:55:01 +01:00
nodes.rs Remove `Expr` postfix from `ExprNamed`, `ExprIf`, and `ExprGenerator` (#10229) 2024-03-04 12:55:01 +01:00
parenthesize.rs Comments outside expression parentheses (#7873) 2023-10-19 09:24:11 +00:00
relocate.rs Remove `Expr` postfix from `ExprNamed`, `ExprIf`, and `ExprGenerator` (#10229) 2024-03-04 12:55:01 +01:00
statement_visitor.rs Remove `Stmt::TryStar` (#6566) 2023-08-14 13:39:44 -04:00
stmt_if.rs Misc. small tweaks from perusing modules (#9383) 2024-01-03 12:30:25 -05:00
str.rs Use `AhoCorasick` to speed up quote match (#9773) 2024-02-02 09:57:39 -05:00
traversal.rs [`flake8-simplify`] Implement `enumerate-for-loop` (`SIM113`) (#7777) 2024-01-14 11:00:59 -05:00
types.rs Remove `RefEquality` (#6393) 2023-08-07 16:04:50 +00:00
visitor.rs Remove `Expr` postfix from `ExprNamed`, `ExprIf`, and `ExprGenerator` (#10229) 2024-03-04 12:55:01 +01:00
whitespace.rs Use consistent re-export from `ruff_source_file` (#9320) 2023-12-30 14:48:45 -05:00