]> git.lizzy.rs Git - rust.git/commitdiff
Use exhaustive matches in shrink_to_fit impls
authorJonas Schievink <jonasschievink@gmail.com>
Sun, 4 Apr 2021 00:56:11 +0000 (02:56 +0200)
committerJonas Schievink <jonasschievink@gmail.com>
Sun, 4 Apr 2021 00:56:11 +0000 (02:56 +0200)
crates/hir_def/src/item_scope.rs
crates/hir_def/src/nameres.rs

index 4ddfd9ee6c82a72c041d3a54b0c74126439dd6e8..a8ee5eeac9f5498a6671785bda32f032c19d2c2f 100644 (file)
@@ -287,14 +287,25 @@ pub(crate) fn dump(&self, buf: &mut String) {
     }
 
     pub(crate) fn shrink_to_fit(&mut self) {
-        self.types.shrink_to_fit();
-        self.values.shrink_to_fit();
-        self.macros.shrink_to_fit();
-        self.unresolved.shrink_to_fit();
-        self.defs.shrink_to_fit();
-        self.impls.shrink_to_fit();
-        self.unnamed_trait_imports.shrink_to_fit();
-        self.legacy_macros.shrink_to_fit();
+        // Exhaustive match to require handling new fields.
+        let Self {
+            types,
+            values,
+            macros,
+            unresolved,
+            defs,
+            impls,
+            unnamed_trait_imports,
+            legacy_macros,
+        } = self;
+        types.shrink_to_fit();
+        values.shrink_to_fit();
+        macros.shrink_to_fit();
+        unresolved.shrink_to_fit();
+        defs.shrink_to_fit();
+        impls.shrink_to_fit();
+        unnamed_trait_imports.shrink_to_fit();
+        legacy_macros.shrink_to_fit();
     }
 }
 
index 6a09ad420b4de432c36ea56ac75143ad3b7a1af2..7dd68219fdefb5a07191c2c12eed24561e422534 100644 (file)
@@ -411,11 +411,25 @@ fn go(buf: &mut String, map: &DefMap, path: &str, module: LocalModuleId) {
     }
 
     fn shrink_to_fit(&mut self) {
-        self.extern_prelude.shrink_to_fit();
-        self.exported_proc_macros.shrink_to_fit();
-        self.diagnostics.shrink_to_fit();
-        self.modules.shrink_to_fit();
-        for (_, module) in self.modules.iter_mut() {
+        // Exhaustive match to require handling new fields.
+        let Self {
+            _c: _,
+            exported_proc_macros,
+            extern_prelude,
+            diagnostics,
+            modules,
+            block: _,
+            edition: _,
+            krate: _,
+            prelude: _,
+            root: _,
+        } = self;
+
+        extern_prelude.shrink_to_fit();
+        exported_proc_macros.shrink_to_fit();
+        diagnostics.shrink_to_fit();
+        modules.shrink_to_fit();
+        for (_, module) in modules.iter_mut() {
             module.children.shrink_to_fit();
             module.scope.shrink_to_fit();
         }