Exhaustively handle fields in Drop for Cfg

This way it's no longer possible to forget to update this code when
adding new configuration fields into CFG.
This commit is contained in:
David Tolnay 2022-11-18 00:19:07 -08:00
parent 5b39d5eb25
commit f908cfa123
No known key found for this signature in database
GPG Key ID: F9BA143B95FF6D82

View File

@ -391,12 +391,19 @@ mod r#impl {
impl<'a> Drop for Cfg<'a> {
fn drop(&mut self) {
if let Cfg::Mut(cfg) = self {
if let Cfg::Mut(super::Cfg {
include_prefix,
exported_header_dirs,
exported_header_prefixes,
exported_header_links,
marker: _,
}) = self
{
let mut current = CURRENT.write().unwrap_or_else(PoisonError::into_inner);
current.include_prefix = intern(cfg.include_prefix);
current.exported_header_dirs = vec::intern(&cfg.exported_header_dirs);
current.exported_header_prefixes = vec::intern(&cfg.exported_header_prefixes);
current.exported_header_links = vec::intern(&cfg.exported_header_links);
current.include_prefix = intern(include_prefix);
current.exported_header_dirs = vec::intern(exported_header_dirs);
current.exported_header_prefixes = vec::intern(exported_header_prefixes);
current.exported_header_links = vec::intern(exported_header_links);
} else {
CONST_DEREFS.with(|derefs| derefs.borrow_mut().remove(&self.handle()));
}