From 0f0de57936902e819b087420e9e2ed9032552ddd Mon Sep 17 00:00:00 2001 From: Simon Sapin Date: Tue, 4 Aug 2015 07:28:53 +0200 Subject: [PATCH] Add a comment to explain the struct pattern trick. https://github.com/servo/servo/issues/6912#issuecomment-127429643 --- components/util/mem.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/components/util/mem.rs b/components/util/mem.rs index 370840b7a16..eb5785a40df 100644 --- a/components/util/mem.rs +++ b/components/util/mem.rs @@ -103,6 +103,8 @@ impl HeapSizeOf for Option { impl HeapSizeOf for url::Url { fn heap_size_of_children(&self) -> usize { + // Using a struct pattern without `..` rather than `foo.bar` field access + // makes sure this will be updated if a field is added. let &url::Url { ref scheme, ref scheme_data, ref query, ref fragment } = self; scheme.heap_size_of_children() + scheme_data.heap_size_of_children() + @@ -122,6 +124,8 @@ impl HeapSizeOf for url::SchemeData { impl HeapSizeOf for url::RelativeSchemeData { fn heap_size_of_children(&self) -> usize { + // Using a struct pattern without `..` rather than `foo.bar` field access + // makes sure this will be updated if a field is added. let &url::RelativeSchemeData { ref username, ref password, ref host, ref port, ref default_port, ref path } = self; username.heap_size_of_children() +