Skip to content

Commit 7919ef0

Browse files
committed
Auto merge of rust-lang#107055 - kylematsuda:eb-fn-sig, r=lcnr
Switch to `EarlyBinder` for `fn_sig` query Part of the work to finish rust-lang#105779 (also see rust-lang/types-team#78). Several queries `X` have a `bound_X` variant that wraps the output in [`EarlyBinder`](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle/ty/subst/struct.EarlyBinder.html). This adds `EarlyBinder` to the return type of the `fn_sig` query and removes `bound_fn_sig`. r? `@lcnr`
2 parents 6874f4e + dc1216b commit 7919ef0

File tree

86 files changed

+193
-172
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

86 files changed

+193
-172
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2599,7 +2599,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
25992599
match ty.kind() {
26002600
ty::FnDef(_, _) | ty::FnPtr(_) => self.annotate_fn_sig(
26012601
self.mir_def_id(),
2602-
self.infcx.tcx.fn_sig(self.mir_def_id()),
2602+
self.infcx.tcx.fn_sig(self.mir_def_id()).subst_identity(),
26032603
),
26042604
_ => None,
26052605
}

compiler/rustc_borrowck/src/diagnostics/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1064,7 +1064,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
10641064
);
10651065
}
10661066
}
1067-
CallKind::Normal { self_arg, desugaring, method_did } => {
1067+
CallKind::Normal { self_arg, desugaring, method_did, method_substs } => {
10681068
let self_arg = self_arg.unwrap();
10691069
let tcx = self.infcx.tcx;
10701070
if let Some((CallDesugaringKind::ForLoopIntoIter, _)) = desugaring {
@@ -1136,7 +1136,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
11361136
&& let self_ty = infcx.replace_bound_vars_with_fresh_vars(
11371137
fn_call_span,
11381138
LateBoundRegionConversionTime::FnCall,
1139-
tcx.fn_sig(method_did).input(0),
1139+
tcx.fn_sig(method_did).subst(tcx, method_substs).input(0),
11401140
)
11411141
&& infcx.can_eq(self.param_env, ty, self_ty).is_ok()
11421142
{

compiler/rustc_borrowck/src/universal_regions.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
472472
// C-variadic fns also have a `VaList` input that's not listed in the signature
473473
// (as it's created inside the body itself, not passed in from outside).
474474
if let DefiningTy::FnDef(def_id, _) = defining_ty {
475-
if self.infcx.tcx.fn_sig(def_id).c_variadic() {
475+
if self.infcx.tcx.fn_sig(def_id).skip_binder().c_variadic() {
476476
let va_list_did = self.infcx.tcx.require_lang_item(
477477
LangItem::VaList,
478478
Some(self.infcx.tcx.def_span(self.mir_def.did)),
@@ -665,7 +665,7 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
665665
}
666666

667667
DefiningTy::FnDef(def_id, _) => {
668-
let sig = tcx.fn_sig(def_id);
668+
let sig = tcx.fn_sig(def_id).subst_identity();
669669
let sig = indices.fold_to_region_vids(tcx, sig);
670670
sig.inputs_and_output()
671671
}

compiler/rustc_codegen_cranelift/src/main_shim.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ pub(crate) fn maybe_create_entry_wrapper(
4646
is_main_fn: bool,
4747
sigpipe: u8,
4848
) {
49-
let main_ret_ty = tcx.fn_sig(rust_main_def_id).output();
49+
let main_ret_ty = tcx.fn_sig(rust_main_def_id).no_bound_vars().unwrap().output();
5050
// Given that `main()` has no arguments,
5151
// then its return type cannot have
5252
// late-bound regions, since late-bound

compiler/rustc_codegen_llvm/src/attributes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ pub fn from_fn_attrs<'ll, 'tcx>(
441441
// the WebAssembly specification, which has this feature. This won't be
442442
// needed when LLVM enables this `multivalue` feature by default.
443443
if !cx.tcx.is_closure(instance.def_id()) {
444-
let abi = cx.tcx.fn_sig(instance.def_id()).abi();
444+
let abi = cx.tcx.fn_sig(instance.def_id()).skip_binder().abi();
445445
if abi == Abi::Wasm {
446446
function_features.push("+multivalue".to_string());
447447
}

compiler/rustc_codegen_ssa/src/base.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ pub fn maybe_create_entry_wrapper<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
436436
cx.type_func(&[], cx.type_int())
437437
};
438438

439-
let main_ret_ty = cx.tcx().fn_sig(rust_main_def_id).output();
439+
let main_ret_ty = cx.tcx().fn_sig(rust_main_def_id).no_bound_vars().unwrap().output();
440440
// Given that `main()` has no arguments,
441441
// then its return type cannot have
442442
// late-bound regions, since late-bound

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: DefId) -> CodegenFnAttrs {
214214
}
215215
} else if attr.has_name(sym::cmse_nonsecure_entry) {
216216
if validate_fn_only_attr(attr.span)
217-
&& !matches!(tcx.fn_sig(did).abi(), abi::Abi::C { .. })
217+
&& !matches!(tcx.fn_sig(did).skip_binder().abi(), abi::Abi::C { .. })
218218
{
219219
struct_span_err!(
220220
tcx.sess,
@@ -234,7 +234,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: DefId) -> CodegenFnAttrs {
234234
} else if attr.has_name(sym::track_caller) {
235235
if !tcx.is_closure(did.to_def_id())
236236
&& validate_fn_only_attr(attr.span)
237-
&& tcx.fn_sig(did).abi() != abi::Abi::Rust
237+
&& tcx.fn_sig(did).skip_binder().abi() != abi::Abi::Rust
238238
{
239239
struct_span_err!(tcx.sess, attr.span, E0737, "`#[track_caller]` requires Rust ABI")
240240
.emit();
@@ -266,7 +266,7 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: DefId) -> CodegenFnAttrs {
266266
}
267267
} else if attr.has_name(sym::target_feature) {
268268
if !tcx.is_closure(did.to_def_id())
269-
&& tcx.fn_sig(did).unsafety() == hir::Unsafety::Normal
269+
&& tcx.fn_sig(did).skip_binder().unsafety() == hir::Unsafety::Normal
270270
{
271271
if tcx.sess.target.is_like_wasm || tcx.sess.opts.actually_rustdoc {
272272
// The `#[target_feature]` attribute is allowed on

compiler/rustc_const_eval/src/const_eval/fn_queries.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fn is_promotable_const_fn(tcx: TyCtxt<'_>, def_id: DefId) -> bool {
6666
if cfg!(debug_assertions) && stab.promotable {
6767
let sig = tcx.fn_sig(def_id);
6868
assert_eq!(
69-
sig.unsafety(),
69+
sig.skip_binder().unsafety(),
7070
hir::Unsafety::Normal,
7171
"don't mark const unsafe fns as promotable",
7272
// https://github.com/rust-lang/rust/pull/53851#issuecomment-418760682

compiler/rustc_const_eval/src/transform/check_consts/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ impl<'mir, 'tcx> ConstCx<'mir, 'tcx> {
7272
let ty::Closure(_, substs) = ty.kind() else { bug!("type_of closure not ty::Closure") };
7373
substs.as_closure().sig()
7474
} else {
75-
self.tcx.fn_sig(did)
75+
self.tcx.fn_sig(did).subst_identity()
7676
}
7777
}
7878
}

compiler/rustc_const_eval/src/util/call_kind.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ pub enum CallKind<'tcx> {
4040
self_arg: Option<Ident>,
4141
desugaring: Option<(CallDesugaringKind, Ty<'tcx>)>,
4242
method_did: DefId,
43+
method_substs: SubstsRef<'tcx>,
4344
},
4445
/// A call to `Fn(..)::call(..)`, desugared from `my_closure(a, b, c)`
4546
FnCall { fn_trait_id: DefId, self_ty: Ty<'tcx> },
@@ -131,6 +132,6 @@ pub fn call_kind<'tcx>(
131132
} else {
132133
None
133134
};
134-
CallKind::Normal { self_arg, desugaring, method_did }
135+
CallKind::Normal { self_arg, desugaring, method_did, method_substs }
135136
})
136137
}

compiler/rustc_hir_analysis/src/astconv/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3140,7 +3140,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
31403140
trait_ref.def_id,
31413141
)?;
31423142

3143-
let fn_sig = tcx.bound_fn_sig(assoc.def_id).subst(
3143+
let fn_sig = tcx.fn_sig(assoc.def_id).subst(
31443144
tcx,
31453145
trait_ref.substs.extend_to(tcx, assoc.def_id, |param, _| tcx.mk_param_from_def(param)),
31463146
);

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -249,15 +249,15 @@ fn compare_method_predicate_entailment<'tcx>(
249249
let unnormalized_impl_sig = infcx.replace_bound_vars_with_fresh_vars(
250250
impl_m_span,
251251
infer::HigherRankedType,
252-
tcx.fn_sig(impl_m.def_id),
252+
tcx.fn_sig(impl_m.def_id).subst_identity(),
253253
);
254254
let unnormalized_impl_fty = tcx.mk_fn_ptr(ty::Binder::dummy(unnormalized_impl_sig));
255255

256256
let norm_cause = ObligationCause::misc(impl_m_span, impl_m_def_id);
257257
let impl_sig = ocx.normalize(&norm_cause, param_env, unnormalized_impl_sig);
258258
debug!("compare_impl_method: impl_fty={:?}", impl_sig);
259259

260-
let trait_sig = tcx.bound_fn_sig(trait_m.def_id).subst(tcx, trait_to_placeholder_substs);
260+
let trait_sig = tcx.fn_sig(trait_m.def_id).subst(tcx, trait_to_placeholder_substs);
261261
let trait_sig = tcx.liberate_late_bound_regions(impl_m.def_id, trait_sig);
262262

263263
// Next, add all inputs and output as well-formed tys. Importantly,
@@ -422,8 +422,8 @@ fn extract_bad_args_for_implies_lint<'tcx>(
422422

423423
// Map late-bound regions from trait to impl, so the names are right.
424424
let mapping = std::iter::zip(
425-
tcx.fn_sig(trait_m.def_id).bound_vars(),
426-
tcx.fn_sig(impl_m.def_id).bound_vars(),
425+
tcx.fn_sig(trait_m.def_id).skip_binder().bound_vars(),
426+
tcx.fn_sig(impl_m.def_id).skip_binder().bound_vars(),
427427
)
428428
.filter_map(|(impl_bv, trait_bv)| {
429429
if let ty::BoundVariableKind::Region(impl_bv) = impl_bv
@@ -540,7 +540,7 @@ fn compare_asyncness<'tcx>(
540540
trait_item_span: Option<Span>,
541541
) -> Result<(), ErrorGuaranteed> {
542542
if tcx.asyncness(trait_m.def_id) == hir::IsAsync::Async {
543-
match tcx.fn_sig(impl_m.def_id).skip_binder().output().kind() {
543+
match tcx.fn_sig(impl_m.def_id).skip_binder().skip_binder().output().kind() {
544544
ty::Alias(ty::Opaque, ..) => {
545545
// allow both `async fn foo()` and `fn foo() -> impl Future`
546546
}
@@ -643,7 +643,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
643643
infcx.replace_bound_vars_with_fresh_vars(
644644
return_span,
645645
infer::HigherRankedType,
646-
tcx.fn_sig(impl_m.def_id),
646+
tcx.fn_sig(impl_m.def_id).subst_identity(),
647647
),
648648
);
649649
impl_sig.error_reported()?;
@@ -657,7 +657,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
657657
let unnormalized_trait_sig = tcx
658658
.liberate_late_bound_regions(
659659
impl_m.def_id,
660-
tcx.bound_fn_sig(trait_m.def_id).subst(tcx, trait_to_placeholder_substs),
660+
tcx.fn_sig(trait_m.def_id).subst(tcx, trait_to_placeholder_substs),
661661
)
662662
.fold_with(&mut collector);
663663
let trait_sig = ocx.normalize(&norm_cause, param_env, unnormalized_trait_sig);
@@ -1117,7 +1117,7 @@ fn compare_self_type<'tcx>(
11171117
ty::ImplContainer => impl_trait_ref.self_ty(),
11181118
ty::TraitContainer => tcx.types.self_param,
11191119
};
1120-
let self_arg_ty = tcx.fn_sig(method.def_id).input(0);
1120+
let self_arg_ty = tcx.fn_sig(method.def_id).subst_identity().input(0);
11211121
let param_env = ty::ParamEnv::reveal_all();
11221122

11231123
let infcx = tcx.infer_ctxt().build();
@@ -1350,8 +1350,8 @@ fn compare_number_of_method_arguments<'tcx>(
13501350
) -> Result<(), ErrorGuaranteed> {
13511351
let impl_m_fty = tcx.fn_sig(impl_m.def_id);
13521352
let trait_m_fty = tcx.fn_sig(trait_m.def_id);
1353-
let trait_number_args = trait_m_fty.inputs().skip_binder().len();
1354-
let impl_number_args = impl_m_fty.inputs().skip_binder().len();
1353+
let trait_number_args = trait_m_fty.skip_binder().inputs().skip_binder().len();
1354+
let impl_number_args = impl_m_fty.skip_binder().inputs().skip_binder().len();
13551355

13561356
if trait_number_args != impl_number_args {
13571357
let trait_span = trait_m

compiler/rustc_hir_analysis/src/check/intrinsic.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,12 @@ fn equate_intrinsic_type<'tcx>(
5858
let fty = tcx.mk_fn_ptr(sig);
5959
let it_def_id = it.owner_id.def_id;
6060
let cause = ObligationCause::new(it.span, it_def_id, ObligationCauseCode::IntrinsicType);
61-
require_same_types(tcx, &cause, tcx.mk_fn_ptr(tcx.fn_sig(it.owner_id)), fty);
61+
require_same_types(
62+
tcx,
63+
&cause,
64+
tcx.mk_fn_ptr(tcx.fn_sig(it.owner_id).subst_identity()),
65+
fty,
66+
);
6267
}
6368
}
6469

compiler/rustc_hir_analysis/src/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -445,7 +445,7 @@ fn suggestion_signature(assoc: &ty::AssocItem, tcx: TyCtxt<'_>) -> String {
445445
// regions just fine, showing `fn(&MyType)`.
446446
fn_sig_suggestion(
447447
tcx,
448-
tcx.fn_sig(assoc.def_id).skip_binder(),
448+
tcx.fn_sig(assoc.def_id).subst_identity().skip_binder(),
449449
assoc.ident(tcx),
450450
tcx.predicates_of(assoc.def_id),
451451
assoc,

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,7 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, associated_items: &[hir::TraitItemRe
386386
// `Self::Iter<'a>` is a GAT we want to gather any potential missing bounds from.
387387
let sig: ty::FnSig<'_> = tcx.liberate_late_bound_regions(
388388
item_def_id.to_def_id(),
389-
tcx.fn_sig(item_def_id),
389+
tcx.fn_sig(item_def_id).subst_identity(),
390390
);
391391
gather_gat_bounds(
392392
tcx,
@@ -1018,7 +1018,7 @@ fn check_associated_item(
10181018
wfcx.register_wf_obligation(span, loc, ty.into());
10191019
}
10201020
ty::AssocKind::Fn => {
1021-
let sig = tcx.fn_sig(item.def_id);
1021+
let sig = tcx.fn_sig(item.def_id).subst_identity();
10221022
let hir_sig = sig_if_method.expect("bad signature for method");
10231023
check_fn_or_method(
10241024
wfcx,
@@ -1203,7 +1203,7 @@ fn check_item_fn(
12031203
decl: &hir::FnDecl<'_>,
12041204
) {
12051205
enter_wf_checking_ctxt(tcx, span, def_id, |wfcx| {
1206-
let sig = tcx.fn_sig(def_id);
1206+
let sig = tcx.fn_sig(def_id).subst_identity();
12071207
check_fn_or_method(wfcx, ident.span, sig, decl, def_id);
12081208
})
12091209
}
@@ -1638,7 +1638,7 @@ fn check_method_receiver<'tcx>(
16381638

16391639
let span = fn_sig.decl.inputs[0].span;
16401640

1641-
let sig = tcx.fn_sig(method.def_id);
1641+
let sig = tcx.fn_sig(method.def_id).subst_identity();
16421642
let sig = tcx.liberate_late_bound_regions(method.def_id, sig);
16431643
let sig = wfcx.normalize(span, None, sig);
16441644

compiler/rustc_hir_analysis/src/collect.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -1087,7 +1087,7 @@ pub fn get_infer_ret_ty<'hir>(output: &'hir hir::FnRetTy<'hir>) -> Option<&'hir
10871087
}
10881088

10891089
#[instrument(level = "debug", skip(tcx))]
1090-
fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> {
1090+
fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::EarlyBinder<ty::PolyFnSig<'_>> {
10911091
use rustc_hir::Node::*;
10921092
use rustc_hir::*;
10931093

@@ -1096,7 +1096,7 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> {
10961096

10971097
let icx = ItemCtxt::new(tcx, def_id.to_def_id());
10981098

1099-
match tcx.hir().get(hir_id) {
1099+
let output = match tcx.hir().get(hir_id) {
11001100
TraitItem(hir::TraitItem {
11011101
kind: TraitItemKind::Fn(sig, TraitFn::Provided(_)),
11021102
generics,
@@ -1169,7 +1169,8 @@ fn fn_sig(tcx: TyCtxt<'_>, def_id: DefId) -> ty::PolyFnSig<'_> {
11691169
x => {
11701170
bug!("unexpected sort of node in fn_sig(): {:?}", x);
11711171
}
1172-
}
1172+
};
1173+
ty::EarlyBinder(output)
11731174
}
11741175

11751176
fn infer_return_ty_for_fn_sig<'tcx>(

compiler/rustc_hir_analysis/src/collect/type_of.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,9 @@ fn infer_placeholder_type<'a>(
867867
}
868868

869869
match ty.kind() {
870-
ty::FnDef(def_id, _) => self.tcx.mk_fn_ptr(self.tcx.fn_sig(*def_id)),
870+
ty::FnDef(def_id, substs) => {
871+
self.tcx.mk_fn_ptr(self.tcx.fn_sig(*def_id).subst(self.tcx, substs))
872+
}
871873
// FIXME: non-capturing closures should also suggest a function pointer
872874
ty::Closure(..) | ty::Generator(..) => {
873875
self.success = false;

compiler/rustc_hir_analysis/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ fn require_same_types<'tcx>(
182182
}
183183

184184
fn check_main_fn_ty(tcx: TyCtxt<'_>, main_def_id: DefId) {
185-
let main_fnsig = tcx.fn_sig(main_def_id);
185+
let main_fnsig = tcx.fn_sig(main_def_id).subst_identity();
186186
let main_span = tcx.def_span(main_def_id);
187187

188188
fn main_fn_diagnostics_def_id(tcx: TyCtxt<'_>, def_id: DefId, sp: Span) -> LocalDefId {
@@ -449,7 +449,7 @@ fn check_start_fn_ty(tcx: TyCtxt<'_>, start_def_id: DefId) {
449449
ObligationCauseCode::StartFunctionType,
450450
),
451451
se_ty,
452-
tcx.mk_fn_ptr(tcx.fn_sig(start_def_id)),
452+
tcx.mk_fn_ptr(tcx.fn_sig(start_def_id).subst_identity()),
453453
);
454454
}
455455
_ => {

compiler/rustc_hir_analysis/src/variance/constraints.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,11 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
119119
}
120120

121121
ty::FnDef(..) => {
122-
self.add_constraints_from_sig(current_item, tcx.fn_sig(def_id), self.covariant);
122+
self.add_constraints_from_sig(
123+
current_item,
124+
tcx.fn_sig(def_id).subst_identity(),
125+
self.covariant,
126+
);
123127
}
124128

125129
ty::Error(_) => {}

compiler/rustc_hir_typeck/src/callee.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
367367
) -> Ty<'tcx> {
368368
let (fn_sig, def_id) = match *callee_ty.kind() {
369369
ty::FnDef(def_id, subst) => {
370-
let fn_sig = self.tcx.bound_fn_sig(def_id).subst(self.tcx, subst);
370+
let fn_sig = self.tcx.fn_sig(def_id).subst(self.tcx, subst);
371371

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

0 commit comments

Comments
 (0)