Skip to content

Commit 0a4507c

Browse files
committed
rustdoc_json: Add static asserts for the size of important types.
A lot of these are large! Lots of room for improvement in the future.
1 parent f9c15f4 commit 0a4507c

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/librustdoc/json/mod.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -382,3 +382,33 @@ impl<'tcx> FormatRenderer<'tcx> for JsonRenderer<'tcx> {
382382
&self.cache
383383
}
384384
}
385+
386+
// Some nodes are used a lot. Make sure they don't unintentionally get bigger.
387+
//
388+
// These assertions are here, not in `src/rustdoc-json-types/lib.rs` where the types are defined,
389+
// because we have access to `static_assert_size` here.
390+
#[cfg(target_pointer_width = "64")]
391+
mod size_asserts {
392+
use rustc_data_structures::static_assert_size;
393+
394+
use super::types::*;
395+
// tidy-alphabetical-start
396+
static_assert_size!(AssocItemConstraint, 208);
397+
static_assert_size!(Crate, 184);
398+
static_assert_size!(ExternalCrate, 48);
399+
static_assert_size!(FunctionPointer, 168);
400+
static_assert_size!(GenericArg, 80);
401+
static_assert_size!(GenericArgs, 104);
402+
static_assert_size!(GenericBound, 72);
403+
static_assert_size!(GenericParamDef, 136);
404+
static_assert_size!(Impl, 304);
405+
// `Item` contains a `PathBuf`, which is different sizes on different OSes.
406+
static_assert_size!(Item, 528 + size_of::<std::path::PathBuf>());
407+
static_assert_size!(ItemSummary, 32);
408+
static_assert_size!(PolyTrait, 64);
409+
static_assert_size!(PreciseCapturingArg, 32);
410+
static_assert_size!(TargetFeature, 80);
411+
static_assert_size!(Type, 80);
412+
static_assert_size!(WherePredicate, 160);
413+
// tidy-alphabetical-end
414+
}

0 commit comments

Comments
 (0)