Skip to content

Commit f4bf64c

Browse files
authored
Rollup merge of rust-lang#97292 - compiler-errors:tcxify-rustc, r=davidtwco
Lifetime variance fixes for rustc rust-lang#97287 migrates rustc to a `Ty` type that is invariant over its lifetime `'tcx`, so I need to fix a bunch of places that assume that `Ty<'a>` and `Ty<'b>` can be unified by shortening both to some common lifetime. This is doable, since many lifetimes are already `'tcx`, so all this PR does is be a bit more explicit that elided lifetimes are actually `'tcx`. Split out from rust-lang#97287 so the compiler team can review independently.
2 parents 215722b + 1784634 commit f4bf64c

File tree

22 files changed

+92
-86
lines changed

22 files changed

+92
-86
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use either::Either;
22
use rustc_const_eval::util::CallKind;
3+
use rustc_data_structures::captures::Captures;
34
use rustc_data_structures::fx::FxHashSet;
45
use rustc_errors::{Applicability, Diagnostic, DiagnosticBuilder, ErrorGuaranteed, MultiSpan};
56
use rustc_hir as hir;
@@ -1622,10 +1623,10 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
16221623
location: Location,
16231624
mpi: MovePathIndex,
16241625
) -> (Vec<MoveSite>, Vec<Location>) {
1625-
fn predecessor_locations<'a>(
1626-
body: &'a mir::Body<'_>,
1626+
fn predecessor_locations<'tcx, 'a>(
1627+
body: &'a mir::Body<'tcx>,
16271628
location: Location,
1628-
) -> impl Iterator<Item = Location> + 'a {
1629+
) -> impl Iterator<Item = Location> + Captures<'tcx> + 'a {
16291630
if location.statement_index == 0 {
16301631
let predecessors = body.predecessors()[location.block].to_vec();
16311632
Either::Left(predecessors.into_iter().map(move |bb| body.terminator_loc(bb)))

compiler/rustc_borrowck/src/member_constraints.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
use rustc_data_structures::captures::Captures;
12
use rustc_data_structures::fx::FxHashMap;
23
use rustc_index::vec::IndexVec;
34
use rustc_middle::infer::MemberConstraint;
@@ -140,11 +141,13 @@ where
140141
}
141142
}
142143

