Skip to content

Commit 63811bc

Browse files
committed
rustc_infer: remove InferCtxt::closure_sig as the FnSig is always shallowly known.
1 parent 7ceebd9 commit 63811bc

File tree

15 files changed

+51
-76
lines changed

15 files changed

+51
-76
lines changed

src/librustc/ty/print/pretty.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -681,9 +681,9 @@ pub trait PrettyPrinter<'tcx>:
681681

682682
if self.tcx().sess.verbose() {
683683
p!(write(
684-
" closure_kind_ty={:?} closure_sig_ty={:?}",
684+
" closure_kind_ty={:?} closure_sig_as_fn_ptr_ty={:?}",
685685
substs.as_closure().kind_ty(did, self.tcx()),
686-
substs.as_closure().sig_ty(did, self.tcx())
686+
substs.as_closure().sig_as_fn_ptr_ty(did, self.tcx())
687687
));
688688
}
689689

src/librustc/ty/sty.rs

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ pub struct ClosureSubsts<'tcx> {
371371
/// parent slice and not canonical substs themselves.
372372
struct SplitClosureSubsts<'tcx> {
373373
closure_kind_ty: Ty<'tcx>,
374-
closure_sig_ty: Ty<'tcx>,
374+
closure_sig_as_fn_ptr_ty: Ty<'tcx>,
375375
upvar_kinds: &'tcx [GenericArg<'tcx>],
376376
}
377377

@@ -384,7 +384,7 @@ impl<'tcx> ClosureSubsts<'tcx> {
384384
let parent_len = generics.parent_count;
385385
SplitClosureSubsts {
386386
closure_kind_ty: self.substs.type_at(parent_len),
387-
closure_sig_ty: self.substs.type_at(parent_len + 1),
387+
closure_sig_as_fn_ptr_ty: self.substs.type_at(parent_len + 1),
388388
upvar_kinds: &self.substs[parent_len + 2..],
389389
}
390390
}
@@ -412,12 +412,10 @@ impl<'tcx> ClosureSubsts<'tcx> {
412412
self.split(def_id, tcx).closure_kind_ty
413413
}
414414

415-
/// Returns the type representing the closure signature for this
416-
/// closure; may contain type variables during inference. To get
417-
/// the closure signature during inference, use
418-
/// `infcx.fn_sig(def_id)`.
419-
pub fn sig_ty(self, def_id: DefId, tcx: TyCtxt<'_>) -> Ty<'tcx> {
420-
self.split(def_id, tcx).closure_sig_ty
415+
/// Returns the `fn` pointer type representing the closure signature for this
416+
/// closure.
417+
pub fn sig_as_fn_ptr_ty(self, def_id: DefId, tcx: TyCtxt<'_>) -> Ty<'tcx> {
418+
self.split(def_id, tcx).closure_sig_as_fn_ptr_ty
421419
}
422420

423421
/// Returns the closure kind for this closure; only usable outside
@@ -429,16 +427,12 @@ impl<'tcx> ClosureSubsts<'tcx> {
429427
self.split(def_id, tcx).closure_kind_ty.to_opt_closure_kind().unwrap()
430428
}
431429

432-
/// Extracts the signature from the closure; only usable outside
433-
/// of an inference context, because in that context we know that
434-
/// there are no type variables.
435-
///
436-
/// If you have an inference context, use `infcx.closure_sig()`.
430+
/// Extracts the signature from the closure.
437431
pub fn sig(&self, def_id: DefId, tcx: TyCtxt<'tcx>) -> ty::PolyFnSig<'tcx> {
438-
let ty = self.sig_ty(def_id, tcx);
432+
let ty = self.sig_as_fn_ptr_ty(def_id, tcx);
439433
match ty.kind {
440434
ty::FnPtr(sig) => sig,
441-
_ => bug!("closure_sig_ty is not a fn-ptr: {:?}", ty.kind),
435+
_ => bug!("closure_sig_as_fn_ptr_ty is not a fn-ptr: {:?}", ty.kind),
442436
}
443437
}
444438
}
@@ -2200,9 +2194,9 @@ impl<'tcx> TyS<'tcx> {
22002194
// ignore errors (#54954)
22012195
ty::Binder::dummy(FnSig::fake())
22022196
}
2203-
Closure(..) => {
2204-
bug!("to get the signature of a closure, use `closure_sig()` not `fn_sig()`",)
2205-
}
2197+
Closure(..) => bug!(
2198+
"to get the signature of a closure, use `substs.as_closure().sig()` not `fn_sig()`",
2199+
),
22062200
_ => bug!("Ty::fn_sig() called on non-fn type: {:?}", self),
22072201
}
22082202
}

src/librustc_infer/infer/mod.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1486,16 +1486,6 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
14861486
closure_kind_ty.to_opt_closure_kind()
14871487
}
14881488

1489-
/// Obtains the signature of a closure. For closures, unlike
1490-
/// `tcx.fn_sig(def_id)`, this method will work during the
1491-
/// type-checking of the enclosing function and return the closure
1492-
/// signature in its partially inferred state.
1493-
pub fn closure_sig(&self, def_id: DefId, substs: SubstsRef<'tcx>) -> ty::PolyFnSig<'tcx> {
1494-
let closure_sig_ty = substs.as_closure().sig_ty(def_id, self.tcx);
1495-
let closure_sig_ty = self.shallow_resolve(closure_sig_ty);
1496-
closure_sig_ty.fn_sig(self.tcx)
1497-
}
1498-
14991489
/// Clears the selection, evaluation, and projection caches. This is useful when
15001490
/// repeatedly attempting to select an `Obligation` while changing only
15011491
/// its `ParamEnv`, since `FulfillmentContext` doesn't use probing.

src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1684,7 +1684,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
16841684
// case it ends up being assigned into the return place.
16851685
annotated_closure = self.annotate_fn_sig(
16861686
*def_id,
1687-
self.infcx.closure_sig(*def_id, *substs),
1687+
substs.as_closure().sig(*def_id, self.infcx.tcx),
16881688
);
16891689
debug!(
16901690
"annotate_argument_and_return_for_borrow: \

src/librustc_mir/borrow_check/type_check/mod.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2083,9 +2083,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
20832083

20842084
CastKind::Pointer(PointerCast::ClosureFnPointer(unsafety)) => {
20852085
let sig = match op.ty(*body, tcx).kind {
2086-
ty::Closure(def_id, substs) => {
2087-
substs.as_closure().sig_ty(def_id, tcx).fn_sig(tcx)
2088-
}
2086+
ty::Closure(def_id, substs) => substs.as_closure().sig(def_id, tcx),
20892087
_ => bug!(),
20902088
};
20912089
let ty_fn_ptr_from = tcx.coerce_closure_fn_ty(sig, *unsafety);

src/librustc_mir/borrow_check/universal_regions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -580,7 +580,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
580580
match defining_ty {
581581
DefiningTy::Closure(def_id, substs) => {
582582
assert_eq!(self.mir_def_id, def_id);
583-
let closure_sig = substs.as_closure().sig_ty(def_id, tcx).fn_sig(tcx);
583+
let closure_sig = substs.as_closure().sig(def_id, tcx);
584584
let inputs_and_output = closure_sig.inputs_and_output();
585585
let closure_ty = tcx.closure_env_ty(def_id, substs).unwrap();
586586
ty::Binder::fuse(closure_ty, inputs_and_output, |closure_ty, inputs_and_output| {

src/librustc_trait_selection/opaque_types.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ where
724724
upvar_ty.visit_with(self);
725725
}
726726

727-
substs.as_closure().sig_ty(def_id, self.tcx).visit_with(self);
727+
substs.as_closure().sig_as_fn_ptr_ty(def_id, self.tcx).visit_with(self);
728728
}
729729

730730
ty::Generator(def_id, ref substs, _) => {

src/librustc_trait_selection/traits/error_reporting/suggestions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ impl<'a, 'tcx> InferCtxtExt<'tcx> for InferCtxt<'a, 'tcx> {
368368
let self_ty = trait_ref.self_ty();
369369
let (def_id, output_ty, callable) = match self_ty.kind {
370370
ty::Closure(def_id, substs) => {
371-
(def_id, self.closure_sig(def_id, substs).output(), "closure")
371+
(def_id, substs.as_closure().sig(def_id, self.tcx).output(), "closure")
372372
}
373373
ty::FnDef(def_id, _) => (def_id, self_ty.fn_sig(self.tcx).output(), "function"),
374374
_ => return,

src/librustc_trait_selection/traits/project.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1311,9 +1311,7 @@ fn confirm_closure_candidate<'cx, 'tcx>(
13111311
vtable: VtableClosureData<'tcx, PredicateObligation<'tcx>>,
13121312
) -> Progress<'tcx> {
13131313
let tcx = selcx.tcx();
1314-
let infcx = selcx.infcx();
1315-
let closure_sig_ty = vtable.substs.as_closure().sig_ty(vtable.closure_def_id, tcx);
1316-
let closure_sig = infcx.shallow_resolve(closure_sig_ty).fn_sig(tcx);
1314+
let closure_sig = vtable.substs.as_closure().sig(vtable.closure_def_id, tcx);
13171315
let Normalized { value: closure_sig, obligations } = normalize_with_depth(
13181316
selcx,
13191317
obligation.param_env,

src/librustc_trait_selection/traits/select.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3349,9 +3349,9 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
33493349
"closure_trait_ref_unnormalized(obligation={:?}, closure_def_id={:?}, substs={:?})",
33503350
obligation, closure_def_id, substs,
33513351
);
3352-
let closure_type = self.infcx.closure_sig(closure_def_id, substs);
3352+
let closure_sig = substs.as_closure().sig(closure_def_id, self.tcx());
33533353

3354-
debug!("closure_trait_ref_unnormalized: closure_type = {:?}", closure_type);
3354+
debug!("closure_trait_ref_unnormalized: closure_sig = {:?}", closure_sig);
33553355

33563356
// (1) Feels icky to skip the binder here, but OTOH we know
33573357
// that the self-type is an unboxed closure type and hence is
@@ -3362,7 +3362,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
33623362
self.tcx(),
33633363
obligation.predicate.def_id(),
33643364
obligation.predicate.skip_binder().self_ty(), // (1)
3365-
closure_type,
3365+
closure_sig,
33663366
util::TupleArgumentsFlag::No,
33673367
)
33683368
.map_bound(|(trait_ref, _)| trait_ref)

0 commit comments

Comments
 (0)