Skip to content

Simplify ast::UseTreeKind - #162794

Open
nnethercote wants to merge 3 commits into
rust-lang:mainfrom
nnethercote:simplify-UseTreeKind
Open

nnethercote wants to merge 3 commits into
rust-lang:mainfrom
nnethercote:simplify-UseTreeKind

Conversation

@nnethercote

Copy link
Copy Markdown
Contributor

We can make things simpler by adjusting how the ids are stored. Details in individual commits.

r? @petrochenkov

It makes sense to put the top-level item first, before the use tree
within the item. And it makes sense to have a single function-level
comment explaining this rather than inline comments at the definition
and every call site.
`is_public` is not relevant here.
`ast::UseTree` doesn't have an `id` field. The top-level use tree uses
the item's id as its id, and nested use trees get their own id. This
requires storing an id next to every nested use tree, which is awkward.

This commit moves the id into `UseTree`. This means the top-level id is
stored twice: once in the item, and once in the top-level use tree. This
is worth it because it makes all the other code that handles use trees
simpler, avoiding many `use_tree`/`id` pairs.
@rustbot

rustbot commented Sep 15, 2026

Copy link
Copy Markdown
Collaborator

The parser was modified, potentially altering the grammar of (stable) Rust
which would be a breaking change.

cc @fmease

rustfmt is developed in its own repository. If possible, consider making this change to rust-lang/rustfmt instead.

cc @rust-lang/rustfmt

clippy is developed in its own repository. If possible, consider making this change to rust-lang/rust-clippy instead.

cc @rust-lang/clippy

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Sep 15, 2026
@rustbot rustbot added T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue. labels Sep 15, 2026
@nnethercote

Copy link
Copy Markdown
Contributor Author

@oli-obk: this will conflict a little with your #161349, but I think they're fundamentally doing different things and are compatible.

@nnethercote

Copy link
Copy Markdown
Contributor Author

LLM disclosure: some of the ideas for these changes came from an LLM. I made all the changes myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-clippy Relevant to the Clippy team. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-rustfmt Relevant to the rustfmt team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants