Skip to content

Commit bdfd78d

Browse files
Improve documentation for TypeckTables::validate_hir_id().
1 parent 4dcc3a4 commit bdfd78d

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/librustc/ty/context.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -396,8 +396,16 @@ impl<'tcx> TypeckTables<'tcx> {
396396
self.upvar_capture_map[&upvar_id]
397397
}
398398

399-
/// Validate that a NodeId can safely be converted to an ItemLocalId for
400-
/// this table.
399+
/// Validate that the given HirId (respectively its `local_id` part) can be
400+
/// safely used as a key in the tables of this TypeckTable. For that to be
401+
/// the case, the HirId must have the same `owner` as all the other IDs in
402+
/// this table (signified by the `local_id_root` field). Otherwise the HirId
403+
/// would be in a different frame of reference and using its `local_id`
404+
/// would result in lookup errors, or worse, in silently wrong data being
405+
/// stored/returned.
406+
///
407+
/// Therefore it is advised to call this method anytime before using a given
408+
/// HirId::local_id as a key.
401409
#[inline]
402410
pub fn validate_hir_id(&self, hir_id: hir::HirId) {
403411
#[cfg(debug_assertions)]

0 commit comments

Comments
 (0)