Skip to content

Conversation

@RalfJung
Copy link
Member

@RalfJung RalfJung commented Aug 2, 2017

The documentation says

    /// Similar to get_parent, returns the parent node id or id if there is no
    /// parent.
    /// This function returns the immediate parent in the AST, whereas get_parent
    /// returns the enclosing item.

One would think that one can walk up the tree by repeatedly calling get_parent_node until it returns the argument, and then work on the NodeIds that arise. However, that is not true: get_parent_node will return id 0 (the crate itself) for items that sit directly in the crate; calling get on that NodeId will panic.

So, the fact that get_parent_node returns the root when passed the root is actually not really useful, because the root itself is already a somewhat degenerate node. This improves the doc so hopefully people writing code that "walks up the tree" don't run into this issue like I did...

@rust-highfive
Copy link
Contributor

r? @arielb1

(rust_highfive has picked a reviewer for you, use r? to override)

@michaelwoerister
Copy link
Member

@bors r+ rollup

Thanks, @RalfJung!

@bors
Copy link
Collaborator

bors commented Aug 2, 2017

📌 Commit e92ddbf has been approved by michaelwoerister

@bors
Copy link
Collaborator

bors commented Aug 2, 2017

⌛ Testing commit e92ddbf with merge cd87b5d...

bors added a commit that referenced this pull request Aug 2, 2017
Improve hir::map::Map::get_parent_node doc

The documentation says
```
    /// Similar to get_parent, returns the parent node id or id if there is no
    /// parent.
    /// This function returns the immediate parent in the AST, whereas get_parent
    /// returns the enclosing item.
```
One would think that one can walk up the tree by repeatedly calling `get_parent_node` until it returns the argument, and then work on the `NodeId`s that arise. However, that is not true: `get_parent_node` will return id 0 (the crate itself) for items that sit directly in the crate; calling `get` on that `NodeId` will panic.

So, the fact that `get_parent_node` returns the root when passed the root is actually not really useful, because the root itself is already a somewhat degenerate node. This improves the doc so hopefully people writing code that "walks up the tree" don't run into this issue like I did...
@bors
Copy link
Collaborator

bors commented Aug 2, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: michaelwoerister
Pushing cd87b5d to master...

@bors bors merged commit e92ddbf into rust-lang:master Aug 2, 2017
@RalfJung RalfJung deleted the mapdoc branch August 3, 2017 04:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants