Skip to content

Commit ebc86b4

Browse files
committed
Fix use of has_infer_types
* Add a new method `has_infer_types_or_consts` that's used instead most of the time, since there's generally no reason to only consider types. * Remove use of `has_closure_types`, because closures are no longer implicitly linked to the `InferCtxt`.
1 parent beac68a commit ebc86b4

File tree

14 files changed

+37
-61
lines changed

14 files changed

+37
-61
lines changed

src/librustc/ty/fold.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
9090
fn has_infer_types(&self) -> bool {
9191
self.has_type_flags(TypeFlags::HAS_TY_INFER)
9292
}
93+
fn has_infer_types_or_consts(&self) -> bool {
94+
self.has_type_flags(TypeFlags::HAS_TY_INFER | TypeFlags::HAS_CT_INFER)
95+
}
9396
fn has_infer_consts(&self) -> bool {
9497
self.has_type_flags(TypeFlags::HAS_CT_INFER)
9598
}
@@ -114,9 +117,6 @@ pub trait TypeFoldable<'tcx>: fmt::Debug + Clone {
114117
fn has_re_placeholders(&self) -> bool {
115118
self.has_type_flags(TypeFlags::HAS_RE_PLACEHOLDER)
116119
}
117-
fn has_closure_types(&self) -> bool {
118-
self.has_type_flags(TypeFlags::HAS_TY_CLOSURE)
119-
}
120120
/// "Free" regions in this context means that it has any region
121121
/// that is not (a) erased or (b) late-bound.
122122
fn has_free_regions(&self) -> bool {

src/librustc/ty/layout.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> {
502502
let univariant = |fields: &[TyLayout<'_>], repr: &ReprOptions, kind| {
503503
Ok(tcx.intern_layout(self.univariant_uninterned(ty, fields, repr, kind)?))
504504
};
505-
debug_assert!(!ty.has_infer_types());
505+
debug_assert!(!ty.has_infer_types_or_consts());
506506

507507
Ok(match ty.kind {
508508
// Basic scalars.
@@ -1752,7 +1752,7 @@ impl<'tcx> SizeSkeleton<'tcx> {
17521752
tcx: TyCtxt<'tcx>,
17531753
param_env: ty::ParamEnv<'tcx>,
17541754
) -> Result<SizeSkeleton<'tcx>, LayoutError<'tcx>> {
1755-
debug_assert!(!ty.has_infer_types());
1755+
debug_assert!(!ty.has_infer_types_or_consts());
17561756

17571757
// First try computing a static layout.
17581758
let err = match tcx.layout_of(param_env.and(ty)) {

src/librustc_infer/infer/freshen.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for TypeFreshener<'a, 'tcx> {
143143
}
144144

145145
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
146-
if !(t.needs_infer()
147-
|| t.has_erasable_regions()
148-
|| (t.has_closure_types() && self.infcx.in_progress_tables.is_some()))
149-
{
146+
if !t.needs_infer() && !t.has_erasable_regions() {
150147
return t;
151148
}
152149

src/librustc_infer/infer/mod.rs

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1482,12 +1482,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
14821482
) -> bool {
14831483
let ty = self.resolve_vars_if_possible(&ty);
14841484

1485-
// Even if the type may have no inference variables, during
1486-
// type-checking closure types are in local tables only.
1487-
if self.in_progress_tables.is_none() || !ty.has_closure_types() {
1488-
if !(param_env, ty).has_local_value() {
1489-
return ty.is_copy_modulo_regions(self.tcx, param_env, span);
1490-
}
1485+
if !(param_env, ty).has_local_value() {
1486+
return ty.is_copy_modulo_regions(self.tcx, param_env, span);
14911487
}
14921488

14931489
let copy_def_id = self.tcx.require_lang_item(lang_items::CopyTraitLangItem, None);

src/librustc_infer/infer/nll_relate/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ where
340340
// In NLL, we don't have type inference variables
341341
// floating around, so we can do this rather imprecise
342342
// variant of the occurs-check.
343-
assert!(!generalized_ty.has_infer_types());
343+
assert!(!generalized_ty.has_infer_types_or_consts());
344344
}
345345

346346
self.infcx.inner.borrow_mut().type_variables.instantiate(vid, generalized_ty);

src/librustc_infer/infer/resolve.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for OpportunisticVarResolver<'a, 'tcx> {
2828
}
2929

3030
fn fold_ty(&mut self, t: Ty<'tcx>) -> Ty<'tcx> {
31-
if !t.has_infer_types() && !t.has_infer_consts() {
31+
if !t.has_infer_types_or_consts() {
3232
t // micro-optimize -- if there is nothing in this type that this fold affects...
3333
} else {
3434
let t = self.infcx.shallow_resolve(t);
@@ -37,7 +37,7 @@ impl<'a, 'tcx> TypeFolder<'tcx> for OpportunisticVarResolver<'a, 'tcx> {
3737
}
3838

3939
fn fold_const(&mut self, ct: &'tcx Const<'tcx>) -> &'tcx Const<'tcx> {
40-
if !ct.has_infer_consts() {
40+
if !ct.has_infer_types_or_consts() {
4141
ct // micro-optimize -- if there is nothing in this const that this fold affects...
4242
} else {
4343
let ct = self.infcx.shallow_resolve(ct);

src/librustc_infer/traits/error_reporting/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
647647
}
648648

649649
// Try to report a help message
650-
if !trait_ref.has_infer_types()
650+
if !trait_ref.has_infer_types_or_consts()
651651
&& self.predicate_can_apply(obligation.param_env, trait_ref)
652652
{
653653
// If a where-clause may be useful, remind the

src/librustc_infer/traits/error_reporting/suggestions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
471471
return;
472472
}
473473
let trait_ref = self.resolve_vars_if_possible(trait_ref);
474-
if trait_ref.has_infer_types() {
474+
if trait_ref.has_infer_types_or_consts() {
475475
// Do not ICE while trying to find if a reborrow would succeed on a trait with
476476
// unresolved bindings.
477477
return;

src/librustc_infer/traits/fulfill.rs

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
299299

300300
let obligation = &mut pending_obligation.obligation;
301301

302-
if obligation.predicate.has_infer_types() {
302+
if obligation.predicate.has_infer_types_or_consts() {
303303
obligation.predicate =
304304
self.selcx.infcx().resolve_vars_if_possible(&obligation.predicate);
305305
}
@@ -346,16 +346,7 @@ impl<'a, 'b, 'tcx> ObligationProcessor for FulfillProcessor<'a, 'b, 'tcx> {
346346
// This is a bit subtle: for the most part, the
347347
// only reason we can fail to make progress on
348348
// trait selection is because we don't have enough
349-
// information about the types in the trait. One
350-
// exception is that we sometimes haven't decided
351-
// what kind of closure a closure is. *But*, in
352-
// that case, it turns out, the type of the
353-
// closure will also change, because the closure
354-
// also includes references to its upvars as part
355-
// of its type, and those types are resolved at
356-
// the same time.
357-
//
358-
// FIXME(#32286) logic seems false if no upvars
349+
// information about the types in the trait.
359350
pending_obligation.stalled_on =
360351
trait_ref_type_vars(self.selcx, data.to_poly_trait_ref());
361352

src/librustc_infer/traits/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ pub fn type_known_to_meet_bound_modulo_regions<'a, 'tcx>(
213213
result
214214
);
215215

216-
if result && (ty.has_infer_types() || ty.has_closure_types()) {
216+
if result && ty.has_infer_types_or_consts() {
217217
// Because of inference "guessing", selection can sometimes claim
218218
// to succeed while the success requires a guess. To ensure
219219
// this function's result remains infallible, we must confirm

0 commit comments

Comments
 (0)