143-
impl<R> MemberConstraintSet<'_, R>
144+
impl<'tcx, R> MemberConstraintSet<'tcx, R>
144145
where
145146
R: Copy + Hash + Eq,
146147
{
147-
pub(crate) fn all_indices(&self) -> impl Iterator<Item = NllMemberConstraintIndex> + '_ {
148+
pub(crate) fn all_indices(
149+
&self,
150+
) -> impl Iterator<Item = NllMemberConstraintIndex> + Captures<'tcx> + '_ {
148151
self.constraints.indices()
149152
}
150153

@@ -154,7 +157,7 @@ where
154157
pub(crate) fn indices(
155158
&self,
156159
member_region_vid: R,
157-
) -> impl Iterator<Item = NllMemberConstraintIndex> + '_ {
160+
) -> impl Iterator<Item = NllMemberConstraintIndex> + Captures<'tcx> + '_ {
158161
let mut next = self.first_constraints.get(&member_region_vid).cloned();
159162
std::iter::from_fn(move || -> Option<NllMemberConstraintIndex> {
160163
if let Some(current) = next {

compiler/rustc_borrowck/src/type_check/liveness/polonius.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@ use super::TypeChecker;
1010
type VarPointRelation = Vec<(Local, LocationIndex)>;
1111
type PathPointRelation = Vec<(MovePathIndex, LocationIndex)>;
1212

13-
struct UseFactsExtractor<'me> {
13+
struct UseFactsExtractor<'me, 'tcx> {
1414
var_defined_at: &'me mut VarPointRelation,
1515
var_used_at: &'me mut VarPointRelation,
1616
location_table: &'me LocationTable,
1717
var_dropped_at: &'me mut VarPointRelation,
18-
move_data: &'me MoveData<'me>,
18+
move_data: &'me MoveData<'tcx>,
1919
path_accessed_at_base: &'me mut PathPointRelation,
2020
}
2121

2222
// A Visitor to walk through the MIR and extract point-wise facts
23-
impl UseFactsExtractor<'_> {
23+
impl UseFactsExtractor<'_, '_> {
2424
fn location_to_index(&self, location: Location) -> LocationIndex {
2525
self.location_table.mid_index(location)
2626
}
@@ -53,7 +53,7 @@ impl UseFactsExtractor<'_> {
5353
}
5454
}
5555

56-
impl Visitor<'_> for UseFactsExtractor<'_> {
56+
impl<'a, 'tcx> Visitor<'tcx> for UseFactsExtractor<'a, 'tcx> {
5757
fn visit_local(&mut self, &local: &Local, context: PlaceContext, location: Location) {
5858
match def_use::categorize(context) {
5959
Some(DefUse::Def) => self.insert_def(local, location),
@@ -63,7 +63,7 @@ impl Visitor<'_> for UseFactsExtractor<'_> {
6363
}
6464
}
6565

66-
fn visit_place(&mut self, place: &Place<'_>, context: PlaceContext, location: Location) {
66+
fn visit_place(&mut self, place: &Place<'tcx>, context: PlaceContext, location: Location) {
6767
self.super_place(place, context, location);
6868
match context {
6969
PlaceContext::NonMutatingUse(_) => {
@@ -82,11 +82,11 @@ impl Visitor<'_> for UseFactsExtractor<'_> {
8282
}
8383
}
8484

85-
pub(super) fn populate_access_facts<'tcx>(
86-
typeck: &mut TypeChecker<'_, 'tcx>,
85+
pub(super) fn populate_access_facts<'a, 'tcx>(
86+
typeck: &mut TypeChecker<'a, 'tcx>,
8787
body: &Body<'tcx>,
8888
location_table: &LocationTable,
89-
move_data: &MoveData<'_>,
89+
move_data: &MoveData<'tcx>,
9090
dropped_at: &mut Vec<(Local, Location)>,
9191
) {
9292
debug!("populate_access_facts()");

compiler/rustc_const_eval/src/interpret/memory.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
197197
size: Size,
198198
align: Align,
199199
kind: MemoryKind<M::MemoryKind>,
200-
) -> InterpResult<'static, Pointer<M::PointerTag>> {
200+
) -> InterpResult<'tcx, Pointer<M::PointerTag>> {
201201
let alloc = Allocation::uninit(size, align, M::PANIC_ON_ALLOC_FAIL)?;
202202
Ok(self.allocate_raw_ptr(alloc, kind))
203203
}
@@ -402,7 +402,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
402402
msg: CheckInAllocMsg,
403403
alloc_size: impl FnOnce(AllocId, Size, M::TagExtra) -> InterpResult<'tcx, (Size, Align, T)>,
404404
) -> InterpResult<'tcx, Option<T>> {
405-
fn check_offset_align(offset: u64, align: Align) -> InterpResult<'static> {
405+
fn check_offset_align<'tcx>(offset: u64, align: Align) -> InterpResult<'tcx> {
406406
if offset % align.bytes() == 0 {
407407
Ok(())
408408
} else {
@@ -654,7 +654,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
654654
&self,
655655
id: AllocId,
656656
liveness: AllocCheck,
657-
) -> InterpResult<'static, (Size, Align)> {
657+
) -> InterpResult<'tcx, (Size, Align)> {
658658
// # Regular allocations
659659
// Don't use `self.get_raw` here as that will
660660
// a) cause cycles in case `id` refers to a static

compiler/rustc_const_eval/src/interpret/place.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1011,7 +1011,7 @@ where
10111011
&mut self,
10121012
layout: TyAndLayout<'tcx>,
10131013
kind: MemoryKind<M::MemoryKind>,
1014-
) -> InterpResult<'static, MPlaceTy<'tcx, M::PointerTag>> {
1014+
) -> InterpResult<'tcx, MPlaceTy<'tcx, M::PointerTag>> {
10151015
let ptr = self.allocate_ptr(layout.size, layout.align.abi, kind)?;
10161016
Ok(MPlaceTy::from_aligned_ptr(ptr.into(), layout))
10171017
}

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl<'a, 'tcx> NiceRegionError<'a, 'tcx> {
9898
&self,
9999
anon_region: Region<'tcx>,
100100
replace_region: Region<'tcx>,
101-
) -> Option<AnonymousParamInfo<'_>> {
101+
) -> Option<AnonymousParamInfo<'tcx>> {
102102
find_param_with_region(self.tcx(), anon_region, replace_region)
103103
}
104104

compiler/rustc_middle/src/mir/interpret/allocation.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ impl<Tag> Allocation<Tag> {
171171

172172
/// Try to create an Allocation of `size` bytes, failing if there is not enough memory
173173
/// available to the compiler to do so.
174-
pub fn uninit(size: Size, align: Align, panic_on_fail: bool) -> InterpResult<'static, Self> {
174+
pub fn uninit<'tcx>(size: Size, align: Align, panic_on_fail: bool) -> InterpResult<'tcx, Self> {
175175
let bytes = Box::<[u8]>::try_new_zeroed_slice(size.bytes_usize()).map_err(|_| {
176176
// This results in an error that can happen non-deterministically, since the memory
177177
// available to the compiler can change between runs. Normally queries are always

compiler/rustc_middle/src/mir/interpret/value.rs

+17-17
Original file line numberDiff line numberDiff line change
@@ -397,90 +397,90 @@ impl<'tcx, Tag: Provenance> Scalar<Tag> {
397397
/// Converts the scalar to produce an unsigned integer of the given size.
398398
/// Fails if the scalar is a pointer.
399399
#[inline]
400-
pub fn to_uint(self, size: Size) -> InterpResult<'static, u128> {
400+
pub fn to_uint(self, size: Size) -> InterpResult<'tcx, u128> {
401401
self.to_bits(size)
402402
}
403403

404404
/// Converts the scalar to produce a `u8`. Fails if the scalar is a pointer.
405-
pub fn to_u8(self) -> InterpResult<'static, u8> {
405+
pub fn to_u8(self) -> InterpResult<'tcx, u8> {
406406
self.to_uint(Size::from_bits(8)).map(|v| u8::try_from(v).unwrap())
407407
}
408408

409409
/// Converts the scalar to produce a `u16`. Fails if the scalar is a pointer.
410-
pub fn to_u16(self) -> InterpResult<'static, u16> {
410+
pub fn to_u16(self) -> InterpResult<'tcx, u16> {
411411
self.to_uint(Size::from_bits(16)).map(|v| u16::try_from(v).unwrap())
412412
}
413413

414414
/// Converts the scalar to produce a `u32`. Fails if the scalar is a pointer.
415-
pub fn to_u32(self) -> InterpResult<'static, u32> {
415+
pub fn to_u32(self) -> InterpResult<'tcx, u32> {
416416
self.to_uint(Size::from_bits(32)).map(|v| u32::try_from(v).unwrap())
417417
}
418418

419419
/// Converts the scalar to produce a `u64`. Fails if the scalar is a pointer.
420-
pub fn to_u64(self) -> InterpResult<'static, u64> {
420+
pub fn to_u64(self) -> InterpResult<'tcx, u64> {
421421
self.to_uint(Size::from_bits(64)).map(|v| u64::try_from(v).unwrap())
422422
}
423423

424424
/// Converts the scalar to produce a `u128`. Fails if the scalar is a pointer.
425-
pub fn to_u128(self) -> InterpResult<'static, u128> {
425+
pub fn to_u128(self) -> InterpResult<'tcx, u128> {
426426
self.to_uint(Size::from_bits(128))
427427
}
428428

