Skip to content

Commit 15c5ff4

Browse files
committed
make lifetime methods more consistent
1 parent 0439230 commit 15c5ff4

13 files changed

Lines changed: 45 additions & 33 deletions

File tree

compiler/rustc_hir_typeck/src/expectation.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ impl<'a, 'tcx> Expectation<'tcx> {
9595
NoExpectation => NoExpectation,
9696
ExpectCastableToType(t) => ExpectCastableToType(fcx.deep_resolve_non_region_vars(t)),
9797
ExpectHasType(t) => ExpectHasType(fcx.deep_resolve_non_region_vars(t)),
98-
ExpectRvalueLikeUnsized(t) => ExpectRvalueLikeUnsized(fcx.deep_resolve_non_region_vars(t)),
98+
ExpectRvalueLikeUnsized(t) => {
99+
ExpectRvalueLikeUnsized(fcx.deep_resolve_non_region_vars(t))
100+
}
99101
}
100102
}
101103

compiler/rustc_hir_typeck/src/fn_ctxt/_impl.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
199199

200200
#[inline]
201201
pub(crate) fn write_ty(&self, id: HirId, ty: Ty<'tcx>) {
202-
debug!("write_ty({:?}, {:?}) in fcx {}", id, self.deep_resolve_non_region_vars(ty), self.tag());
202+
debug!(
203+
"write_ty({:?}, {:?}) in fcx {}",
204+
id,
205+
self.deep_resolve_non_region_vars(ty),
206+
self.tag()
207+
);
203208
let mut typeck = self.typeck_results.borrow_mut();
204209
let mut node_ty = typeck.node_types_mut();
205210

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1860,7 +1860,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
18601860
format!(
18611861
"{deps_list} need{} to match the {} type of this parameter",
18621862
pluralize!((deps.len() != 1) as u32),
1863-
self.deep_resolve_non_region_vars(expected_ty).sort_string(self.tcx),
1863+
self.deep_resolve_non_region_vars(expected_ty)
1864+
.sort_string(self.tcx),
18641865
),
18651866
);
18661867
}
@@ -3332,7 +3333,10 @@ impl<'a, 'tcx> ArgsCtxt<'a, 'tcx> {
33323333
.borrow()
33333334
.expr_ty_adjusted_opt(expr)
33343335
.unwrap_or_else(|| Ty::new_misc_error(self.call_ctxt.fn_ctxt.tcx));
3335-
(self.call_ctxt.fn_ctxt.deep_resolve_non_region_vars(ty), self.normalize_span(expr.span))
3336+
(
3337+
self.call_ctxt.fn_ctxt.deep_resolve_non_region_vars(ty),
3338+
self.normalize_span(expr.span),
3339+
)
33363340
})
33373341
.collect()
33383342
}

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -991,7 +991,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
991991
return false;
992992
}
993993

994-
let found = self.resolve_numeric_literals_with_default(self.deep_resolve_non_region_vars(found));
994+
let found =
995+
self.resolve_numeric_literals_with_default(self.deep_resolve_non_region_vars(found));
995996
// Only suggest changing the return type for methods that
996997
// haven't set a return type at all (and aren't `fn main()`, impl or closure).
997998
match &fn_decl.output {

compiler/rustc_infer/src/infer/context.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,14 @@ impl<'tcx> rustc_type_ir::InferCtxtLike for InferCtxt<'tcx> {
8686
}
8787
}
8888

89-
fn universe_of_lt(&self, lt: ty::RegionVid) -> Option<ty::UniverseIndex> {
89+
fn universe_of_region(&self, lt: ty::RegionVid) -> Option<ty::UniverseIndex> {
9090
match self.inner.borrow_mut().unwrap_region_constraints().try_resolve_region_var(lt) {
9191
Err(universe) => Some(universe),
9292
Ok(_) => None,
9393
}
9494
}
9595

96-
fn universe_of_ct(&self, ct: ty::ConstVid) -> Option<ty::UniverseIndex> {
96+
fn universe_of_const(&self, ct: ty::ConstVid) -> Option<ty::UniverseIndex> {
9797
match self.try_resolve_const_var(ct) {
9898
Err(universe) => Some(universe),
9999
Ok(_) => None,
@@ -135,13 +135,10 @@ impl<'tcx> rustc_type_ir::InferCtxtLike for InferCtxt<'tcx> {
135135
}
136136

137137
fn shallow_resolve_const_var(&self, vid: ty::ConstVid) -> ty::Const<'tcx> {
138-
match self.try_resolve_const_var(vid) {
139-
Ok(ct) => ct,
140-
Err(_) => ty::Const::new_var(self.tcx, self.root_const_var(vid)),
141-
}
138+
self.shallow_resolve_const_var(vid)
142139
}
143140

144-
fn opportunistic_resolve_lt_var(&self, vid: ty::RegionVid) -> ty::Region<'tcx> {
141+
fn shallow_resolve_region_var(&self, vid: ty::RegionVid) -> ty::Region<'tcx> {
145142
self.inner
146143
.borrow_mut()
147144
.unwrap_region_constraints()

compiler/rustc_next_trait_solver/src/canonical/canonicalizer.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> TypeFolder<I> for Canonicaliz
470470

471471
ty::ReVar(vid) => {
472472
debug_assert_eq!(
473-
self.delegate.opportunistic_resolve_lt_var(vid),
473+
self.delegate.shallow_resolve_region_var(vid),
474474
r,
475475
"region vid should have been resolved fully before canonicalization"
476476
);
@@ -482,7 +482,7 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> TypeFolder<I> for Canonicaliz
482482
))
483483
}
484484
CanonicalizeMode::Response { .. } => {
485-
CanonicalVarKind::Region(self.delegate.universe_of_lt(vid).unwrap())
485+
CanonicalVarKind::Region(self.delegate.universe_of_region(vid).unwrap())
486486
}
487487
}
488488
}
@@ -525,7 +525,7 @@ impl<D: SolverDelegate<Interner = I>, I: Interner> TypeFolder<I> for Canonicaliz
525525
CanonicalVarKind::Const(ty::UniverseIndex::ROOT)
526526
}
527527
CanonicalizeMode::Response { .. } => {
528-
CanonicalVarKind::Const(self.delegate.universe_of_ct(vid).unwrap())
528+
CanonicalVarKind::Const(self.delegate.universe_of_const(vid).unwrap())
529529
}
530530
}
531531
}

