Skip to content

Commit 34fb823

Browse files
committed
Remove span from BrAnon.
1 parent ded1a8b commit 34fb823

File tree

25 files changed

+57
-88
lines changed

25 files changed

+57
-88
lines changed

compiler/rustc_borrowck/src/diagnostics/region_name.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ impl<'tcx> MirBorrowckCtxt<'_, 'tcx> {
354354
})
355355
}
356356

357-
ty::BoundRegionKind::BrAnon(..) => None,
357+
ty::BoundRegionKind::BrAnon => None,
358358
},
359359

360360
ty::ReLateBound(..)

compiler/rustc_borrowck/src/renumber.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_middle::mir::visit::{MutVisitor, TyContext};
77
use rustc_middle::mir::{Body, ConstOperand, Location, Promoted};
88
use rustc_middle::ty::GenericArgsRef;
99
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable};
10-
use rustc_span::{Span, Symbol};
10+
use rustc_span::Symbol;
1111

1212
/// Replaces all free regions appearing in the MIR with fresh
1313
/// inference variables, returning the number of variables created.
@@ -28,21 +28,15 @@ pub fn renumber_mir<'tcx>(
2828
renumberer.visit_body(body);
2929
}
3030

31-
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
32-
pub(crate) enum BoundRegionInfo {
33-
Name(Symbol),
34-
Span(Span),
35-
}
36-
3731
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash)]
3832
pub(crate) enum RegionCtxt {
3933
Location(Location),
4034
TyContext(TyContext),
4135
Free(Symbol),
42-
Bound(BoundRegionInfo),
43-
LateBound(BoundRegionInfo),
36+
Bound(Symbol),
37+
LateBound(Symbol),
4438
Existential(Option<Symbol>),
45-
Placeholder(BoundRegionInfo),
39+
Placeholder(Symbol),
4640
Unknown,
4741
}
4842