429429
/// Converts the scalar to produce a machine-pointer-sized unsigned integer.
430430
/// Fails if the scalar is a pointer.
431-
pub fn to_machine_usize(self, cx: &impl HasDataLayout) -> InterpResult<'static, u64> {
431+
pub fn to_machine_usize(self, cx: &impl HasDataLayout) -> InterpResult<'tcx, u64> {
432432
let b = self.to_uint(cx.data_layout().pointer_size)?;
433433
Ok(u64::try_from(b).unwrap())
434434
}
435435

436436
/// Converts the scalar to produce a signed integer of the given size.
437437
/// Fails if the scalar is a pointer.
438438
#[inline]
439-
pub fn to_int(self, size: Size) -> InterpResult<'static, i128> {
439+
pub fn to_int(self, size: Size) -> InterpResult<'tcx, i128> {
440440
let b = self.to_bits(size)?;
441441
Ok(size.sign_extend(b) as i128)
442442
}
443443

444444
/// Converts the scalar to produce an `i8`. Fails if the scalar is a pointer.
445-
pub fn to_i8(self) -> InterpResult<'static, i8> {
445+
pub fn to_i8(self) -> InterpResult<'tcx, i8> {
446446
self.to_int(Size::from_bits(8)).map(|v| i8::try_from(v).unwrap())
447447
}
448448

