From 92479aca5b106a0b2863ecf4def3becf2997460c Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Tue, 21 Apr 2026 20:33:44 +0300 Subject: [PATCH] rustc_middle: Optimize `DefId` comparisons --- compiler/rustc_middle/src/ty/mod.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/compiler/rustc_middle/src/ty/mod.rs b/compiler/rustc_middle/src/ty/mod.rs index 56a7abfac6635..89a8a45b81914 100644 --- a/compiler/rustc_middle/src/ty/mod.rs +++ b/compiler/rustc_middle/src/ty/mod.rs @@ -338,7 +338,9 @@ impl TyCtxt<'_> { } pub fn is_descendant_of(self, mut descendant: DefId, ancestor: DefId) -> bool { - if descendant.krate != ancestor.krate { + // Def-ids from different crates are always unordered, and def-ids of parent nodes + // are always created before def-ids of child nodes. + if descendant.krate != ancestor.krate || descendant.index < ancestor.index { return false; }