1
Fork 0

fix up subst_identity vs skip_binder; add some FIXMEs as identified in review

This commit is contained in:
Kyle Matsuda 2023-01-19 12:52:52 -07:00
parent ab40ba2fb1
commit a969c194d8
10 changed files with 36 additions and 44 deletions

View file

@ -1136,7 +1136,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
&& let self_ty = infcx.replace_bound_vars_with_fresh_vars( && let self_ty = infcx.replace_bound_vars_with_fresh_vars(
fn_call_span, fn_call_span,
LateBoundRegionConversionTime::FnCall, LateBoundRegionConversionTime::FnCall,
tcx.fn_sig(method_did).subst_identity().input(0), // FIXME: should use `subst` with the method substs.
// Probably need to add `method_substs` to `CallKind`
tcx.fn_sig(method_did).skip_binder().input(0),
) )
&& infcx.can_eq(self.param_env, ty, self_ty).is_ok() && infcx.can_eq(self.param_env, ty, self_ty).is_ok()
{ {

View file

@ -422,8 +422,8 @@ fn extract_bad_args_for_implies_lint<'tcx>(
// Map late-bound regions from trait to impl, so the names are right. // Map late-bound regions from trait to impl, so the names are right.
let mapping = std::iter::zip( let mapping = std::iter::zip(
tcx.fn_sig(trait_m.def_id).subst_identity().bound_vars(), tcx.fn_sig(trait_m.def_id).skip_binder().bound_vars(),
tcx.fn_sig(impl_m.def_id).subst_identity().bound_vars(), tcx.fn_sig(impl_m.def_id).skip_binder().bound_vars(),
) )
.filter_map(|(impl_bv, trait_bv)| { .filter_map(|(impl_bv, trait_bv)| {
if let ty::BoundVariableKind::Region(impl_bv) = impl_bv if let ty::BoundVariableKind::Region(impl_bv) = impl_bv
@ -540,7 +540,7 @@ fn compare_asyncness<'tcx>(
trait_item_span: Option<Span>, trait_item_span: Option<Span>,
) -> Result<(), ErrorGuaranteed> { ) -> Result<(), ErrorGuaranteed> {
if tcx.asyncness(trait_m.def_id) == hir::IsAsync::Async { if tcx.asyncness(trait_m.def_id) == hir::IsAsync::Async {
match tcx.fn_sig(impl_m.def_id).subst_identity().skip_binder().output().kind() { match tcx.fn_sig(impl_m.def_id).skip_binder().skip_binder().output().kind() {
ty::Alias(ty::Opaque, ..) => { ty::Alias(ty::Opaque, ..) => {
// allow both `async fn foo()` and `fn foo() -> impl Future` // allow both `async fn foo()` and `fn foo() -> impl Future`
} }

View file

@ -867,8 +867,8 @@ fn infer_placeholder_type<'a>(
} }
match ty.kind() { match ty.kind() {
ty::FnDef(def_id, _) => { ty::FnDef(def_id, substs) => {
self.tcx.mk_fn_ptr(self.tcx.fn_sig(*def_id).subst_identity()) self.tcx.mk_fn_ptr(self.tcx.fn_sig(*def_id).subst(self.tcx, substs))
} }
// FIXME: non-capturing closures should also suggest a function pointer // FIXME: non-capturing closures should also suggest a function pointer
ty::Closure(..) | ty::Generator(..) => { ty::Closure(..) | ty::Generator(..) => {

View file

@ -603,6 +603,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
let substs = ty::InternalSubsts::for_item(self.tcx, m.def_id, |param, _| { let substs = ty::InternalSubsts::for_item(self.tcx, m.def_id, |param, _| {
self.var_for_def(deref.span, param) self.var_for_def(deref.span, param)
}); });
let mutability =
match self.tcx.fn_sig(m.def_id).skip_binder().input(0).skip_binder().kind() {
ty::Ref(_, _, hir::Mutability::Mut) => "&mut ",
ty::Ref(_, _, _) => "&",
_ => "",
};
vec![ vec![
( (
deref.span.until(base.span), deref.span.until(base.span),
@ -611,18 +617,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
with_no_trimmed_paths!( with_no_trimmed_paths!(
self.tcx.def_path_str_with_substs(m.def_id, substs,) self.tcx.def_path_str_with_substs(m.def_id, substs,)
), ),
match self mutability,
.tcx
.fn_sig(m.def_id)
.subst_identity()
.input(0)
.skip_binder()
.kind()
{
ty::Ref(_, _, hir::Mutability::Mut) => "&mut ",
ty::Ref(_, _, _) => "&",
_ => "",
},
), ),
), ),
match &args[..] { match &args[..] {

View file

@ -503,9 +503,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
debug!("method_predicates after subst = {:?}", method_predicates); debug!("method_predicates after subst = {:?}", method_predicates);
let sig = self.tcx.fn_sig(def_id); let sig = self.tcx.fn_sig(def_id).subst(self.tcx, all_substs);
let sig = sig.subst(self.tcx, all_substs);
debug!("type scheme substituted, sig={:?}", sig); debug!("type scheme substituted, sig={:?}", sig);
let sig = self.replace_bound_vars_with_fresh_vars(sig); let sig = self.replace_bound_vars_with_fresh_vars(sig);

View file

@ -399,8 +399,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
// N.B., instantiate late-bound regions before normalizing the // N.B., instantiate late-bound regions before normalizing the
// function signature so that normalization does not need to deal // function signature so that normalization does not need to deal
// with bound regions. // with bound regions.
let fn_sig = tcx.fn_sig(def_id); let fn_sig = tcx.fn_sig(def_id).subst(self.tcx, substs);
let fn_sig = fn_sig.subst(self.tcx, substs);
let fn_sig = let fn_sig =
self.replace_bound_vars_with_fresh_vars(obligation.cause.span, infer::FnCall, fn_sig); self.replace_bound_vars_with_fresh_vars(obligation.cause.span, infer::FnCall, fn_sig);

View file

@ -921,13 +921,10 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
expected: Ty<'tcx>, expected: Ty<'tcx>,
) -> bool { ) -> bool {
match method.kind { match method.kind {
ty::AssocKind::Fn => { ty::AssocKind::Fn => self.probe(|_| {
let fty = self.tcx.fn_sig(method.def_id);
self.probe(|_| {
let substs = self.fresh_substs_for_item(self.span, method.def_id); let substs = self.fresh_substs_for_item(self.span, method.def_id);
let fty = fty.subst(self.tcx, substs); let fty = self.tcx.fn_sig(method.def_id).subst(self.tcx, substs);
let fty = let fty = self.replace_bound_vars_with_fresh_vars(self.span, infer::FnCall, fty);
self.replace_bound_vars_with_fresh_vars(self.span, infer::FnCall, fty);
if let Some(self_ty) = self_ty { if let Some(self_ty) = self_ty {
if self if self
@ -939,8 +936,7 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
} }
} }
self.can_sub(self.param_env, fty.output(), expected).is_ok() self.can_sub(self.param_env, fty.output(), expected).is_ok()
}) }),
}
_ => false, _ => false,
} }
} }

View file

@ -161,7 +161,8 @@ impl<'tcx> FunctionItemRefChecker<'_, 'tcx> {
.as_ref() .as_ref()
.assert_crate_local() .assert_crate_local()
.lint_root; .lint_root;
let fn_sig = self.tcx.fn_sig(fn_id).skip_binder(); // FIXME: use existing printing routines to print the function signature
let fn_sig = self.tcx.fn_sig(fn_id).subst(self.tcx, fn_substs);
let unsafety = fn_sig.unsafety().prefix_str(); let unsafety = fn_sig.unsafety().prefix_str();
let abi = match fn_sig.abi() { let abi = match fn_sig.abi() {
Abi::Rust => String::from(""), Abi::Rust => String::from(""),

View file

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

View file

@ -9,12 +9,12 @@ pub fn provide(providers: &mut ty::query::Providers) {
fn assumed_wf_types(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::List<Ty<'_>> { fn assumed_wf_types(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::List<Ty<'_>> {
match tcx.def_kind(def_id) { match tcx.def_kind(def_id) {
DefKind::Fn => { DefKind::Fn => {
let sig = tcx.fn_sig(def_id).skip_binder(); let sig = tcx.fn_sig(def_id).subst_identity();
let liberated_sig = tcx.liberate_late_bound_regions(def_id, sig); let liberated_sig = tcx.liberate_late_bound_regions(def_id, sig);
liberated_sig.inputs_and_output liberated_sig.inputs_and_output
} }
DefKind::AssocFn => { DefKind::AssocFn => {
let sig = tcx.fn_sig(def_id).skip_binder(); let sig = tcx.fn_sig(def_id).subst_identity();
let liberated_sig = tcx.liberate_late_bound_regions(def_id, sig); let liberated_sig = tcx.liberate_late_bound_regions(def_id, sig);
let mut assumed_wf_types: Vec<_> = let mut assumed_wf_types: Vec<_> =
tcx.assumed_wf_types(tcx.parent(def_id)).as_slice().into(); tcx.assumed_wf_types(tcx.parent(def_id)).as_slice().into();