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

Lines changed: 4 additions & 4 deletions
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

Lines changed: 3 additions & 4 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 21 additions & 0 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 4 additions & 0 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 2 additions & 2 deletions
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

Lines changed: 1 addition & 1 deletion
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

Lines changed: 2 additions & 2 deletions
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

0 commit comments

Comments
 (0)