Skip to content

Commit 2b5fd9a

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 15c701f commit 2b5fd9a

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

0 commit comments

Comments
 (0)