Skip to content

Commit 0a1f6dd

Browse files
Add doc comment for LocalDefId.
1 parent 4c4f7a3 commit 0a1f6dd

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/librustc/hir/def_id.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ impl DefId {
198198
self.krate == LOCAL_CRATE
199199
}
200200

201-
#[inline]
201+
#[inline]
202202
pub fn to_local(self) -> LocalDefId {
203203
LocalDefId::from_def_id(self)
204204
}
@@ -207,7 +207,12 @@ impl DefId {
207207
impl serialize::UseSpecializedEncodable for DefId {}
208208
impl serialize::UseSpecializedDecodable for DefId {}
209209

210-
210+
/// A LocalDefId is equivalent to a DefId with `krate == LOCAL_CRATE`. Since
211+
/// we encode this information in the type, we can ensure at compile time that
212+
/// no DefIds from upstream crates get thrown into the mix. There are quite a
213+
/// few cases where we know that only DefIds from the local crate are expected
214+
/// and a DefId from a different crate would signify a bug somewhere. This
215+
/// is when LocalDefId comes in handy.
211216
#[derive(Clone, Copy, Eq, PartialEq, Ord, PartialOrd, Hash)]
212217
pub struct LocalDefId(DefIndex);
213218

0 commit comments

Comments
 (0)