Skip to content

Commit 84c1b90

Browse files
committed
Invert free region map edges in root assumptions
`FreeRegionMap::relation` stores `'sub <= 'sup` edges while `Assumptions::region_outlives` expects `'longer: 'shorter` ones. The mismatch is not yet observable as nothing reads the region relation at the root, but `Assumptions::new` merges edges derived from type outlives clauses into the same relation, which would otherwise leave it with mixed edge directions.
1 parent f4a1919 commit 84c1b90

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

compiler/rustc_infer/src/infer/outlives/obligations.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@
5959
//! might later infer `?U` to something like `&'b u32`, which would
6060
//! imply that `'b: 'a`.
6161
62-
use rustc_data_structures::transitive_relation::TransitiveRelation;
62+
use rustc_data_structures::transitive_relation::{TransitiveRelation, TransitiveRelationBuilder};
6363
use rustc_data_structures::undo_log::UndoLogs;
6464
use rustc_middle::bug;
6565
use rustc_middle::mir::ConstraintCategory;
@@ -234,14 +234,21 @@ impl<'tcx> InferCtxt<'tcx> {
234234
&self,
235235
outlives_env: &OutlivesEnvironment<'tcx>,
236236
) {
237+
// `FreeRegionMap::relation` stores `'sub <= 'sup` edges while
238+
// `Assumptions::region_outlives` expects `'longer: 'shorter` ones, so the
239+
// edges have to be inverted here.
240+
let mut region_outlives = TransitiveRelationBuilder::default();
241+
for (r1, r2) in outlives_env.free_region_map().relation.base_edges() {
242+
region_outlives.add(r2, r1);
243+
}
237244
let assumptions = rustc_type_ir::region_constraint::Assumptions::new(
238245
self.tcx,
239246
assumed_type_outlives(
240247
self.tcx,
241248
outlives_env.known_type_outlives(),
242249
outlives_env.region_bound_pairs(),
243250
),
244-
outlives_env.free_region_map().relation.clone(),
251+
region_outlives.freeze(),
245252
);
246253
self.destructure_solver_region_constraints(assumptions, self);
247254
}

0 commit comments

Comments
 (0)