Skip to content

Check tail node in check_links #46269

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 26, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions src/liballoc/linked_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1288,6 +1288,8 @@ mod tests {
let mut node_ptr: &Node<T>;
match list.head {
None => {
// tail node should also be None.
assert!(list.tail.is_none());
assert_eq!(0, list.len);
return;
}
Expand All @@ -1314,6 +1316,11 @@ mod tests {
}
}
}

// verify that the tail node points to the last node.
let tail = list.tail.as_ref().expect("some tail node").as_ref();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need the extra as_ref at the end here?

Copy link
Contributor Author

@udoprog udoprog Nov 26, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

list.tail is an Option<Shared<Node<T>>>. The first as_ref avoids creating a local copy (which would have to be in scope). The second converts the Shared ptr into a reference (through Shared::as_ref), which can then be casted.

So yes unless I'm missing something?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh I see, sorry I hadn't noticed the extra level of indirection in there. Looks like the way you're doing this is about as good as it gets, since Shared::as_ptr returns a *mut T, so you'd have to cast that anyways.

assert_eq!(tail as *const Node<T>, node_ptr as *const Node<T>);
// check that len matches interior links.
assert_eq!(len, list.len);
}
}
Expand Down