449449
/// Converts the scalar to produce an `i16`. Fails if the scalar is a pointer.
450-
pub fn to_i16(self) -> InterpResult<'static, i16> {
450+
pub fn to_i16(self) -> InterpResult<'tcx, i16> {
451451
self.to_int(Size::from_bits(16)).map(|v| i16::try_from(v).unwrap())
452452
}
453453

454454
/// Converts the scalar to produce an `i32`. Fails if the scalar is a pointer.
455-
pub fn to_i32(self) -> InterpResult<'static, i32> {
455+
pub fn to_i32(self) -> InterpResult<'tcx, i32> {
456456
self.to_int(Size::from_bits(32)).map(|v| i32::try_from(v).unwrap())
457457
}
458458

459459
/// Converts the scalar to produce an `i64`. Fails if the scalar is a pointer.
460-
pub fn to_i64(self) -> InterpResult<'static, i64> {
460+
pub fn to_i64(self) -> InterpResult<'tcx, i64> {
461461
self.to_int(Size::from_bits(64)).map(|v| i64::try_from(v).unwrap())
462462
}
463463

464464
/// Converts the scalar to produce an `i128`. Fails if the scalar is a pointer.
465-
pub fn to_i128(self) -> InterpResult<'static, i128> {
465+
pub fn to_i128(self) -> InterpResult<'tcx, i128> {
466466
self.to_int(Size::from_bits(128))
467467
}
468468

469469
/// Converts the scalar to produce a machine-pointer-sized signed integer.
470470
/// Fails if the scalar is a pointer.
471-
pub fn to_machine_isize(self, cx: &impl HasDataLayout) -> InterpResult<'static, i64> {
471+
pub fn to_machine_isize(self, cx: &impl HasDataLayout) -> InterpResult<'tcx, i64> {
472472
let b = self.to_int(cx.data_layout().pointer_size)?;
473473
Ok(i64::try_from(b).unwrap())
474474
}
475475

476476
#[inline]
477-
pub fn to_f32(self) -> InterpResult<'static, Single> {
477+
pub fn to_f32(self) -> InterpResult<'tcx, Single> {
478478
// Going through `u32` to check size and truncation.
479479
Ok(Single::from_bits(self.to_u32()?.into()))
480480
}
481481

482482
#[inline]
483-
pub fn to_f64(self) -> InterpResult<'static, Double> {
483+
pub fn to_f64(self) -> InterpResult<'tcx, Double> {
484484
// Going through `u64` to check size and truncation.
485485
Ok(Double::from_bits(self.to_u64()?.into()))
486486
}
@@ -534,7 +534,7 @@ impl<Tag> ScalarMaybeUninit<Tag> {
534534
}
535535

