Skip to content

Commit a969c19

Browse files
committed
fix up subst_identity vs skip_binder; add some FIXMEs as identified in review
1 parent ab40ba2 commit a969c19

File tree

10 files changed

+37
-45
lines changed

10 files changed

+37
-45
lines changed

compiler/rustc_borrowck/src/diagnostics/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,9 @@ 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).subst_identity().input(0),
1139+
// FIXME: should use `subst` with the method substs.
1140+
// Probably need to add `method_substs` to `CallKind`
1141+
tcx.fn_sig(method_did).skip_binder().input(0),
11401142
)
11411143
&& infcx.can_eq(self.param_env, ty, self_ty).is_ok()
11421144
{

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -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).subst_identity().bound_vars(),
426-
tcx.fn_sig(impl_m.def_id).subst_identity().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).subst_identity().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
}

compiler/rustc_hir_analysis/src/collect/type_of.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -867,8 +867,8 @@ fn infer_placeholder_type<'a>(
867867
}
868868

869869
match ty.kind() {
870-
ty::FnDef(def_id, _) => {
871-
self.tcx.mk_fn_ptr(self.tcx.fn_sig(*def_id).subst_identity())
870+
ty::FnDef(def_id, substs) => {
871+
self.tcx.mk_fn_ptr(self.tcx.fn_sig(*def_id).subst(self.tcx, substs))
872872
}
873873
// FIXME: non-capturing closures should also suggest a function pointer
874874
ty::Closure(..) | ty::Generator(..) => {

compiler/rustc_hir_typeck/src/demand.rs

+7-12
Original file line numberDiff line numberDiff line change
@@ -603,6 +603,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
603603
let substs = ty::InternalSubsts::for_item(self.tcx, m.def_id, |param, _| {
604604
self.var_for_def(deref.span, param)
605605
});
606+
let mutability =
607+
match self.tcx.fn_sig(m.def_id).skip_binder().input(0).skip_binder().kind() {
608+
ty::Ref(_, _, hir::Mutability::Mut) => "&mut ",
609+
ty::Ref(_, _, _) => "&",
610+
_ => "",
611+
};
606612
vec![
607613
(
608614
deref.span.until(base.span),
@@ -611,18 +617,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
611617
with_no_trimmed_paths!(
612618
self.tcx.def_path_str_with_substs(m.def_id, substs,)
613619
),
614-
match self
615-
.tcx
616-
.fn_sig(m.def_id)
617-
.subst_identity()
618-
.input(0)
619-
.skip_binder()
620-
.kind()
621-
{
622-
ty::Ref(_, _, hir::Mutability::Mut) => "&mut ",
623-
ty::Ref(_, _, _) => "&",
624-
_ => "",
625-
},
620+
mutability,
626621
),
627622
),
628623
match &args[..] {

compiler/rustc_hir_typeck/src/method/confirm.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -503,9 +503,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
503503

504504
debug!("method_predicates after subst = {:?}", method_predicates);
505505

506-
let sig = self.tcx.fn_sig(def_id);
507-
508-
let sig = sig.subst(self.tcx, all_substs);
506+
let sig = self.tcx.fn_sig(def_id).subst(self.tcx, all_substs);
509507
debug!("type scheme substituted, sig={:?}", sig);
510508

511509
let sig = self.replace_bound_vars_with_fresh_vars(sig);

compiler/rustc_hir_typeck/src/method/mod.rs

+1-2
Original file line numberDiff line numberDiff line change
@@ -399,8 +399,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
399399
// N.B., instantiate late-bound regions before normalizing the
400400
// function signature so that normalization does not need to deal
401401
// with bound regions.
402-
let fn_sig = tcx.fn_sig(def_id);
403-
let fn_sig = fn_sig.subst(self.tcx, substs);
402+
let fn_sig = tcx.fn_sig(def_id).subst(self.tcx, substs);
404403
let fn_sig =
405404
self.replace_bound_vars_with_fresh_vars(obligation.cause.span, infer::FnCall, fn_sig);
406405

compiler/rustc_hir_typeck/src/method/probe.rs

+15-19
Original file line numberDiff line numberDiff line change
@@ -921,26 +921,22 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
921921
expected: Ty<'tcx>,
922922
) -> bool {
923923
match method.kind {
924-
ty::AssocKind::Fn => {
925-
let fty = self.tcx.fn_sig(method.def_id);
926-
self.probe(|_| {
927-
let substs = self.fresh_substs_for_item(self.span, method.def_id);
928-
let fty = fty.subst(self.tcx, substs);
929-
let fty =
930-
self.replace_bound_vars_with_fresh_vars(self.span, infer::FnCall, fty);
931-
932-
if let Some(self_ty) = self_ty {
933-
if self
934-
.at(&ObligationCause::dummy(), self.param_env)
935-
.sup(fty.inputs()[0], self_ty)
936-
.is_err()
937-
{
938-
return false;
939-
}
924+
ty::AssocKind::Fn => self.probe(|_| {
925+
let substs = self.fresh_substs_for_item(self.span, method.def_id);
926+
let fty = self.tcx.fn_sig(method.def_id).subst(self.tcx, substs);
927+
let fty = self.replace_bound_vars_with_fresh_vars(self.span, infer::FnCall, fty);
928+
929+
if let Some(self_ty) = self_ty {
930+
if self
931+
.at(&ObligationCause::dummy(), self.param_env)
932+
.sup(fty.inputs()[0], self_ty)
933+
.is_err()
934+
{
935+
return false;
940936
}
941-
self.can_sub(self.param_env, fty.output(), expected).is_ok()
942-
})
943-
}
937+
}
938+
self.can_sub(self.param_env, fty.output(), expected).is_ok()
939+
}),
944940
_ => false,
945941
}
946942
}

compiler/rustc_mir_transform/src/function_item_references.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,8 @@ impl<'tcx> FunctionItemRefChecker<'_, 'tcx> {
161161
.as_ref()
162162
.assert_crate_local()
163163
.lint_root;
164-
let fn_sig = self.tcx.fn_sig(fn_id).skip_binder();
164+
// FIXME: use existing printing routines to print the function signature
165+
let fn_sig = self.tcx.fn_sig(fn_id).subst(self.tcx, fn_substs);
165166
let unsafety = fn_sig.unsafety().prefix_str();
166167
let abi = match fn_sig.abi() {
167168
Abi::Rust => String::from(""),

compiler/rustc_privacy/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,7 @@ where
198198
// Something like `fn() -> Priv {my_func}` is considered a private type even if
199199
// `my_func` is public, so we need to visit signatures.
200200
if let ty::FnDef(..) = ty.kind() {
201+
// FIXME: this should probably use `substs` from `FnDef`
201202
tcx.fn_sig(def_id).subst_identity().visit_with(self)?;
202203
}
203204
// Inherent static methods don't have self type in substs.

compiler/rustc_ty_utils/src/implied_bounds.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ pub fn provide(providers: &mut ty::query::Providers) {
99
fn assumed_wf_types(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::List<Ty<'_>> {
1010
match tcx.def_kind(def_id) {
1111
DefKind::Fn => {
12-
let sig = tcx.fn_sig(def_id).skip_binder();
12+
let sig = tcx.fn_sig(def_id).subst_identity();
1313
let liberated_sig = tcx.liberate_late_bound_regions(def_id, sig);
1414
liberated_sig.inputs_and_output
1515
}
1616
DefKind::AssocFn => {
17-
let sig = tcx.fn_sig(def_id).skip_binder();
17+
let sig = tcx.fn_sig(def_id).subst_identity();
1818
let liberated_sig = tcx.liberate_late_bound_regions(def_id, sig);
1919
let mut assumed_wf_types: Vec<_> =
2020
tcx.assumed_wf_types(tcx.parent(def_id)).as_slice().into();

0 commit comments

Comments
 (0)