Skip to content
Discussion options

You must be logged in to vote

I'm afraid it's not possible to have AstNodes in traverse. The 2 are fundamentally incompatible, because AstNodes contains & references to all AST nodes, and traverse provides &mut references to nodes (so you can mutate the AST).

Traverse pulls some tricks to allow reading back up the tree by carefully ensuring you can never obtain a & and &mut ref to same node at the same time. But it's not possible to generalize to an ability to get hold of any node at any time, the way AstNodes allows. This would be a violation of Rust's aliasing rules.

So I'm sorry to say, this isn't going to be possible.

Out of interest, can I ask what is it that you're trying to do? What's the purpose for which you …

Replies: 1 comment 5 replies

Comment options

You must be logged in to vote
5 replies
@Hookyns
Comment options

@Hookyns
Comment options

@overlookmotel
Comment options

@Hookyns
Comment options

@overlookmotel
Comment options

Answer selected by Hookyns
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants