Skip to content

Commit 1666ab0

Browse files
committed
Remove allows_infer now that every use of it is delegated to HirTyLowere
1 parent 4860ac5 commit 1666ab0

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

compiler/rustc_hir_analysis/src/collect.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ use rustc_infer::traits::ObligationCause;
2929
use rustc_middle::hir::nested_filter;
3030
use rustc_middle::query::Providers;
3131
use rustc_middle::ty::util::{Discr, IntTypeExt};
32-
use rustc_middle::ty::{self, AdtKind, Const, IsSuggestable, Ty, TyCtxt, Upcast};
32+
use rustc_middle::ty::{
33+
self, AdtKind, Const, IsSuggestable, Ty, TyCtxt, TypeVisitableExt as _, Upcast,
34+
};
3335
use rustc_middle::{bug, span_bug};
3436
use rustc_span::symbol::{kw, sym, Ident, Symbol};
3537
use rustc_span::{Span, DUMMY_SP};
@@ -372,8 +374,8 @@ impl<'tcx> HirTyLowerer<'tcx> for ItemCtxt<'tcx> {
372374
self.item_def_id
373375
}
374376

375-
fn allow_infer(&self) -> bool {
376-
false
377+
fn check_type(&self, ty: Ty<'tcx>) {
378+
assert!(!ty.has_infer(), "{ty:?}")
377379
}
378380

379381
fn re_infer(

compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ pub trait HirTyLowerer<'tcx> {
9090
/// Returns the [`DefId`] of the overarching item whose constituents get lowered.
9191
fn item_def_id(&self) -> LocalDefId;
9292

93-
/// Returns `true` if the current context allows the use of inference variables.
94-
fn allow_infer(&self) -> bool;
93+
/// Checks if a type is valid for this context and panics otherwise.
94+
/// This is used to prevent the use of inference variables in `ItemCtxt`.
95+
fn check_type(&self, _: Ty<'tcx>);
9596

9697
/// Returns the region to use when a lifetime is omitted (and not elided).
9798
///
@@ -1204,7 +1205,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
12041205
//
12051206

12061207
let infcx = self.infcx();
1207-
assert!(self.allow_infer() || !self_ty.has_infer());
1208+
self.check_type(self_ty);
12081209

12091210
// FIXME(inherent_associated_types): Acquiring the ParamEnv this early leads to cycle errors
12101211
// when inside of an ADT (#108491) or where clause.
@@ -1368,7 +1369,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
13681369
let tcx = self.tcx();
13691370

13701371
let infcx = self.infcx();
1371-
assert!(self.allow_infer() || !qself_ty.has_infer());
1372+
self.check_type(qself_ty);
13721373

13731374
tcx.all_traits()
13741375
.filter(|trait_def_id| {

compiler/rustc_hir_typeck/src/fn_ctxt/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -222,8 +222,8 @@ impl<'a, 'tcx> HirTyLowerer<'tcx> for FnCtxt<'a, 'tcx> {
222222
self.body_id
223223
}
224224

225-
fn allow_infer(&self) -> bool {
226-
true
225+
fn check_type(&self, _: Ty<'tcx>) {
226+
// Nothing to do, we allow all types
227227
}
228228

229229
fn re_infer(

0 commit comments

Comments
 (0)