Skip to content

Commit dfc02d2

Browse files
Rollup merge of #127386 - compiler-errors:uplift-outlives-components, r=lcnr
Uplift outlives components to `rustc_type_ir` We need this to uplift `push_outlives_components`, since the elaborator uses `push_outlives_components` to elaborate type outlives obligations and I want to uplift elaboration. This ends up reworking and inlining a fair portion of the `GenericArg::walk_shallow` function, whose only callsite was this one. I believe I got the logic correct, but may be worthwhile to look at it closely just in case. Unfortunately github was too dumb to understand that this is a rename + change -- I could also rework the git history to split the "copy the file over" part from the actual logical changes if that makes this easier to review. r? lcnr
2 parents 8a8ad34 + c2a88ea commit dfc02d2

File tree

15 files changed

+373
-306
lines changed

15 files changed

+373
-306
lines changed

compiler/rustc_hir_analysis/src/outlives/utils.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use rustc_data_structures::fx::FxIndexMap;
2-
use rustc_infer::infer::outlives::components::{push_outlives_components, Component};
32
use rustc_middle::ty::{self, Region, Ty, TyCtxt};
43
use rustc_middle::ty::{GenericArg, GenericArgKind};
54
use rustc_middle::{bug, span_bug};
65
use rustc_span::Span;
6+
use rustc_type_ir::outlives::{push_outlives_components, Component};
77
use smallvec::smallvec;
88

99
/// Tracks the `T: 'a` or `'a: 'a` predicates that we have inferred

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

-266
This file was deleted.

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

-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use crate::infer::lexical_region_resolve;
88
use rustc_middle::traits::query::{NoSolution, OutlivesBound};
99
use rustc_middle::ty;
1010

11-
pub mod components;
1211
pub mod env;
1312
pub mod for_liveness;
1413
pub mod obligations;

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,6 @@
5959
//! might later infer `?U` to something like `&'b u32`, which would
6060
//! imply that `'b: 'a`.
6161
62-
use crate::infer::outlives::components::{push_outlives_components, Component};
6362
use crate::infer::outlives::env::RegionBoundPairs;
6463
use crate::infer::outlives::verify::VerifyBoundCx;
6564
use crate::infer::resolve::OpportunisticRegionResolver;
@@ -75,6 +74,7 @@ use rustc_middle::ty::{
7574
};
7675
use rustc_middle::ty::{GenericArgKind, PolyTypeOutlivesPredicate};
7776
use rustc_span::DUMMY_SP;
77+
use rustc_type_ir::outlives::{push_outlives_components, Component};
7878
use smallvec::smallvec;
7979

8080
use super::env::OutlivesEnvironment;
@@ -291,7 +291,7 @@ where
291291
fn components_must_outlive(
292292
&mut self,
293293
origin: infer::SubregionOrigin<'tcx>,
294-
components: &[Component<'tcx>],
294+
components: &[Component<TyCtxt<'tcx>>],
295295
region: ty::Region<'tcx>,
296296
category: ConstraintCategory<'tcx>,
297297
) {

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
use crate::infer::outlives::components::{compute_alias_components_recursive, Component};
21
use crate::infer::outlives::env::RegionBoundPairs;
32
use crate::infer::region_constraints::VerifyIfEq;
43
use crate::infer::{GenericKind, VerifyBound};
54
use rustc_data_structures::sso::SsoHashSet;
65
use rustc_middle::ty::GenericArg;
76
use rustc_middle::ty::{self, OutlivesPredicate, Ty, TyCtxt};
7+
use rustc_type_ir::outlives::{compute_alias_components_recursive, Component};
88

99
use smallvec::smallvec;
1010

@@ -139,7 +139,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
139139

140140
fn bound_from_components(
141141
&self,
142-
components: &[Component<'tcx>],
142+
components: &[Component<TyCtxt<'tcx>>],
143143
visited: &mut SsoHashSet<GenericArg<'tcx>>,
144144
) -> VerifyBound<'tcx> {
145145
let mut bounds = components
@@ -158,7 +158,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
158158

159159
fn bound_from_single_component(
160160
&self,
161-
component: &Component<'tcx>,
161+
component: &Component<TyCtxt<'tcx>>,
162162
visited: &mut SsoHashSet<GenericArg<'tcx>>,
163163
) -> VerifyBound<'tcx> {
164164
match *component {

compiler/rustc_infer/src/traits/util.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
use smallvec::smallvec;
22

3-
use crate::infer::outlives::components::{push_outlives_components, Component};
43
use crate::traits::{self, Obligation, ObligationCauseCode, PredicateObligation};
54
use rustc_data_structures::fx::FxHashSet;
65
use rustc_middle::ty::ToPolyTraitRef;
76
use rustc_middle::ty::{self, Ty, TyCtxt, Upcast};
87
use rustc_span::symbol::Ident;
98
use rustc_span::Span;
9+
use rustc_type_ir::outlives::{push_outlives_components, Component};
1010

1111
pub fn anonymize_predicate<'tcx>(
1212
tcx: TyCtxt<'tcx>,

compiler/rustc_middle/src/ty/consts/kind.rs

+7
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ pub struct Expr<'tcx> {
5454
pub kind: ExprKind,
5555
args: ty::GenericArgsRef<'tcx>,
5656
}
57+
58+
impl<'tcx> rustc_type_ir::inherent::ExprConst<TyCtxt<'tcx>> for Expr<'tcx> {
59+
fn args(self) -> ty::GenericArgsRef<'tcx> {
60+
self.args
61+
}
62+
}
63+
5764
impl<'tcx> Expr<'tcx> {
5865
pub fn new_binop(
5966
tcx: TyCtxt<'tcx>,

compiler/rustc_middle/src/ty/walk.rs

-17
Original file line numberDiff line numberDiff line change
@@ -78,23 +78,6 @@ impl<'tcx> GenericArg<'tcx> {
7878
pub fn walk(self) -> TypeWalker<'tcx> {
7979
TypeWalker::new(self)
8080
}
81-
82-
/// Iterator that walks the immediate children of `self`. Hence
83-
/// `Foo<Bar<i32>, u32>` yields the sequence `[Bar<i32>, u32]`
84-
/// (but not `i32`, like `walk`).
85-
///
86-
/// Iterator only walks items once.
87-
/// It accepts visited set, updates it with all visited types
88-
/// and skips any types that are already there.
89-
pub fn walk_shallow(
90-
self,
91-
visited: &mut SsoHashSet<GenericArg<'tcx>>,
92-
) -> impl Iterator<Item = GenericArg<'tcx>> {
93-
let mut stack = SmallVec::new();
94-
push_inner(&mut stack, self);
95-
stack.retain(|a| visited.insert(*a));
96-
stack.into_iter()
97-
}
9881
}
9982

10083
impl<'tcx> Ty<'tcx> {

0 commit comments

Comments
 (0)