Skip to content

Commit 6c05e8d

Browse files
committed
Add bound_fn_sig
1 parent c92248a commit 6c05e8d

File tree

16 files changed

+59
-36
lines changed

16 files changed

+59
-36
lines changed

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1385,8 +1385,8 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
13851385
}
13861386

13871387
(ty::FnDef(did1, substs1), ty::FnDef(did2, substs2)) => {
1388-
let sig1 = EarlyBinder(self.tcx.fn_sig(*did1)).subst(self.tcx, substs1);
1389-
let sig2 = EarlyBinder(self.tcx.fn_sig(*did2)).subst(self.tcx, substs2);
1388+
let sig1 = self.tcx.bound_fn_sig(*did1).subst(self.tcx, substs1);
1389+
let sig2 = self.tcx.bound_fn_sig(*did2).subst(self.tcx, substs2);
13901390
let mut values = self.cmp_fn_sig(&sig1, &sig2);
13911391
let path1 = format!(" {{{}}}", self.tcx.def_path_str_with_substs(*did1, substs1));
13921392
let path2 = format!(" {{{}}}", self.tcx.def_path_str_with_substs(*did2, substs2));
@@ -1397,7 +1397,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
13971397
}
13981398

13991399
(ty::FnDef(did1, substs1), ty::FnPtr(sig2)) => {
1400-
let sig1 = EarlyBinder(self.tcx.fn_sig(*did1)).subst(self.tcx, substs1);
1400+
let sig1 = self.tcx.bound_fn_sig(*did1).subst(self.tcx, substs1);
14011401
let mut values = self.cmp_fn_sig(&sig1, sig2);
14021402
values.0.push_highlighted(format!(
14031403
" {{{}}}",
@@ -1407,7 +1407,7 @@ impl<'a, 'tcx> InferCtxt<'a, 'tcx> {
14071407
}
14081408

14091409
(ty::FnPtr(sig1), ty::FnDef(did2, substs2)) => {
1410-
let sig2 = EarlyBinder(self.tcx.fn_sig(*did2)).subst(self.tcx, substs2);
1410+
let sig2 = self.tcx.bound_fn_sig(*did2).subst(self.tcx, substs2);
14111411
let mut values = self.cmp_fn_sig(sig1, &sig2);
14121412
values.1.push_normal(format!(
14131413
" {{{}}}",

compiler/rustc_middle/src/ty/layout.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -2749,10 +2749,9 @@ impl<'tcx> ty::Instance<'tcx> {
27492749
// `src/test/ui/polymorphization/normalized_sig_types.rs`), and codegen not keeping
27502750
// track of a polymorphization `ParamEnv` to allow normalizing later.
27512751
let mut sig = match *ty.kind() {
2752-
ty::FnDef(def_id, substs) => EarlyBinder(
2753-
tcx.normalize_erasing_regions(tcx.param_env(def_id), tcx.fn_sig(def_id)),
2754-
)
2755-
.subst(tcx, substs),
2752+
ty::FnDef(def_id, substs) => tcx
2753+
.normalize_erasing_regions(tcx.param_env(def_id), tcx.bound_fn_sig(def_id))
2754+
.subst(tcx, substs),
27562755
_ => unreachable!(),
27572756
};
27582757

compiler/rustc_middle/src/ty/print/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -589,7 +589,7 @@ pub trait PrettyPrinter<'tcx>:
589589
p!(")")
590590
}
591591
ty::FnDef(def_id, substs) => {
592-
let sig = EarlyBinder(self.tcx().fn_sig(def_id)).subst(self.tcx(), substs);
592+
let sig = self.tcx().bound_fn_sig(def_id).subst(self.tcx(), substs);
593593
p!(print(sig), " {{", print_value_path(def_id, substs), "}}");
594594
}
595595
ty::FnPtr(ref bare_fn) => p!(print(bare_fn)),

compiler/rustc_middle/src/ty/structural_impls.rs

+21
Original file line numberDiff line numberDiff line change
@@ -860,6 +860,27 @@ impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for Box<[T]> {
860860
}
861861
}
862862

863+
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::EarlyBinder<T> {
864+
fn try_super_fold_with<F: FallibleTypeFolder<'tcx>>(
865+
self,
866+
folder: &mut F,
867+
) -> Result<Self, F::Error> {
868+
self.try_map_bound(|ty| ty.try_fold_with(folder))
869+
}
870+
871+
fn try_fold_with<F: FallibleTypeFolder<'tcx>>(self, folder: &mut F) -> Result<Self, F::Error> {
872+
self.try_map_bound(|ty| ty.try_fold_with(folder))
873+
}
874+
875+
fn super_visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
876+
self.as_ref().0.visit_with(visitor)
877+
}
878+
879+
fn visit_with<V: TypeVisitor<'tcx>>(&self, visitor: &mut V) -> ControlFlow<V::BreakTy> {
880+
self.as_ref().0.visit_with(visitor)
881+
}
882+
}
883+
863884
impl<'tcx, T: TypeFoldable<'tcx>> TypeFoldable<'tcx> for ty::Binder<'tcx, T> {
864885
fn try_super_fold_with<F: FallibleTypeFolder<'tcx>>(
865886
self,

compiler/rustc_middle/src/ty/sty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2180,7 +2180,7 @@ impl<'tcx> Ty<'tcx> {
21802180

21812181
pub fn fn_sig(self, tcx: TyCtxt<'tcx>) -> PolyFnSig<'tcx> {
21822182
match self.kind() {
2183-
FnDef(def_id, substs) => EarlyBinder(tcx.fn_sig(*def_id)).subst(tcx, substs),
2183+
FnDef(def_id, substs) => tcx.bound_fn_sig(*def_id).subst(tcx, substs),
21842184
FnPtr(f) => *f,
21852185
Error(_) => {
21862186
// ignore errors (#54954)

compiler/rustc_middle/src/ty/util.rs

+4
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,10 @@ impl<'tcx> TyCtxt<'tcx> {
596596
pub fn bound_type_of(self, def_id: DefId) -> EarlyBinder<Ty<'tcx>> {
597597
EarlyBinder(self.type_of(def_id))
598598
}
599+
600+
pub fn bound_fn_sig(self, def_id: DefId) -> EarlyBinder<ty::PolyFnSig<'tcx>> {
601+
EarlyBinder(self.fn_sig(def_id))
602+
}
599603
}
600604

601605
struct OpaqueTypeExpander<'tcx> {

compiler/rustc_mir_transform/src/inline.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_middle::mir::visit::*;
88
use rustc_middle::mir::*;
99
use rustc_middle::traits::ObligationCause;
1010
use rustc_middle::ty::subst::Subst;
11-
use rustc_middle::ty::{self, ConstKind, EarlyBinder, Instance, InstanceDef, ParamEnv, Ty, TyCtxt};
11+
use rustc_middle::ty::{self, ConstKind, Instance, InstanceDef, ParamEnv, Ty, TyCtxt};
1212
use rustc_span::{hygiene::ExpnKind, ExpnData, LocalExpnId, Span};
1313
use rustc_target::spec::abi::Abi;
1414

@@ -260,7 +260,7 @@ impl<'tcx> Inliner<'tcx> {
260260
return None;
261261
}
262262

263-
let fn_sig = EarlyBinder(self.tcx.fn_sig(def_id)).subst(self.tcx, substs);
263+
let fn_sig = self.tcx.bound_fn_sig(def_id).subst(self.tcx, substs);
264264

265265
return Some(CallSite {
266266
callee,

compiler/rustc_mir_transform/src/shim.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option<Ty<'tcx>>)
151151
} else {
152152
InternalSubsts::identity_for_item(tcx, def_id)
153153
};
154-
let sig = EarlyBinder(tcx.fn_sig(def_id)).subst(tcx, substs);
154+
let sig = tcx.bound_fn_sig(def_id).subst(tcx, substs);
155155
let sig = tcx.erase_late_bound_regions(sig);
156156
let span = tcx.def_span(def_id);
157157

@@ -343,7 +343,7 @@ impl<'tcx> CloneShimBuilder<'tcx> {
343343
// otherwise going to be TySelf and we can't index
344344
// or access fields of a Place of type TySelf.
345345
let substs = tcx.mk_substs_trait(self_ty, &[]);
346-
let sig = EarlyBinder(tcx.fn_sig(def_id)).subst(tcx, substs);
346+
let sig = tcx.bound_fn_sig(def_id).subst(tcx, substs);
347347
let sig = tcx.erase_late_bound_regions(sig);
348348
let span = tcx.def_span(def_id);
349349

compiler/rustc_typeck/src/astconv/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2693,7 +2693,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
26932693
trait_ref.def_id,
26942694
)?;
26952695

2696-
let fn_sig = EarlyBinder(tcx.fn_sig(assoc.def_id)).subst(
2696+
let fn_sig = tcx.bound_fn_sig(assoc.def_id).subst(
26972697
tcx,
26982698
trait_ref.substs.extend_to(tcx, assoc.def_id, |param, _| tcx.mk_param_from_def(param)),
26992699
);

compiler/rustc_typeck/src/check/callee.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_middle::ty::adjustment::{
1818
Adjust, Adjustment, AllowTwoPhase, AutoBorrow, AutoBorrowMutability,
1919
};
2020
use rustc_middle::ty::subst::{Subst, SubstsRef};
21-
use rustc_middle::ty::{self, EarlyBinder, Ty, TyCtxt, TypeFoldable};
21+
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable};
2222
use rustc_span::symbol::{sym, Ident};
2323
use rustc_span::Span;
2424
use rustc_target::spec::abi;
@@ -339,7 +339,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
339339
) -> Ty<'tcx> {
340340
let (fn_sig, def_id) = match *callee_ty.kind() {
341341
ty::FnDef(def_id, subst) => {
342-
let fn_sig = EarlyBinder(self.tcx.fn_sig(def_id)).subst(self.tcx, subst);
342+
let fn_sig = self.tcx.bound_fn_sig(def_id).subst(self.tcx, subst);
343343

344344
// Unit testing: function items annotated with
345345
// `#[rustc_evaluate_where_clauses]` trigger special output

compiler/rustc_typeck/src/check/compare_method.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -265,9 +265,8 @@ fn compare_predicate_entailment<'tcx>(
265265
let impl_fty = tcx.mk_fn_ptr(ty::Binder::dummy(impl_sig));
266266
debug!("compare_impl_method: impl_fty={:?}", impl_fty);
267267

268-
// First liberate late bound regions and subst placeholders
269-
let trait_sig = tcx.liberate_late_bound_regions(impl_m.def_id, tcx.fn_sig(trait_m.def_id));
270-
let trait_sig = EarlyBinder(trait_sig).subst(tcx, trait_to_placeholder_substs);
268+
let trait_sig = tcx.bound_fn_sig(trait_m.def_id).subst(tcx, trait_to_placeholder_substs);
269+
let trait_sig = tcx.liberate_late_bound_regions(impl_m.def_id, trait_sig);
271270
let trait_sig =
272271
inh.normalize_associated_types_in(impl_m_span, impl_m_hir_id, param_env, trait_sig);
273272
// Add the resulting inputs and output as well-formed.

compiler/rustc_typeck/src/check/fn_ctxt/_impl.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1044,8 +1044,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10441044
) {
10451045
let (sig, did, substs) = match (&expected.kind(), &found.kind()) {
10461046
(ty::FnDef(did1, substs1), ty::FnDef(did2, substs2)) => {
1047-
let sig1 = EarlyBinder(self.tcx.fn_sig(*did1)).subst(self.tcx, substs1);
1048-
let sig2 = EarlyBinder(self.tcx.fn_sig(*did2)).subst(self.tcx, substs2);
1047+
let sig1 = self.tcx.bound_fn_sig(*did1).subst(self.tcx, substs1);
1048+
let sig2 = self.tcx.bound_fn_sig(*did2).subst(self.tcx, substs2);
10491049
if sig1 != sig2 {
10501050
return;
10511051
}
@@ -1056,7 +1056,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
10561056
(sig1, *did1, substs1)
10571057
}
10581058
(ty::FnDef(did, substs), ty::FnPtr(sig2)) => {
1059-
let sig1 = EarlyBinder(self.tcx.fn_sig(*did)).subst(self.tcx, substs);
1059+
let sig1 = self.tcx.bound_fn_sig(*did).subst(self.tcx, substs);
10601060
if sig1 != *sig2 {
10611061
return;
10621062
}

compiler/rustc_typeck/src/check/method/confirm.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ use rustc_middle::ty::adjustment::{Adjust, Adjustment, PointerCast};
1111
use rustc_middle::ty::adjustment::{AllowTwoPhase, AutoBorrow, AutoBorrowMutability};
1212
use rustc_middle::ty::fold::TypeFoldable;
1313
use rustc_middle::ty::subst::{self, Subst, SubstsRef};
14-
use rustc_middle::ty::{self, EarlyBinder, GenericParamDefKind, Ty};
14+
use rustc_middle::ty::{self, GenericParamDefKind, Ty};
1515
use rustc_span::Span;
1616
use rustc_trait_selection::traits;
1717

@@ -460,9 +460,9 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
460460

461461
debug!("method_predicates after subst = {:?}", method_predicates);
462462

463-
let sig = self.tcx.fn_sig(def_id);
463+
let sig = self.tcx.bound_fn_sig(def_id);
464464

465-
let sig = EarlyBinder(sig).subst(self.tcx, all_substs);
465+
let sig = sig.subst(self.tcx, all_substs);
466466
debug!("type scheme substituted, sig={:?}", sig);
467467

468468
let sig = self.replace_bound_vars_with_fresh_vars(sig);

compiler/rustc_typeck/src/check/method/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use rustc_infer::infer::{self, InferOk};
2121
use rustc_middle::ty::subst::Subst;
2222
use rustc_middle::ty::subst::{InternalSubsts, SubstsRef};
2323
use rustc_middle::ty::GenericParamDefKind;
24-
use rustc_middle::ty::{self, EarlyBinder, ToPredicate, Ty, TypeFoldable};
24+
use rustc_middle::ty::{self, ToPredicate, Ty, TypeFoldable};
2525
use rustc_span::symbol::Ident;
2626
use rustc_span::Span;
2727
use rustc_trait_selection::traits;
@@ -460,8 +460,8 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
460460
// N.B., instantiate late-bound regions first so that
461461
// `instantiate_type_scheme` can normalize associated types that
462462
// may reference those regions.
463-
let fn_sig = tcx.fn_sig(def_id);
464-
let fn_sig = EarlyBinder(fn_sig).subst(self.tcx, substs);
463+
let fn_sig = tcx.bound_fn_sig(def_id);
464+
let fn_sig = fn_sig.subst(self.tcx, substs);
465465
let fn_sig = self.replace_bound_vars_with_fresh_vars(span, infer::FnCall, fn_sig).0;
466466

467467
let InferOk { value, obligations: o } = if is_op {

compiler/rustc_typeck/src/check/method/probe.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -901,10 +901,10 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
901901
) -> bool {
902902
match method.kind {
903903
ty::AssocKind::Fn => {
904-
let fty = self.tcx.fn_sig(method.def_id);
904+
let fty = self.tcx.bound_fn_sig(method.def_id);
905905
self.probe(|_| {
906906
let substs = self.fresh_substs_for_item(self.span, method.def_id);
907-
let fty = EarlyBinder(fty).subst(self.tcx, substs);
907+
let fty = fty.subst(self.tcx, substs);
908908
let (fty, _) =
909909
self.replace_bound_vars_with_fresh_vars(self.span, infer::FnCall, fty);
910910

@@ -1771,7 +1771,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
17711771

17721772
#[instrument(level = "debug", skip(self))]
17731773
fn xform_method_sig(&self, method: DefId, substs: SubstsRef<'tcx>) -> ty::FnSig<'tcx> {
1774-
let fn_sig = self.tcx.fn_sig(method);
1774+
let fn_sig = self.tcx.bound_fn_sig(method);
17751775
debug!(?fn_sig);
17761776

17771777
assert!(!substs.has_escaping_bound_vars());
@@ -1785,7 +1785,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
17851785
assert_eq!(substs.len(), generics.parent_count as usize);
17861786

17871787
let xform_fn_sig = if generics.params.is_empty() {
1788-
EarlyBinder(fn_sig).subst(self.tcx, substs)
1788+
fn_sig.subst(self.tcx, substs)
17891789
} else {
17901790
let substs = InternalSubsts::for_item(self.tcx, method, |param, _| {
17911791
let i = param.index as usize;
@@ -1803,7 +1803,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
18031803
}
18041804
}
18051805
});
1806-
EarlyBinder(fn_sig).subst(self.tcx, substs)
1806+
fn_sig.subst(self.tcx, substs)
18071807
};
18081808

18091809
self.erase_late_bound_regions(xform_fn_sig)

src/tools/clippy/clippy_utils/src/ty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use rustc_lint::LateContext;
1313
use rustc_middle::mir::interpret::{ConstValue, Scalar};
1414
use rustc_middle::ty::subst::{GenericArg, GenericArgKind, Subst};
1515
use rustc_middle::ty::{
16-
self, AdtDef, Binder, EarlyBinder, FnSig, IntTy, Predicate, PredicateKind, Ty, TyCtxt, TypeFoldable, UintTy, VariantDiscr,
16+
self, AdtDef, Binder, FnSig, IntTy, Predicate, PredicateKind, Ty, TyCtxt, TypeFoldable, UintTy, VariantDiscr,
1717
};
1818
use rustc_span::symbol::Ident;
1919
use rustc_span::{sym, Span, Symbol, DUMMY_SP};
@@ -520,7 +520,7 @@ pub fn expr_sig<'tcx>(cx: &LateContext<'tcx>, expr: &Expr<'_>) -> Option<ExprFnS
520520
let ty = cx.typeck_results().expr_ty_adjusted(expr).peel_refs();
521521
match *ty.kind() {
522522
ty::Closure(_, subs) => Some(ExprFnSig::Closure(subs.as_closure().sig())),
523-
ty::FnDef(id, subs) => Some(ExprFnSig::Sig(EarlyBinder(cx.tcx.fn_sig(id)).subst(cx.tcx, subs))),
523+
ty::FnDef(id, subs) => Some(ExprFnSig::Sig(cx.tcx.bound_fn_sig(id).subst(cx.tcx, subs))),
524524
ty::FnPtr(sig) => Some(ExprFnSig::Sig(sig)),
525525
ty::Dynamic(bounds, _) => {
526526
let lang_items = cx.tcx.lang_items();

0 commit comments

Comments
 (0)