-
-
Notifications
You must be signed in to change notification settings - Fork 14.3k
Clarify BTree range_search comments
#81312
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -94,7 +94,7 @@ impl<BorrowType: marker::BorrowType, K, V> NodeRef<BorrowType, K, V, marker::Lea | |
| K: Borrow<Q>, | ||
| R: RangeBounds<Q>, | ||
| { | ||
| // WARNING: Inlining these variables would be unsound (#81138) | ||
| // It might be unsound to inline these variables if this logic changes (#81138). | ||
| // We assume the bounds reported by `range` remain the same, but | ||
| // an adversarial implementation could change between calls | ||
| let (start, end) = (range.start_bound(), range.end_bound()); | ||
|
|
@@ -114,6 +114,8 @@ impl<BorrowType: marker::BorrowType, K, V> NodeRef<BorrowType, K, V, marker::Lea | |
| loop { | ||
| let (lower_edge_idx, lower_child_bound) = self.find_lower_bound_index(lower_bound); | ||
| let (upper_edge_idx, upper_child_bound) = self.find_upper_bound_index(upper_bound); | ||
| // SAFETY: This panic is used for safety, so external impls can't be called here. The | ||
| // comparison is done with integers for that reason. | ||
|
||
| if lower_edge_idx > upper_edge_idx { | ||
| panic!("Ord is ill-defined in BTreeMap range") | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's good to tone down the warning, but I don't know what you mean with "if this logic changes". What logic? It might be bad to inline these variables without any other change, because successfully passing the match statement might fool you to believe the start and end actually used were fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I meant the code in the rest of the method. This might be better:
The rest of the comment already explains why inlining can cause a safety issue.