From 0a1f6dd8a8c27caf913a16eb0a1afeaa8183b983 Mon Sep 17 00:00:00 2001 From: Michael Woerister Date: Thu, 16 Nov 2017 18:07:49 +0100 Subject: [PATCH] Add doc comment for LocalDefId. --- src/librustc/hir/def_id.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/librustc/hir/def_id.rs b/src/librustc/hir/def_id.rs index 05d021ac6d2..f6fcff37ca5 100644 --- a/src/librustc/hir/def_id.rs +++ b/src/librustc/hir/def_id.rs @@ -198,7 +198,7 @@ impl DefId { self.krate == LOCAL_CRATE } - #[inline] + #[inline] pub fn to_local(self) -> LocalDefId { LocalDefId::from_def_id(self) } @@ -207,7 +207,12 @@ impl DefId { impl serialize::UseSpecializedEncodable for DefId {} impl serialize::UseSpecializedDecodable for DefId {} - +/// A LocalDefId is equivalent to a DefId with `krate == LOCAL_CRATE`. Since +/// we encode this information in the type, we can ensure at compile time that +/// no DefIds from upstream crates get thrown into the mix. There are quite a +/// few cases where we know that only DefIds from the local crate are expected +/// and a DefId from a different crate would signify a bug somewhere. This +/// is when LocalDefId comes in handy. #[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)] pub struct LocalDefId(DefIndex);