fix up subst_identity vs skip_binder; add some FIXMEs as identified in review
This commit is contained in:
parent
ab40ba2fb1
commit
a969c194d8
compiler
rustc_borrowck/src/diagnostics
rustc_hir_analysis/src
rustc_hir_typeck/src
rustc_mir_transform/src
rustc_privacy/src
rustc_ty_utils/src
@ -1136,7 +1136,9 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
|
||||
&& let self_ty = infcx.replace_bound_vars_with_fresh_vars(
|
||||
fn_call_span,
|
||||
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()
|
||||
{
|
||||
|
@ -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.
|
||||
let mapping = std::iter::zip(
|
||||
tcx.fn_sig(trait_m.def_id).subst_identity().bound_vars(),
|
||||
tcx.fn_sig(impl_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).skip_binder().bound_vars(),
|
||||
)
|
||||
.filter_map(|(impl_bv, trait_bv)| {
|
||||
if let ty::BoundVariableKind::Region(impl_bv) = impl_bv
|
||||
@ -540,7 +540,7 @@ fn compare_asyncness<'tcx>(
|
||||
trait_item_span: Option<Span>,
|
||||
) -> Result<(), ErrorGuaranteed> {
|
||||
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, ..) => {
|
||||
// allow both `async fn foo()` and `fn foo() -> impl Future`
|
||||
}
|
||||
|
@ -867,8 +867,8 @@ fn infer_placeholder_type<'a>(
|
||||
}
|
||||
|
||||
match ty.kind() {
|
||||
ty::FnDef(def_id, _) => {
|
||||
self.tcx.mk_fn_ptr(self.tcx.fn_sig(*def_id).subst_identity())
|
||||
ty::FnDef(def_id, substs) => {
|
||||
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
|
||||
ty::Closure(..) | ty::Generator(..) => {
|
||||
|
@ -603,6 +603,12 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
let substs = ty::InternalSubsts::for_item(self.tcx, m.def_id, |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![
|
||||
(
|
||||
deref.span.until(base.span),
|
||||
@ -611,18 +617,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
with_no_trimmed_paths!(
|
||||
self.tcx.def_path_str_with_substs(m.def_id, substs,)
|
||||
),
|
||||
match self
|
||||
.tcx
|
||||
.fn_sig(m.def_id)
|
||||
.subst_identity()
|
||||
.input(0)
|
||||
.skip_binder()
|
||||
.kind()
|
||||
{
|
||||
ty::Ref(_, _, hir::Mutability::Mut) => "&mut ",
|
||||
ty::Ref(_, _, _) => "&",
|
||||
_ => "",
|
||||
},
|
||||
mutability,
|
||||
),
|
||||
),
|
||||
match &args[..] {
|
||||
|
@ -503,9 +503,7 @@ impl<'a, 'tcx> ConfirmContext<'a, 'tcx> {
|
||||
|
||||
debug!("method_predicates after subst = {:?}", method_predicates);
|
||||
|
||||
let sig = self.tcx.fn_sig(def_id);
|
||||
|
||||
let sig = sig.subst(self.tcx, all_substs);
|
||||
let sig = self.tcx.fn_sig(def_id).subst(self.tcx, all_substs);
|
||||
debug!("type scheme substituted, sig={:?}", sig);
|
||||
|
||||
let sig = self.replace_bound_vars_with_fresh_vars(sig);
|
||||
|
@ -399,8 +399,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
||||
// N.B., instantiate late-bound regions before normalizing the
|
||||
// function signature so that normalization does not need to deal
|
||||
// with bound regions.
|
||||
let fn_sig = tcx.fn_sig(def_id);
|
||||
let fn_sig = fn_sig.subst(self.tcx, substs);
|
||||
let fn_sig = tcx.fn_sig(def_id).subst(self.tcx, substs);
|
||||
let fn_sig =
|
||||
self.replace_bound_vars_with_fresh_vars(obligation.cause.span, infer::FnCall, fn_sig);
|
||||
|
||||
|
@ -921,26 +921,22 @@ impl<'a, 'tcx> ProbeContext<'a, 'tcx> {
|
||||
expected: Ty<'tcx>,
|
||||
) -> bool {
|
||||
match method.kind {
|
||||
ty::AssocKind::Fn => {
|
||||
let fty = self.tcx.fn_sig(method.def_id);
|
||||
self.probe(|_| {
|
||||
let substs = self.fresh_substs_for_item(self.span, method.def_id);
|
||||
let fty = fty.subst(self.tcx, substs);
|
||||
let fty =
|
||||
self.replace_bound_vars_with_fresh_vars(self.span, infer::FnCall, fty);
|
||||
ty::AssocKind::Fn => self.probe(|_| {
|
||||
let substs = self.fresh_substs_for_item(self.span, method.def_id);
|
||||
let fty = self.tcx.fn_sig(method.def_id).subst(self.tcx, substs);
|
||||
let fty = self.replace_bound_vars_with_fresh_vars(self.span, infer::FnCall, fty);
|
||||
|
||||
if let Some(self_ty) = self_ty {
|
||||
if self
|
||||
.at(&ObligationCause::dummy(), self.param_env)
|
||||
.sup(fty.inputs()[0], self_ty)
|
||||
.is_err()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if let Some(self_ty) = self_ty {
|
||||
if self
|
||||
.at(&ObligationCause::dummy(), self.param_env)
|
||||
.sup(fty.inputs()[0], self_ty)
|
||||
.is_err()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
self.can_sub(self.param_env, fty.output(), expected).is_ok()
|
||||
})
|
||||
}
|
||||
}
|
||||
self.can_sub(self.param_env, fty.output(), expected).is_ok()
|
||||
}),
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
@ -161,7 +161,8 @@ impl<'tcx> FunctionItemRefChecker<'_, 'tcx> {
|
||||
.as_ref()
|
||||
.assert_crate_local()
|
||||
.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 abi = match fn_sig.abi() {
|
||||
Abi::Rust => String::from(""),
|
||||
|
@ -198,6 +198,7 @@ where
|
||||
// Something like `fn() -> Priv {my_func}` is considered a private type even if
|
||||
// `my_func` is public, so we need to visit signatures.
|
||||
if let ty::FnDef(..) = ty.kind() {
|
||||
// FIXME: this should probably use `substs` from `FnDef`
|
||||
tcx.fn_sig(def_id).subst_identity().visit_with(self)?;
|
||||
}
|
||||
// Inherent static methods don't have self type in substs.
|
||||
|
@ -9,12 +9,12 @@ pub fn provide(providers: &mut ty::query::Providers) {
|
||||
fn assumed_wf_types(tcx: TyCtxt<'_>, def_id: DefId) -> &ty::List<Ty<'_>> {
|
||||
match tcx.def_kind(def_id) {
|
||||
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);
|
||||
liberated_sig.inputs_and_output
|
||||
}
|
||||
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 mut assumed_wf_types: Vec<_> =
|
||||
tcx.assumed_wf_types(tcx.parent(def_id)).as_slice().into();
|
||||
|
Loading…
x
Reference in New Issue
Block a user