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

+3-3
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

+2-2
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

+1-4
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

+2-6
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

+1-1
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

+2-2
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

+1-1
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

+1-1
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

+2-11
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

+1-1
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

src/librustc_infer/traits/project.rs

+4-12
Original file line numberDiff line numberDiff line change
@@ -490,22 +490,14 @@ fn opt_normalize_projection_type<'a, 'b, 'tcx>(
490490
match cache_result {
491491
Ok(()) => {}
492492
Err(ProjectionCacheEntry::Ambiguous) => {
493-
// If we found ambiguity the last time, that generally
494-
// means we will continue to do so until some type in the
495-
// key changes (and we know it hasn't, because we just
496-
// fully resolved it). One exception though is closure
497-
// types, which can transition from having a fixed kind to
498-
// no kind with no visible change in the key.
499-
//
500-
// FIXME(#32286) refactor this so that closure type
501-
// changes
493+
// If we found ambiguity the last time, that means we will continue
494+
// to do so until some type in the key changes (and we know it
495+
// hasn't, because we just fully resolved it).
502496
debug!(
503497
"opt_normalize_projection_type: \
504498
found cache entry: ambiguous"
505499
);
506-
if !projection_ty.has_closure_types() {
507-
return None;
508-
}
500+
return None;
509501
}
510502
Err(ProjectionCacheEntry::InProgress) => {
511503
// If while normalized A::B, we are asked to normalize

src/librustc_traits/implied_outlives_bounds.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ fn compute_implied_outlives_bounds<'tcx>(
8484
// to avoids duplicate errors that otherwise show up.
8585
fulfill_cx.register_predicate_obligations(
8686
infcx,
87-
obligations.iter().filter(|o| o.predicate.has_infer_types()).cloned(),
87+
obligations.iter().filter(|o| o.predicate.has_infer_types_or_consts()).cloned(),
8888
);
8989

9090
// From the full set of obligations, just filter down to the

src/librustc_typeck/check/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2900,14 +2900,14 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
29002900
debug!("resolve_vars_with_obligations(ty={:?})", ty);
29012901

29022902
// No Infer()? Nothing needs doing.
2903-
if !ty.has_infer_types() && !ty.has_infer_consts() {
2903+
if !ty.has_infer_types_or_consts() {
29042904
debug!("resolve_vars_with_obligations: ty={:?}", ty);
29052905
return ty;
29062906
}
29072907

29082908
// If `ty` is a type variable, see whether we already know what it is.
29092909
ty = self.resolve_vars_if_possible(&ty);
2910-
if !ty.has_infer_types() && !ty.has_infer_consts() {
2910+
if !ty.has_infer_types_or_consts() {
29112911
debug!("resolve_vars_with_obligations: ty={:?}", ty);
29122912
return ty;
29132913
}

src/test/ui/const-generics/array-impls/into-iter-no-impls-length-33.stderr

+14-14
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
error[E0277]: arrays only have std trait implementations for lengths 0..=32
2-
--> $DIR/into-iter-no-impls-length-33.rs:12:5
2+
--> $DIR/into-iter-no-impls-length-33.rs:12:19
33
|
44
LL | IntoIter::new([0i32; 33])
5-
| ^^^^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[i32; 33]`
5+
| ^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[i32; 33]`
66
|
77
= note: required by `std::array::IntoIter::<T, N>::new`
88

@@ -19,10 +19,10 @@ LL | IntoIter::new([0i32; 33])
1919
= note: the return type of a function must have a statically known size
2020

2121
error[E0277]: arrays only have std trait implementations for lengths 0..=32
22-
--> $DIR/into-iter-no-impls-length-33.rs:18:5
22+
--> $DIR/into-iter-no-impls-length-33.rs:18:19
2323
|
2424
LL | IntoIter::new([0i32; 33])
25-
| ^^^^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[i32; 33]`
25+
| ^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[i32; 33]`
2626
|
2727
= note: required by `std::array::IntoIter::<T, N>::new`
2828

@@ -39,10 +39,10 @@ LL | IntoIter::new([0i32; 33])
3939
= note: the return type of a function must have a statically known size
4040

4141
error[E0277]: arrays only have std trait implementations for lengths 0..=32
42-
--> $DIR/into-iter-no-impls-length-33.rs:24:5
42+
--> $DIR/into-iter-no-impls-length-33.rs:24:19
4343
|
4444
LL | IntoIter::new([0i32; 33])
45-
| ^^^^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[i32; 33]`
45+
| ^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[i32; 33]`
4646
|
4747
= note: required by `std::array::IntoIter::<T, N>::new`
4848

@@ -59,10 +59,10 @@ LL | IntoIter::new([0i32; 33])
5959
= note: the return type of a function must have a statically known size
6060

6161
error[E0277]: arrays only have std trait implementations for lengths 0..=32
62-
--> $DIR/into-iter-no-impls-length-33.rs:30:5
62+
--> $DIR/into-iter-no-impls-length-33.rs:30:19
6363
|
6464
LL | IntoIter::new([0i32; 33])
65-
| ^^^^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[i32; 33]`
65+
| ^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[i32; 33]`
6666
|
6767
= note: required by `std::array::IntoIter::<T, N>::new`
6868

@@ -79,10 +79,10 @@ LL | IntoIter::new([0i32; 33])
7979
= note: the return type of a function must have a statically known size
8080

8181
error[E0277]: arrays only have std trait implementations for lengths 0..=32
82-
--> $DIR/into-iter-no-impls-length-33.rs:36:5
82+
--> $DIR/into-iter-no-impls-length-33.rs:36:19
8383
|
8484
LL | IntoIter::new([0i32; 33])
85-
| ^^^^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[i32; 33]`
85+
| ^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[i32; 33]`
8686
|
8787
= note: required by `std::array::IntoIter::<T, N>::new`
8888

@@ -99,10 +99,10 @@ LL | IntoIter::new([0i32; 33])
9999
= note: the return type of a function must have a statically known size
100100

101101
error[E0277]: arrays only have std trait implementations for lengths 0..=32
102-
--> $DIR/into-iter-no-impls-length-33.rs:42:5
102+
--> $DIR/into-iter-no-impls-length-33.rs:42:19
103103
|
104104
LL | IntoIter::new([0i32; 33])
105-
| ^^^^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[i32; 33]`
105+
| ^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[i32; 33]`
106106
|
107107
= note: required by `std::array::IntoIter::<T, N>::new`
108108

@@ -119,10 +119,10 @@ LL | IntoIter::new([0i32; 33])
119119
= note: the return type of a function must have a statically known size
120120

121121
error[E0277]: arrays only have std trait implementations for lengths 0..=32
122-
--> $DIR/into-iter-no-impls-length-33.rs:48:5
122+
--> $DIR/into-iter-no-impls-length-33.rs:48:19
123123
|
124124
LL | IntoIter::new([0i32; 33])
125-
| ^^^^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[i32; 33]`
125+
| ^^^^^^^^^^ the trait `std::array::LengthAtMost32` is not implemented for `[i32; 33]`
126126
|
127127
= note: required by `std::array::IntoIter::<T, N>::new`
128128

0 commit comments

Comments
 (0)