From dca8ff5b252ce2430fa61e6a5bd230b1edc9ea50 Mon Sep 17 00:00:00 2001 From: bjorn3 Date: Thu, 3 Mar 2022 18:44:02 +0100 Subject: [PATCH] Prevent duplicate monomorphization of deserialization impls This reduces binary size from 9.7MiB (5.8MiB for just rustbuild code) to 9.3MiB (5.3MiB for just rustbuild code). This doesn't reduce compile time in a statistically significant way. --- src/bootstrap/config.rs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/bootstrap/config.rs b/src/bootstrap/config.rs index 762f18fb32f..6e8471b1de7 100644 --- a/src/bootstrap/config.rs +++ b/src/bootstrap/config.rs @@ -731,7 +731,11 @@ impl Config { let contents = t!(fs::read_to_string(file), format!("config file {} not found", file.display())); - match toml::from_str(&contents) { + // Deserialize to Value and then TomlConfig to prevent the Deserialize impl of + // TomlConfig and sub types to be monomorphized 5x by toml. + match toml::from_str(&contents) + .and_then(|table: toml::Value| TomlConfig::deserialize(table)) + { Ok(table) => table, Err(err) => { println!("failed to parse TOML configuration '{}': {}", file.display(), err);