about summary refs log tree commit diff
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2021-12-01 07:22:29 +1100
committerNicholas Nethercote <n.nethercote@gmail.com>2021-12-01 15:08:37 +1100
commite7ee8230ced7c14043ca51191063c13e7fbc7212 (patch)
tree63b3083a08f337e7cdb72977c1c009ba6398af33
parent686e313a9aa14107c8631ffe48fa09110a7692db (diff)
downloadrust-e7ee8230ced7c14043ca51191063c13e7fbc7212.tar.gz
rust-e7ee8230ced7c14043ca51191063c13e7fbc7212.zip
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`.
-rw-r--r--compiler/rustc_resolve/src/lib.rs9
1 files changed, 3 insertions, 6 deletions
diff --git a/compiler/rustc_resolve/src/lib.rs b/compiler/rustc_resolve/src/lib.rs
index d17e8875a1e..a8ae4736c04 100644
--- a/compiler/rustc_resolve/src/lib.rs
+++ b/compiler/rustc_resolve/src/lib.rs
@@ -1430,12 +1430,9 @@ impl<'a> Resolver<'a> {
     }
 
     pub fn next_node_id(&mut self) -> NodeId {
-        let next = self
-            .next_node_id
-            .as_usize()
-            .checked_add(1)
-            .expect("input too large; ran out of NodeIds");
-        self.next_node_id = ast::NodeId::from_usize(next);
+        let next =
+            self.next_node_id.as_u32().checked_add(1).expect("input too large; ran out of NodeIds");
+        self.next_node_id = ast::NodeId::from_u32(next);
         self.next_node_id
     }