536536
#[inline]
537-
pub fn check_init(self) -> InterpResult<'static, Scalar<Tag>> {
537+
pub fn check_init<'tcx>(self) -> InterpResult<'tcx, Scalar<Tag>> {
538538
match self {
539539
ScalarMaybeUninit::Scalar(scalar) => Ok(scalar),
540540
ScalarMaybeUninit::Uninit => throw_ub!(InvalidUninitBytes(None)),

compiler/rustc_middle/src/mir/mod.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ use crate::ty::subst::{GenericArg, InternalSubsts, Subst, SubstsRef};
1313
use crate::ty::{self, List, Ty, TyCtxt};
1414
use crate::ty::{AdtDef, InstanceDef, Region, ScalarInt, UserTypeAnnotationIndex};
1515

16+
use rustc_data_structures::captures::Captures;
1617
use rustc_errors::ErrorGuaranteed;
1718
use rustc_hir::def::{CtorKind, Namespace};
1819
use rustc_hir::def_id::{DefId, LocalDefId, CRATE_DEF_ID};
@@ -484,7 +485,7 @@ impl<'tcx> Body<'tcx> {
484485

485486
/// Returns an iterator over all user-declared mutable locals.
486487
#[inline]
487-
pub fn mut_vars_iter<'a>(&'a self) -> impl Iterator<Item = Local> + 'a {
488+
pub fn mut_vars_iter<'a>(&'a self) -> impl Iterator<Item = Local> + Captures<'tcx> + 'a {
488489
(self.arg_count + 1..self.local_decls.len()).filter_map(move |index| {
489490
let local = Local::new(index);
490491
let decl = &self.local_decls[local];
@@ -498,7 +499,9 @@ impl<'tcx> Body<'tcx> {
498499

499500
/// Returns an iterator over all user-declared mutable arguments and locals.
500501
#[inline]
501-
pub fn mut_vars_and_args_iter<'a>(&'a self) -> impl Iterator<Item = Local> + 'a {
502+
pub fn mut_vars_and_args_iter<'a>(
503+
&'a self,
504+
) -> impl Iterator<Item = Local> + Captures<'tcx> + 'a {
502505
(1..self.local_decls.len()).filter_map(move |index| {
503506
let local = Local::new(index);
504507
let decl = &self.local_decls[local];

compiler/rustc_middle/src/mir/patch.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ impl<'tcx> MirPatch<'tcx> {
192192
}
193193
}
194194

195-
pub fn source_info_for_location(&self, body: &Body<'_>, loc: Location) -> SourceInfo {
195+
pub fn source_info_for_location(&self, body: &Body<'tcx>, loc: Location) -> SourceInfo {
196196
let data = match loc.block.index().checked_sub(body.basic_blocks().len()) {
197197
Some(new) => &self.new_blocks[new],
198198
None => &body[loc.block],

compiler/rustc_middle/src/traits/mod.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,6 @@ impl Hash for ObligationCause<'_> {
115115
}
116116
}
117117

118-
const MISC_OBLIGATION_CAUSE_CODE: ObligationCauseCode<'static> = MiscObligation;
119-
120118
impl<'tcx> ObligationCause<'tcx> {
121119
#[inline]
122120
pub fn new(
@@ -201,7 +199,7 @@ pub struct UnifyReceiverContext<'tcx> {
201199

202200
#[derive(Clone, Debug, PartialEq, Eq, Hash, Lift, Default)]
203201
pub struct InternedObligationCauseCode<'tcx> {
204-
/// `None` for `MISC_OBLIGATION_CAUSE_CODE` (a common case, occurs ~60% of
202+
/// `None` for `ObligationCauseCode::MiscObligation` (a common case, occurs ~60% of
205203
/// the time). `Some` otherwise.
206204
code: Option<Lrc<ObligationCauseCode<'tcx>>>,
207205
}
@@ -210,7 +208,11 @@ impl<'tcx> ObligationCauseCode<'tcx> {
210208
#[inline(always)]
211209
fn into(self) -> InternedObligationCauseCode<'tcx> {
212210
InternedObligationCauseCode {
213-
code: if let MISC_OBLIGATION_CAUSE_CODE = self { None } else { Some(Lrc::new(self)) },
211+
code: if let ObligationCauseCode::MiscObligation = self {
212+
None
213+
} else {
214+
Some(Lrc::new(self))
215+
},
214216
}
215217
}
216218
}
@@ -219,7 +221,7 @@ impl<'tcx> std::ops::Deref for InternedObligationCauseCode<'tcx> {
219221
type Target = ObligationCauseCode<'tcx>;
220222

221223
fn deref(&self) -> &Self::Target {
222-
self.code.as_deref().unwrap_or(&MISC_OBLIGATION_CAUSE_CODE)
224+
self.code.as_deref().unwrap_or(&ObligationCauseCode::MiscObligation)
223225
}
224226
}
225227

compiler/rustc_middle/src/ty/layout.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2163,7 +2163,7 @@ impl<'tcx> SizeSkeleton<'tcx> {
21632163
}
21642164
}
21652165

2166-
pub fn same_size(self, other: SizeSkeleton<'_>) -> bool {
2166+
pub fn same_size(self, other: SizeSkeleton<'tcx>) -> bool {
21672167
match (self, other) {
21682168
(SizeSkeleton::Known(a), SizeSkeleton::Known(b)) => a == b,
21692169
(SizeSkeleton::Pointer { tail: a, .. }, SizeSkeleton::Pointer { tail: b, .. }) => {

0 commit comments

Comments
 (0)