Skip to content

Commit e2eb89f

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 9c4ff56 commit e2eb89f

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

0 commit comments

Comments
 (0)