Skip to content

Commit 4f252f1

Browse files
authored
Rollup merge of #91404 - nnethercote:fix-bad-NodeId-limit-checking, r=dtolnay
Fix bad `NodeId` limit checking. `Resolver::next_node_id` converts a `u32` to a `usize` (which is possibly bigger), does a checked add, and then converts the result back to a `u32`. The `usize` conversion completely subverts the checked add! This commit removes the conversion to/from `usize`.
2 parents ce197e2 + e7ee823 commit 4f252f1

File tree

1 file changed

+3
-6
lines changed
  • compiler/rustc_resolve/src

1 file changed

+3
-6
lines changed

Diff for: compiler/rustc_resolve/src/lib.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -1430,12 +1430,9 @@ impl<'a> Resolver<'a> {
14301430
}
14311431

14321432
pub fn next_node_id(&mut self) -> NodeId {
1433-
let next = self
1434-
.next_node_id
1435-
.as_usize()
1436-
.checked_add(1)
1437-
.expect("input too large; ran out of NodeIds");
1438-
self.next_node_id = ast::NodeId::from_usize(next);
1433+
let next =
1434+
self.next_node_id.as_u32().checked_add(1).expect("input too large; ran out of NodeIds");
1435+
self.next_node_id = ast::NodeId::from_u32(next);
14391436
self.next_node_id
14401437
}
14411438

0 commit comments

Comments
 (0)