Skip to content

Commit b1964e6

Browse files
committed
Auto merge of #80163 - jackh726:binder-refactor-part-3, r=lcnr
Make BoundRegion have a kind of BoungRegionKind Split from #76814 Also includes making `replace_escaping_bound_vars` only return `T` Going to r? `@lcnr` Feel free to reassign
2 parents 29e3212 + 328fcee commit b1964e6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+183
-181
lines changed

compiler/rustc_codegen_cranelift/src/abi/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ pub(crate) fn fn_sig_for_fn_abi<'tcx>(tcx: TyCtxt<'tcx>, instance: Instance<'tcx
6464
ty::Generator(_, substs, _) => {
6565
let sig = substs.as_generator().poly_sig();
6666

67-
let env_region = ty::ReLateBound(ty::INNERMOST, ty::BrEnv);
67+
let env_region = ty::ReLateBound(ty::INNERMOST, ty::BoundRegion { kind: ty::BrEnv });
6868
let env_ty = tcx.mk_mut_ref(tcx.mk_region(env_region), ty);
6969

7070
let pin_did = tcx.require_lang_item(rustc_hir::LangItem::Pin, None);

compiler/rustc_infer/src/infer/canonical/canonicalizer.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,8 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
625625
r: ty::Region<'tcx>,
626626
) -> ty::Region<'tcx> {
627627
let var = self.canonical_var(info, r.into());
628-
let region = ty::ReLateBound(self.binder_index, ty::BoundRegion::BrAnon(var.as_u32()));
628+
let br = ty::BoundRegion { kind: ty::BrAnon(var.as_u32()) };
629+
let region = ty::ReLateBound(self.binder_index, br);
629630
self.tcx().mk_region(region)
630631
}
631632

compiler/rustc_infer/src/infer/canonical/substitute.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,6 @@ where
8787
c => bug!("{:?} is a const but value is {:?}", bound_ct, c),
8888
};
8989

90-
tcx.replace_escaping_bound_vars(value, fld_r, fld_t, fld_c).0
90+
tcx.replace_escaping_bound_vars(value, fld_r, fld_t, fld_c)
9191
}
9292
}