compiler/rustc_next_trait_solver/src/placeholder.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ where
248248

249249
fn fold_region(&mut self, r0: Region<I>) -> Region<I> {
250250
let r1 = match r0.kind() {
251-
ty::ReVar(vid) => self.infcx.opportunistic_resolve_lt_var(vid),
251+
ty::ReVar(vid) => self.infcx.shallow_resolve_region_var(vid),
252252
_ => r0,
253253
};
254254

compiler/rustc_next_trait_solver/src/solve/eval_ctxt/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1094,7 +1094,7 @@ where
10941094
}
10951095
ty::TermKind::Const(ct) => {
10961096
if let ty::ConstKind::Infer(ty::InferConst::Var(vid)) = ct.kind() {
1097-
self.delegate.universe_of_ct(vid).unwrap()
1097+
self.delegate.universe_of_const(vid).unwrap()
10981098
} else {
10991099
return false;
11001100
}
@@ -1161,7 +1161,7 @@ where
11611161
return ControlFlow::Break(());
11621162
}
11631163

1164-
self.check_nameable(self.delegate.universe_of_ct(vid).unwrap())
1164+
self.check_nameable(self.delegate.universe_of_const(vid).unwrap())
11651165
}
11661166
ty::ConstKind::Placeholder(p) => self.check_nameable(p.universe()),
11671167
_ => {
@@ -1309,7 +1309,7 @@ where
13091309

13101310
pub(super) fn eager_resolve_region(&self, r: Region<I>) -> Region<I> {
13111311
if let ty::ReVar(vid) = r.kind() {
1312-
self.delegate.opportunistic_resolve_lt_var(vid)
1312+
self.delegate.shallow_resolve_region_var(vid)
13131313
} else {
13141314
r
13151315
}

compiler/rustc_trait_selection/src/error_reporting/traits/fulfillment_errors.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
111111
let bound_predicate = obligation.predicate.kind();
112112
match bound_predicate.skip_binder() {
113113
ty::PredicateKind::Clause(ty::ClauseKind::Trait(trait_predicate)) => {
114-
let leaf_trait_predicate =
115-
self.deep_resolve_non_region_vars(bound_predicate.rebind(trait_predicate));
114+
let leaf_trait_predicate = self
115+
.deep_resolve_non_region_vars(bound_predicate.rebind(trait_predicate));
116116

117117
// Let's use the root obligation as the main message, when we care about the
118118
// most general case ("X doesn't implement Pattern<'_>") over the case that
@@ -1669,8 +1669,10 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
16691669
(
16701670
with_forced_trimmed_paths!(format!(
16711671
"type mismatch resolving `{}`",
1672-
self.tcx
1673-
.short_string(self.deep_resolve_non_region_vars(predicate), &mut file),
1672+
self.tcx.short_string(
1673+
self.deep_resolve_non_region_vars(predicate),
1674+
&mut file
1675+
),
16741676
)),
16751677
obligation.cause.span,
16761678
None,

compiler/rustc_trait_selection/src/error_reporting/traits/suggestions.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4159,7 +4159,8 @@ impl<'a, 'tcx> TypeErrCtxt<'a, 'tcx> {
41594159
let is_upvar_tys_infer_tuple = if !matches!(ty.kind(), ty::Tuple(..)) {
41604160
false
41614161
} else if let ObligationCauseCode::BuiltinDerived(data) = &*data.parent_code {
4162-
let parent_trait_ref = self.deep_resolve_non_region_vars(data.parent_trait_pred);
4162+
let parent_trait_ref =
4163+
self.deep_resolve_non_region_vars(data.parent_trait_pred);
41634164
let nested_ty = parent_trait_ref.skip_binder().self_ty();
41644165
matches!(nested_ty.kind(), ty::Coroutine(..))
41654166
|| matches!(nested_ty.kind(), ty::Closure(..))

0 commit comments

Comments
 (0)