Skip to content

Commit 470dcd7

Browse files
committed
Inline initialisation of RegionDefinition
1 parent 49541b2 commit 470dcd7

File tree

2 files changed

+12
-21
lines changed

2 files changed

+12
-21
lines changed

compiler/rustc_borrowck/src/eliminate_placeholders.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use rustc_data_structures::fx::FxIndexMap;
77
use rustc_data_structures::graph::scc;
88
use rustc_data_structures::graph::scc::Sccs;
99
use rustc_index::IndexVec;
10+
use rustc_infer::infer::RegionVariableOrigin;
1011
use rustc_middle::mir::ConstraintCategory;
1112
use rustc_middle::ty::{RegionVid, UniverseIndex};
1213
use tracing::debug;
@@ -154,12 +155,19 @@ fn region_definitions<'tcx>(
154155
let mut has_placeholders = false;
155156

156157
for info in var_infos.iter() {
157-
let definition = RegionDefinition::new(info);
158-
has_placeholders |= matches!(definition.origin, NllRegionVariableOrigin::Placeholder(_));
158+
let origin = match info.origin {
159+
RegionVariableOrigin::Nll(origin) => origin,
160+
_ => NllRegionVariableOrigin::Existential { from_forall: false },
161+
};
162+
163+
let definition = RegionDefinition { origin, universe: info.universe, external_name: None };
164+
165+
has_placeholders |= matches!(origin, NllRegionVariableOrigin::Placeholder(_));
159166
definitions.push(definition);
160167
}
161168

162169
// Add external names from universal regions in fun function definitions.
170+
// FIXME: this two-step method is annoying, but I don't know how to avoid it.
163171
for (external_name, variable) in universal_regions.named_universal_regions_iter() {
164172
debug!("region {:?} has external name {:?}", variable, external_name);
165173
definitions[variable].external_name = Some(external_name);

compiler/rustc_borrowck/src/region_infer/mod.rs

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,8 @@ use rustc_errors::Diag;
99
use rustc_hir::def_id::CRATE_DEF_ID;
1010
use rustc_index::IndexVec;
1111
use rustc_infer::infer::outlives::test_type_match;
12-
use rustc_infer::infer::region_constraints::{
13-
GenericKind, RegionVariableInfo, VerifyBound, VerifyIfEq,
14-
};
15-
use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin, RegionVariableOrigin};
12+
use rustc_infer::infer::region_constraints::{GenericKind, VerifyBound, VerifyIfEq};
13+
use rustc_infer::infer::{InferCtxt, NllRegionVariableOrigin};
1614
use rustc_middle::bug;
1715
use rustc_middle::mir::{
1816
AnnotationSource, BasicBlock, Body, ConstraintCategory, Local, Location, ReturnConstraint,
@@ -2143,21 +2141,6 @@ impl<'tcx> RegionInferenceContext<'tcx> {
21432141
}
21442142
}
21452143

2146-
impl<'tcx> RegionDefinition<'tcx> {
2147-
pub(crate) fn new(rv_info: &RegionVariableInfo) -> Self {
2148-
// Create a new region definition. Note that, for free
2149-
// regions, the `external_name` field gets updated later in
2150-
// [[crate::eliminate_placeholders]].
2151-
2152-
let origin = match rv_info.origin {
2153-
RegionVariableOrigin::Nll(origin) => origin,
2154-
_ => NllRegionVariableOrigin::Existential { from_forall: false },
2155-
};
2156-
2157-
Self { origin, universe: rv_info.universe, external_name: None }
2158-
}
2159-
}
2160-
21612144
#[derive(Clone, Debug)]
21622145
pub(crate) struct BlameConstraint<'tcx> {
21632146
pub category: ConstraintCategory<'tcx>,

0 commit comments

Comments
 (0)