compiler/rustc_infer/src/infer/error_reporting/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,9 @@ fn msg_span_from_early_bound_and_free_regions(
165165
}
166166
(format!("the lifetime `{}` as defined on", br.name), sp)
167167
}
168-
ty::ReFree(ty::FreeRegion { bound_region: ty::BoundRegion::BrNamed(_, name), .. }) => {
168+
ty::ReFree(ty::FreeRegion {
169+
bound_region: ty::BoundRegionKind::BrNamed(_, name), ..
170+
}) => {
169171
let mut sp = sm.guess_head_span(tcx.hir().span(node));
170172
if let Some(param) =
171173
tcx.hir().get_generics(scope).and_then(|generics| generics.get_named(name))
@@ -2279,7 +2281,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
22792281
&self,
22802282
var_origin: RegionVariableOrigin,
22812283
) -> DiagnosticBuilder<'tcx> {
2282-
let br_string = |br: ty::BoundRegion| {
2284+
let br_string = |br: ty::BoundRegionKind| {
22832285
let mut s = match br {
22842286
ty::BrNamed(_, name) => name.to_string(),
22852287
_ => String::new(),

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/find_anon_type.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
2525
pub(super) fn find_anon_type(
2626
&self,
2727
region: Region<'tcx>,
28-
br: &ty::BoundRegion,
28+
br: &ty::BoundRegionKind,
2929
) -> Option<(&hir::Ty<'tcx>, &hir::FnDecl<'tcx>)> {
3030
if let Some(anon_reg) = self.tcx().is_suitable_region(region) {
3131
let hir_id = self.tcx().hir().local_def_id_to_hir_id(anon_reg.def_id);
@@ -56,7 +56,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
5656
fn find_component_for_bound_region(
5757
&self,
5858
arg: &'tcx hir::Ty<'tcx>,
59-
br: &ty::BoundRegion,
59+
br: &ty::BoundRegionKind,
6060
) -> Option<&'tcx hir::Ty<'tcx>> {
6161
let mut nested_visitor = FindNestedTypeVisitor {
6262
tcx: self.tcx(),
@@ -80,7 +80,7 @@ struct FindNestedTypeVisitor<'tcx> {
8080
tcx: TyCtxt<'tcx>,
8181
// The bound_region corresponding to the Refree(freeregion)
8282
// associated with the anonymous region we are looking for.
83-
bound_region: ty::BoundRegion,
83+
bound_region: ty::BoundRegionKind,
8484
// The type where the anonymous lifetime appears
8585
// for e.g., Vec<`&u8`> and <`&u8`>
8686
found_type: Option<&'tcx hir::Ty<'tcx>>,
@@ -207,7 +207,7 @@ impl Visitor<'tcx> for FindNestedTypeVisitor<'tcx> {
207207
struct TyPathVisitor<'tcx> {
208208
tcx: TyCtxt<'tcx>,
209209
found_it: bool,
210-
bound_region: ty::BoundRegion,
210+
bound_region: ty::BoundRegionKind,
211211
current_index: ty::DebruijnIndex,
212212
}
213213

compiler/rustc_infer/src/infer/error_reporting/nice_region_error/util.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ pub(super) struct AnonymousParamInfo<'tcx> {
1414
pub param: &'tcx hir::Param<'tcx>,
1515
/// The type corresponding to the anonymous region parameter.
1616
pub param_ty: Ty<'tcx>,
17-
/// The ty::BoundRegion corresponding to the anonymous region.
18-
pub bound_region: ty::BoundRegion,
17+
/// The ty::BoundRegionKind corresponding to the anonymous region.
18+
pub bound_region: ty::BoundRegionKind,
1919
/// The `Span` of the parameter type.
2020
pub param_ty_span: Span,
2121
/// Signals that the argument is the first parameter in the declaration.
@@ -43,7 +43,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
4343
ty::ReFree(ref free_region) => (free_region.scope, free_region.bound_region),
4444
ty::ReEarlyBound(ebr) => (
4545
self.tcx().parent(ebr.def_id).unwrap(),
46-
ty::BoundRegion::BrNamed(ebr.def_id, ebr.name),
46+
ty::BoundRegionKind::BrNamed(ebr.def_id, ebr.name),
4747
),
4848
_ => return None, // not a free region
4949
};
@@ -145,7 +145,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
145145
pub(super) fn is_return_type_anon(
146146
&self,
147147
scope_def_id: LocalDefId,
148-
br: ty::BoundRegion,
148+
br: ty::BoundRegionKind,
149149
decl: &hir::FnDecl<'_>,
150150
) -> Option<Span> {
151151
let ret_ty = self.tcx().type_of(scope_def_id);

compiler/rustc_infer/src/infer/higher_ranked/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,10 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
7777
// (i.e., if there are no placeholders).
7878
let next_universe = self.universe().next_universe();
7979

80-
let fld_r = |br| {
80+
let fld_r = |br: ty::BoundRegion| {
8181
self.tcx.mk_region(ty::RePlaceholder(ty::PlaceholderRegion {
8282
universe: next_universe,
83-
name: br,
83+
name: br.kind,
8484
}))
8585
};
8686

compiler/rustc_infer/src/infer/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ pub enum RegionVariableOrigin {
450450

451451
/// Region variables created for bound regions
452452
/// in a function or method that is called
453-
LateBoundRegion(Span, ty::BoundRegion, LateBoundRegionConversionTime),
453+
LateBoundRegion(Span, ty::BoundRegionKind, LateBoundRegionConversionTime),
454454

455455
UpvarRegion(ty::UpvarId, Span),
456456

@@ -1421,7 +1421,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
14211421
where
14221422
T: TypeFoldable<'tcx>,
14231423
{
1424-
let fld_r = |br| self.next_region_var(LateBoundRegion(span, br, lbrct));
1424+
let fld_r =
1425+
|br: ty::BoundRegion| self.next_region_var(LateBoundRegion(span, br.kind, lbrct));
14251426
let fld_t = |_| {
14261427
self.next_ty_var(TypeVariableOrigin {
14271428
kind: TypeVariableOriginKind::MiscVariable,

compiler/rustc_infer/src/infer/nll_relate/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ where
176176
universe
177177
});
178178

179-
let placeholder = ty::PlaceholderRegion { universe, name: br };
179+
let placeholder = ty::PlaceholderRegion { universe, name: br.kind };
180180
delegate.next_placeholder_region(placeholder)
181181
} else {
182182
delegate.next_existential_region_var(true)

compiler/rustc_middle/src/ich/impls_ty.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,16 +70,16 @@ impl<'a> HashStable<StableHashingContext<'a>> for ty::RegionKind {
7070
ty::ReEmpty(universe) => {
7171
universe.hash_stable(hcx, hasher);
7272
}
73-
ty::ReLateBound(db, ty::BrAnon(i)) => {
73+
ty::ReLateBound(db, ty::BoundRegion { kind: ty::BrAnon(i) }) => {
7474
db.hash_stable(hcx, hasher);
7575
i.hash_stable(hcx, hasher);
7676
}
77-
ty::ReLateBound(db, ty::BrNamed(def_id, name)) => {
77+
ty::ReLateBound(db, ty::BoundRegion { kind: ty::BrNamed(def_id, name) }) => {
7878
db.hash_stable(hcx, hasher);
7979
def_id.hash_stable(hcx, hasher);
8080
name.hash_stable(hcx, hasher);
8181
}
82-
ty::ReLateBound(db, ty::BrEnv) => {
82+
ty::ReLateBound(db, ty::BoundRegion { kind: ty::BrEnv }) => {
8383
db.hash_stable(hcx, hasher);
8484
}
8585
ty::ReEarlyBound(ty::EarlyBoundRegion { def_id, index, name }) => {

0 commit comments

Comments
 (0)