compiler/rustc_borrowck/src/type_check/mod.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -1367,14 +1367,13 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
13671367
}
13681368
};
13691369
let (sig, map) = tcx.replace_late_bound_regions(sig, |br| {
1370-
use crate::renumber::{BoundRegionInfo, RegionCtxt};
1370+
use crate::renumber::RegionCtxt;
13711371

13721372
let region_ctxt_fn = || {
13731373
let reg_info = match br.kind {
1374-
ty::BoundRegionKind::BrAnon(Some(span)) => BoundRegionInfo::Span(span),
1375-
ty::BoundRegionKind::BrAnon(..) => BoundRegionInfo::Name(sym::anon),
1376-
ty::BoundRegionKind::BrNamed(_, name) => BoundRegionInfo::Name(name),
1377-
ty::BoundRegionKind::BrEnv => BoundRegionInfo::Name(sym::env),
1374+
ty::BoundRegionKind::BrAnon => sym::anon,
1375+
ty::BoundRegionKind::BrNamed(_, name) => name,
1376+
ty::BoundRegionKind::BrEnv => sym::env,
13781377
};
13791378

13801379
RegionCtxt::LateBound(reg_info)

compiler/rustc_borrowck/src/type_check/relate_tys.rs

+4-5
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_span::{Span, Symbol};
1111

1212
use crate::constraints::OutlivesConstraint;
1313
use crate::diagnostics::UniverseInfo;
14-
use crate::renumber::{BoundRegionInfo, RegionCtxt};
14+
use crate::renumber::RegionCtxt;
1515
use crate::type_check::{InstantiateOpaqueType, Locations, TypeChecker};
1616

1717
impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
@@ -126,10 +126,9 @@ impl<'tcx> TypeRelatingDelegate<'tcx> for NllTypeRelatingDelegate<'_, '_, 'tcx>
126126
.placeholder_region(self.type_checker.infcx, placeholder);
127127

128128
let reg_info = match placeholder.bound.kind {
129-
ty::BoundRegionKind::BrAnon(Some(span)) => BoundRegionInfo::Span(span),
130-
ty::BoundRegionKind::BrAnon(..) => BoundRegionInfo::Name(sym::anon),
131-
ty::BoundRegionKind::BrNamed(_, name) => BoundRegionInfo::Name(name),
132-
ty::BoundRegionKind::BrEnv => BoundRegionInfo::Name(sym::env),
129+
ty::BoundRegionKind::BrAnon => sym::anon,
130+
ty::BoundRegionKind::BrNamed(_, name) => name,
131+
ty::BoundRegionKind::BrEnv => sym::env,
133132
};
134133

135134
if cfg!(debug_assertions) {

compiler/rustc_borrowck/src/universal_regions.rs

+6-14
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use rustc_span::symbol::{kw, sym};
2828
use rustc_span::Symbol;
2929
use std::iter;
3030

31-
use crate::renumber::{BoundRegionInfo, RegionCtxt};
31+
use crate::renumber::RegionCtxt;
3232
use crate::BorrowckInferCtxt;
3333

3434
#[derive(Debug)]
@@ -446,9 +446,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
446446
if !indices.indices.contains_key(&r) {
447447
let region_vid = {
448448
let name = r.get_name_or_anon();
449-
self.infcx.next_nll_region_var(FR, || {
450-
RegionCtxt::LateBound(BoundRegionInfo::Name(name))
451-
})
449+
self.infcx.next_nll_region_var(FR, || RegionCtxt::LateBound(name))
452450
};
453451

454452
debug!(?region_vid);
@@ -480,9 +478,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
480478
if !indices.indices.contains_key(&r) {
481479
let region_vid = {
482480
let name = r.get_name_or_anon();
483-
self.infcx.next_nll_region_var(FR, || {
484-
RegionCtxt::LateBound(BoundRegionInfo::Name(name))
485-
})
481+
self.infcx.next_nll_region_var(FR, || RegionCtxt::LateBound(name))
486482
};
487483

488484
debug!(?region_vid);
@@ -796,7 +792,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> {
796792
_ => sym::anon,
797793
};
798794

799-
self.next_nll_region_var(origin, || RegionCtxt::Bound(BoundRegionInfo::Name(name)))
795+
self.next_nll_region_var(origin, || RegionCtxt::Bound(name))
800796
};
801797

802798
indices.insert_late_bound_region(liberated_region, region_vid.as_var());
@@ -826,9 +822,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> {
826822
if !indices.indices.contains_key(&r) {
827823
let region_vid = {
828824
let name = r.get_name_or_anon();
829-
self.next_nll_region_var(FR, || {
830-
RegionCtxt::LateBound(BoundRegionInfo::Name(name))
831-
})
825+
self.next_nll_region_var(FR, || RegionCtxt::LateBound(name))
832826
};
833827

834828
debug!(?region_vid);
@@ -848,9 +842,7 @@ impl<'cx, 'tcx> InferCtxtExt<'tcx> for BorrowckInferCtxt<'cx, 'tcx> {
848842
if !indices.indices.contains_key(&r) {
849843
let region_vid = {
850844
let name = r.get_name_or_anon();
851-
self.next_nll_region_var(FR, || {
852-
RegionCtxt::LateBound(BoundRegionInfo::Name(name))
853-
})
845+
self.next_nll_region_var(FR, || RegionCtxt::LateBound(name))
854846
};
855847

856848
indices.insert_late_bound_region(r, region_vid.as_var());

compiler/rustc_hir_analysis/src/astconv/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2781,15 +2781,15 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
27812781
) {
27822782
for br in referenced_regions.difference(&constrained_regions) {
27832783
let br_name = match *br {
2784-
ty::BrNamed(_, kw::UnderscoreLifetime) | ty::BrAnon(..) | ty::BrEnv => {
2784+
ty::BrNamed(_, kw::UnderscoreLifetime) | ty::BrAnon | ty::BrEnv => {
27852785
"an anonymous lifetime".to_string()
27862786
}
27872787
ty::BrNamed(_, name) => format!("lifetime `{name}`"),
27882788
};
27892789

27902790
let mut err = generate_err(&br_name);
27912791

2792-
if let ty::BrNamed(_, kw::UnderscoreLifetime) | ty::BrAnon(..) = *br {
2792+
if let ty::BrNamed(_, kw::UnderscoreLifetime) | ty::BrAnon = *br {
27932793
// The only way for an anonymous lifetime to wind up
27942794
// in the return type but **also** be unconstrained is
27952795
// if it only appears in "associated types" in the

compiler/rustc_hir_analysis/src/check/intrinsic.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,15 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
137137
let name_str = intrinsic_name.as_str();
138138

139139
let bound_vars = tcx.mk_bound_variable_kinds(&[
140-
ty::BoundVariableKind::Region(ty::BrAnon(None)),
140+
ty::BoundVariableKind::Region(ty::BrAnon),
141141
ty::BoundVariableKind::Region(ty::BrEnv),
142142
]);
143143
let mk_va_list_ty = |mutbl| {
144144
tcx.lang_items().va_list().map(|did| {
145145
let region = ty::Region::new_late_bound(
146146
tcx,
147147
ty::INNERMOST,
148-
ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon(None) },
148+
ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon },
149149
);
150150
let env_region = ty::Region::new_late_bound(
151151
tcx,
@@ -405,7 +405,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
405405
);
406406
let discriminant_def_id = assoc_items[0];
407407

408-
let br = ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon(None) };
408+
let br = ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon };
409409
(
410410
1,
411411
vec![Ty::new_imm_ref(
@@ -463,7 +463,7 @@ pub fn check_intrinsic_type(tcx: TyCtxt<'_>, it: &hir::ForeignItem<'_>) {
463463
}
464464

465465
sym::raw_eq => {
466-
let br = ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon(None) };
466+
let br = ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind: ty::BrAnon };
467467
let param_ty = Ty::new_imm_ref(
468468
tcx,
469469
ty::Region::new_late_bound(tcx, ty::INNERMOST, br),

compiler/rustc_infer/src/errors/note_and_explain.rs

+2-5
Original file line numberDiff line numberDiff line change
@@ -56,11 +56,8 @@ impl<'a> DescriptionCtx<'a> {
5656
(Some(span), "as_defined", name.to_string())
5757
}
5858
}
59-
ty::BrAnon(span) => {
60-
let span = match span {
61-
Some(_) => span,
62-
None => Some(tcx.def_span(scope)),
63-
};
59+
ty::BrAnon => {
60+
let span = Some(tcx.def_span(scope));
6461
(span, "defined_here", String::new())
6562
}
6663
_ => {

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ impl<'cx, 'tcx> Canonicalizer<'cx, 'tcx> {
775775
r: ty::Region<'tcx>,
776776
) -> ty::Region<'tcx> {
777777
let var = self.canonical_var(info, r.into());
778-
let br = ty::BoundRegion { var, kind: ty::BrAnon(None) };
778+
let br = ty::BoundRegion { var, kind: ty::BrAnon };
779779
ty::Region::new_late_bound(self.interner(), self.binder_index, br)
780780
}
781781

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

+3-10
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,9 @@ fn msg_span_from_named_region<'tcx>(
242242
};
243243
(text, Some(span))
244244
}
245-
ty::BrAnon(span) => (
245+
ty::BrAnon => (
246246
"the anonymous lifetime as defined here".to_string(),
247-
Some(match span {
248-
Some(span) => span,
249-
None => tcx.def_span(scope)
250-
})
247+
Some(tcx.def_span(scope))
251248
),
252249
_ => (
253250
format!("the lifetime `{region}` as defined here"),
@@ -262,11 +259,7 @@ fn msg_span_from_named_region<'tcx>(
262259
..
263260
}) => (format!("the lifetime `{name}` as defined here"), Some(tcx.def_span(def_id))),
264261
ty::RePlaceholder(ty::PlaceholderRegion {
265-
bound: ty::BoundRegion { kind: ty::BoundRegionKind::BrAnon(Some(span)), .. },
266-
..
267-
}) => ("the anonymous lifetime defined here".to_owned(), Some(span)),
268-
ty::RePlaceholder(ty::PlaceholderRegion {
269-
bound: ty::BoundRegion { kind: ty::BoundRegionKind::BrAnon(None), .. },
262+
bound: ty::BoundRegion { kind: ty::BoundRegionKind::BrAnon, .. },
270263
..
271264
}) => ("an anonymous lifetime".to_owned(), None),
272265
_ => bug!("{:?}", region),

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
6161
let is_impl_item = region_info.is_impl_item;
6262

6363
match br {
64-
ty::BrNamed(_, kw::UnderscoreLifetime) | ty::BrAnon(..) => {}
64+
ty::BrNamed(_, kw::UnderscoreLifetime) | ty::BrAnon => {}
6565
_ => {
6666
/* not an anonymous region */
6767
debug!("try_report_named_anon_conflict: not an anonymous region");

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

+2-4
Original file line numberDiff line numberDiff line change
@@ -36,15 +36,13 @@ impl<'tcx> NiceRegionError<'_, 'tcx> {
3636
ty::BrNamed(def_id, symbol) => {
3737
(Some(self.tcx().def_span(def_id)), Some(symbol))
3838
}
39-
ty::BrAnon(span) => (*span, None),
40-
ty::BrEnv => (None, None),
39+
ty::BrAnon | ty::BrEnv => (None, None),
4140
};
4241
let (sup_span, sup_symbol) = match sup_name {
4342
ty::BrNamed(def_id, symbol) => {
4443
(Some(self.tcx().def_span(def_id)), Some(symbol))
4544
}
46-
ty::BrAnon(span) => (*span, None),
47-
ty::BrEnv => (None, None),
45+
ty::BrAnon | ty::BrEnv => (None, None),
4846
};
4947
let diag = match (sub_span, sup_span, sub_symbol, sup_symbol) {
5048
(Some(sub_span), Some(sup_span), Some(&sub_symbol), Some(&sup_symbol)) => {

compiler/rustc_middle/src/infer/canonical.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ impl<'tcx> CanonicalVarValues<'tcx> {
455455
CanonicalVarKind::Region(_) | CanonicalVarKind::PlaceholderRegion(_) => {
456456
let br = ty::BoundRegion {
457457
var: ty::BoundVar::from_usize(i),
458-
kind: ty::BrAnon(None),
458+
kind: ty::BrAnon,
459459
};
460460
ty::Region::new_late_bound(tcx, ty::INNERMOST, br).into()
461461
}

compiler/rustc_middle/src/mir/query.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,7 @@ impl<'tcx> ClosureOutlivesSubjectTy<'tcx> {
414414
pub fn bind(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Self {
415415
let inner = tcx.fold_regions(ty, |r, depth| match r.kind() {
416416
ty::ReVar(vid) => {
417-
let br =
418-
ty::BoundRegion { var: ty::BoundVar::new(vid.index()), kind: ty::BrAnon(None) };
417+
let br = ty::BoundRegion { var: ty::BoundVar::new(vid.index()), kind: ty::BrAnon };
419418
ty::Region::new_late_bound(tcx, depth, br)
420419
}
421420
_ => bug!("unexpected region in ClosureOutlivesSubjectTy: {r:?}"),

compiler/rustc_middle/src/ty/context.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -318,7 +318,7 @@ pub struct CommonLifetimes<'tcx> {
318318
pub re_vars: Vec<Region<'tcx>>,
319319

320320
/// Pre-interned values of the form:
321-
/// `ReLateBound(DebruijnIndex(i), BoundRegion { var: v, kind: BrAnon(None) })`
321+
/// `ReLateBound(DebruijnIndex(i), BoundRegion { var: v, kind: BrAnon })`
322322
/// for small values of `i` and `v`.
323323
pub re_late_bounds: Vec<Vec<Region<'tcx>>>,
324324
}
@@ -395,7 +395,7 @@ impl<'tcx> CommonLifetimes<'tcx> {
395395
.map(|v| {
396396
mk(ty::ReLateBound(
397397
ty::DebruijnIndex::from(i),
398-
ty::BoundRegion { var: ty::BoundVar::from(v), kind: ty::BrAnon(None) },
398+
ty::BoundRegion { var: ty::BoundVar::from(v), kind: ty::BrAnon },
399399
))
400400
})
401401
.collect()

compiler/rustc_middle/src/ty/fold.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ impl<'tcx> TyCtxt<'tcx> {
385385
let index = entry.index();
386386
let var = ty::BoundVar::from_usize(index);
387387
let kind = entry
388-
.or_insert_with(|| ty::BoundVariableKind::Region(ty::BrAnon(None)))
388+
.or_insert_with(|| ty::BoundVariableKind::Region(ty::BrAnon))
389389
.expect_region();
390390
let br = ty::BoundRegion { var, kind };
391391
ty::Region::new_late_bound(self.tcx, ty::INNERMOST, br)

compiler/rustc_middle/src/ty/print/pretty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2330,7 +2330,7 @@ impl<'a, 'tcx> ty::TypeFolder<TyCtxt<'tcx>> for RegionFolder<'a, 'tcx> {
23302330
// If this is an anonymous placeholder, don't rename. Otherwise, in some
23312331
// async fns, we get a `for<'r> Send` bound
23322332
match kind {
2333-
ty::BrAnon(..) | ty::BrEnv => r,
2333+
ty::BrAnon | ty::BrEnv => r,
23342334
_ => {
23352335
// Index doesn't matter, since this is just for naming and these never get bound
23362336
let br = ty::BoundRegion { var: ty::BoundVar::from_u32(0), kind };
@@ -2451,7 +2451,7 @@ impl<'tcx> FmtPrinter<'_, 'tcx> {
24512451
binder_level_idx: ty::DebruijnIndex,
24522452
br: ty::BoundRegion| {
24532453
let (name, kind) = match br.kind {
2454-
ty::BrAnon(..) | ty::BrEnv => {
2454+
ty::BrAnon | ty::BrEnv => {
24552455
let name = next_name(&self);
24562456

24572457
if let Some(lt_idx) = lifetime_idx {

compiler/rustc_middle/src/ty/structural_impls.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl<'tcx> fmt::Debug for ty::adjustment::Adjustment<'tcx> {
6868
impl fmt::Debug for ty::BoundRegionKind {
6969
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
7070
match *self {
71-
ty::BrAnon(span) => write!(f, "BrAnon({span:?})"),
71+
ty::BrAnon => write!(f, "BrAnon"),
7272
ty::BrNamed(did, name) => {
7373
if did.is_crate_root() {
7474
write!(f, "BrNamed({name})")

compiler/rustc_middle/src/ty/sty.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ pub struct FreeRegion {
6969
#[derive(HashStable)]
7070
pub enum BoundRegionKind {
7171
/// An anonymous region parameter for a given fn (&T)
72-
BrAnon(Option<Span>),
72+
BrAnon,
7373

7474
/// Named region parameters for functions (a in &'a T)
7575
///
@@ -1465,7 +1465,7 @@ impl<'tcx> Region<'tcx> {
14651465
bound_region: ty::BoundRegion,
14661466
) -> Region<'tcx> {
14671467
// Use a pre-interned one when possible.
1468-
if let ty::BoundRegion { var, kind: ty::BrAnon(None) } = bound_region
1468+
if let ty::BoundRegion { var, kind: ty::BrAnon } = bound_region
14691469
&& let Some(inner) = tcx.lifetimes.re_late_bounds.get(debruijn.as_usize())
14701470
&& let Some(re) = inner.get(var.as_usize()).copied()
14711471
{
@@ -3010,7 +3010,7 @@ mod size_asserts {
30103010
use super::*;
30113011
use rustc_data_structures::static_assert_size;
30123012
// tidy-alphabetical-start
3013-
static_assert_size!(RegionKind<'_>, 28);
3013+
static_assert_size!(RegionKind<'_>, 24);
30143014
static_assert_size!(TyKind<'_>, 32);
30153015
// tidy-alphabetical-end
30163016
}

compiler/rustc_smir/src/rustc_smir/mod.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -979,13 +979,11 @@ impl<'tcx> Stable<'tcx> for ty::BoundTyKind {
979979
impl<'tcx> Stable<'tcx> for ty::BoundRegionKind {
980980
type T = stable_mir::ty::BoundRegionKind;
981981

982-
fn stable(&self, tables: &mut Tables<'tcx>) -> Self::T {
982+
fn stable(&self, _: &mut Tables<'tcx>) -> Self::T {
983983
use stable_mir::ty::BoundRegionKind;
984984

985985
match self {
986-
ty::BoundRegionKind::BrAnon(option_span) => {
987-
BoundRegionKind::BrAnon(option_span.map(|span| span.stable(tables)))
988-
}
986+
ty::BoundRegionKind::BrAnon => BoundRegionKind::BrAnon,
989987
ty::BoundRegionKind::BrNamed(def_id, symbol) => {
990988
BoundRegionKind::BrNamed(rustc_internal::br_named_def(*def_id), symbol.to_string())
991989
}

0 commit comments

Comments
 (0)