about summary refs log tree commit diff
path: root/src/librustdoc/clean/auto_trait.rs
diff options
context:
space:
mode:
authorNicholas Nethercote <n.nethercote@gmail.com>2025-07-25 20:34:36 +1000
committerNicholas Nethercote <n.nethercote@gmail.com>2025-07-31 20:04:51 +1000
commit066a973312066b792c5de4b41b92dcb437f22bac (patch)
treec23a8cdb7b9ca7579eb485cec461e80511b91f89 /src/librustdoc/clean/auto_trait.rs
parent75a1f47750fb34031f00cc2ee2b0d385426bec94 (diff)
downloadrust-066a973312066b792c5de4b41b92dcb437f22bac.tar.gz
rust-066a973312066b792c5de4b41b92dcb437f22bac.zip
Overhaul `Constraint`.
This commit changes it to store a `Region` instead of a `RegionVid` for the `Var` cases:
- We avoid having to call `Region::new_var` to re-create `Region`s from
  `RegionVid`s in a few places, avoiding the interning process, giving a
  small perf win. (At the cost of the type allowing some invalid
  combinations of values.)
- All the cases now store two `Region`s, so the commit also separates
  the `ConstraintKind` (a new type) from the `sub` and `sup` arguments
  in `Constraint`.
Diffstat (limited to 'src/librustdoc/clean/auto_trait.rs')
-rw-r--r--src/librustdoc/clean/auto_trait.rs40
1 files changed, 22 insertions, 18 deletions
diff --git a/src/librustdoc/clean/auto_trait.rs b/src/librustdoc/clean/auto_trait.rs
index a91ea55bcae..e6ac0270f78 100644
--- a/src/librustdoc/clean/auto_trait.rs
+++ b/src/librustdoc/clean/auto_trait.rs
@@ -1,6 +1,6 @@
 use rustc_data_structures::fx::{FxIndexMap, FxIndexSet, IndexEntry};
 use rustc_hir as hir;
-use rustc_infer::infer::region_constraints::{Constraint, RegionConstraintData};
+use rustc_infer::infer::region_constraints::{ConstraintKind, RegionConstraintData};
 use rustc_middle::bug;
 use rustc_middle::ty::{self, Region, Ty, fold_regions};
 use rustc_span::def_id::DefId;
@@ -233,31 +233,35 @@ fn clean_region_outlives_constraints<'tcx>(
     // Each `RegionTarget` (a `RegionVid` or a `Region`) maps to its smaller and larger regions.
     // Note that "larger" regions correspond to sub regions in the surface language.
     // E.g., in `'a: 'b`, `'a` is the larger region.
-    for (constraint, _) in &regions.constraints {
-        match *constraint {
-            Constraint::VarSubVar(vid1, vid2) => {
-                let deps1 = map.entry(RegionTarget::RegionVid(vid1)).or_default();
-                deps1.larger.insert(RegionTarget::RegionVid(vid2));
+    for (c, _) in &regions.constraints {
+        match c.kind {
+            ConstraintKind::VarSubVar => {
+                let sub_vid = c.sub.as_var();
+                let sup_vid = c.sup.as_var();
+                let deps1 = map.entry(RegionTarget::RegionVid(sub_vid)).or_default();
+                deps1.larger.insert(RegionTarget::RegionVid(sup_vid));
 
-                let deps2 = map.entry(RegionTarget::RegionVid(vid2)).or_default();
-                deps2.smaller.insert(RegionTarget::RegionVid(vid1));
+                let deps2 = map.entry(RegionTarget::RegionVid(sup_vid)).or_default();
+                deps2.smaller.insert(RegionTarget::RegionVid(sub_vid));
             }
-            Constraint::RegSubVar(region, vid) => {
-                let deps = map.entry(RegionTarget::RegionVid(vid)).or_default();
-                deps.smaller.insert(RegionTarget::Region(region));
+            ConstraintKind::RegSubVar => {
+                let sup_vid = c.sup.as_var();
+                let deps = map.entry(RegionTarget::RegionVid(sup_vid)).or_default();
+                deps.smaller.insert(RegionTarget::Region(c.sub));
             }
-            Constraint::VarSubReg(vid, region) => {
-                let deps = map.entry(RegionTarget::RegionVid(vid)).or_default();
-                deps.larger.insert(RegionTarget::Region(region));
+            ConstraintKind::VarSubReg => {
+                let sub_vid = c.sub.as_var();
+                let deps = map.entry(RegionTarget::RegionVid(sub_vid)).or_default();
+                deps.larger.insert(RegionTarget::Region(c.sup));
             }
-            Constraint::RegSubReg(r1, r2) => {
+            ConstraintKind::RegSubReg => {
                 // The constraint is already in the form that we want, so we're done with it
                 // The desired order is [larger, smaller], so flip them.
-                if early_bound_region_name(r1) != early_bound_region_name(r2) {
+                if early_bound_region_name(c.sub) != early_bound_region_name(c.sup) {
                     outlives_predicates
-                        .entry(early_bound_region_name(r2).expect("no region_name found"))
+                        .entry(early_bound_region_name(c.sup).expect("no region_name found"))
                         .or_default()
-                        .push(r1);
+                        .push(c.sub);
                 }
             }
         }