Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 23 additions & 24 deletions compiler/rustc_hir_analysis/src/collect/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,13 +63,26 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_

let icx = ItemCtxt::new(tcx, def_id);

let new_bound_fn_def = |hir: HirId, did| {
let args = ty::GenericArgs::identity_for_item(tcx, def_id);
Ty::new_fn_def(
tcx,
did,
match &tcx
.late_bound_vars_map(hir.owner)
.get(&hir.local_id)
.cloned()
.map(|x| tcx.mk_bound_variable_kinds(&x))
{
Some(late_bound) => ty::Binder::bind_with_vars(args, late_bound),
None => ty::Binder::dummy(args),
},
)
};

let output = match tcx.hir_node(hir_id) {
Node::TraitItem(item) => match item.kind {
TraitItemKind::Fn(..) => {
let args = ty::GenericArgs::identity_for_item(tcx, def_id);
// FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes)
Ty::new_fn_def(tcx, def_id.to_def_id(), ty::Binder::dummy(args))
}
TraitItemKind::Fn(_, _) => new_bound_fn_def(item.hir_id(), def_id.to_def_id()),
TraitItemKind::Const(ty, rhs) => rhs
.and_then(|rhs| {
ty.is_suggestable_infer_ty().then(|| {
Expand All @@ -92,11 +105,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
},

Node::ImplItem(item) => match item.kind {
ImplItemKind::Fn(..) => {
let args = ty::GenericArgs::identity_for_item(tcx, def_id);
// FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes)
Ty::new_fn_def(tcx, def_id.to_def_id(), ty::Binder::dummy(args))
}
ImplItemKind::Fn(_, _) => new_bound_fn_def(item.hir_id(), def_id.to_def_id()),
ImplItemKind::Const(ty, rhs) => {
if ty.is_suggestable_infer_ty() {
infer_placeholder_type(
Expand Down Expand Up @@ -171,11 +180,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
}
_ => icx.lower_ty(self_ty),
},
ItemKind::Fn { .. } => {
let args = ty::GenericArgs::identity_for_item(tcx, def_id);
// FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes)
Ty::new_fn_def(tcx, def_id.to_def_id(), ty::Binder::dummy(args))
}
ItemKind::Fn { .. } => new_bound_fn_def(item.hir_id(), def_id.to_def_id()),
ItemKind::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) => {
let def = tcx.adt_def(def_id);
let args = ty::GenericArgs::identity_for_item(tcx, def_id);
Expand All @@ -196,10 +201,8 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
Node::OpaqueTy(..) => tcx.type_of_opaque(def_id).instantiate_identity().skip_norm_wip(),

Node::ForeignItem(foreign_item) => match foreign_item.kind {
ForeignItemKind::Fn(..) => {
let args = ty::GenericArgs::identity_for_item(tcx, def_id);
// FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes)
Ty::new_fn_def(tcx, def_id.to_def_id(), ty::Binder::dummy(args))
ForeignItemKind::Fn(_, _, _generics) => {
new_bound_fn_def(foreign_item.hir_id(), def_id.to_def_id())
}
ForeignItemKind::Static(ty, _, _) => {
let ty = icx.lower_ty(ty);
Expand All @@ -219,11 +222,7 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
VariantData::Unit(..) | VariantData::Struct { .. } => {
tcx.type_of(tcx.hir_get_parent_item(hir_id)).instantiate_identity().skip_norm_wip()
}
VariantData::Tuple(_, _, ctor) => {
let args = ty::GenericArgs::identity_for_item(tcx, def_id);
// FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes)
Ty::new_fn_def(tcx, ctor.to_def_id(), ty::Binder::dummy(args))
}
VariantData::Tuple(_, hir_id, ctor) => new_bound_fn_def(*hir_id, ctor.to_def_id()),
},

Node::Field(field) => icx.lower_ty(field.ty),
Expand Down
11 changes: 4 additions & 7 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1483,13 +1483,10 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
Ok(ct)
}
TypeRelativePath::Ctor { ctor_def_id, args } => match tcx.def_kind(ctor_def_id) {
DefKind::Ctor(_, CtorKind::Fn) => {
// FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes)
Ok(ty::Const::zero_sized(
tcx,
tcx.type_of(ctor_def_id).instantiate(tcx, args).skip_norm_wip(),
))
}
DefKind::Ctor(_, CtorKind::Fn) => Ok(ty::Const::zero_sized(
tcx,
tcx.type_of(ctor_def_id).instantiate(tcx, args).skip_norm_wip(),
)),
DefKind::Ctor(ctor_of, CtorKind::Const) => {
Ok(self.construct_const_ctor_value(ctor_def_id, ctor_of, args))
}
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_middle/src/ty/sty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,6 @@ impl<'tcx> Ty<'tcx> {
tcx.def_kind(def_id),
DefKind::AssocFn | DefKind::Fn | DefKind::Ctor(_, CtorKind::Fn)
);
// FIXME(156581): check that the binder is being used correctly (turbofishing/fndef changes)
let args = args.map_bound(|args| tcx.check_and_mk_args(def_id, args));
Ty::new(tcx, FnDef(def_id, args))
}
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_mir_build/src/builder/expr/into.rs
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
let success = this.cfg.start_new_block();
let clone_trait = this.tcx.require_lang_item(LangItem::Clone, span);
let clone_fn = this.tcx.associated_item_def_ids(clone_trait)[0];
// FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes)
let func =
Operand::function_handle(this.tcx, clone_fn, &[ty.into()], expr_span);
let ref_ty = Ty::new_imm_ref(this.tcx, this.tcx.lifetimes.re_erased, ty);
Expand Down
17 changes: 10 additions & 7 deletions compiler/rustc_mir_transform/src/elaborate_drop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,11 +247,19 @@ where
// Resolving async_drop_in_place<T> function for drop_ty
tcx.require_lang_item(LangItem::AsyncDropInPlace, span)
};
let async_drop_fn_sig = tcx.fn_sig(async_drop_fn_def_id);

let fut_ty = tcx
.instantiate_bound_regions_with_erased(
// FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes)
Ty::new_fn_def(tcx, async_drop_fn_def_id, ty::Binder::dummy([drop_ty])).fn_sig(tcx),
Ty::new_fn_def(
tcx,
async_drop_fn_def_id,
async_drop_fn_sig
.instantiate(tcx, &[drop_ty.into()])
.skip_norm_wip()
.rebind([drop_ty]),
)
.fn_sig(tcx),
)
.output();
let fut = self.new_temp(fut_ty);
Expand Down Expand Up @@ -373,7 +381,6 @@ where
unwind_with_dead,
vec![self.storage_live(fut)],
TerminatorKind::Call {
// FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes)
func: Operand::function_handle(tcx, async_drop_fn_def_id, &[drop_ty.into()], span),
args: [dummy_spanned(drop_arg)].into(),
destination: fut.into(),
Expand Down Expand Up @@ -402,7 +409,6 @@ where
func: Operand::function_handle(
tcx,
pin_obj_new_unchecked_fn,
// FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes)
&[obj_ref_ty.into()],
span,
),
Expand Down Expand Up @@ -568,7 +574,6 @@ where
unwind,
Vec::new(),
TerminatorKind::Call {
// FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes)
func: Operand::function_handle(tcx, poll_fn, &[fut_ty.into()], source_info.span),
args: [
dummy_spanned(Operand::Move(fut_pin_local.into())),
Expand Down Expand Up @@ -598,7 +603,6 @@ where
func: Operand::function_handle(
tcx,
get_context_fn,
// FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes)
&[tcx.lifetimes.re_erased.into(), tcx.lifetimes.re_erased.into()],
source_info.span,
),
Expand Down Expand Up @@ -1252,7 +1256,6 @@ where
),
)],
TerminatorKind::Call {
// FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes)
func: Operand::function_handle(tcx, drop_fn, &[ty.into()], self.source_info.span),
args: [dummy_spanned(Operand::Move(Place::from(ref_place)))].into(),
destination: unit_temp,
Expand Down
2 changes: 0 additions & 2 deletions compiler/rustc_mir_transform/src/shim.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,6 @@ pub fn build_drop_shim<'tcx>(
start.terminator = Some(Terminator {
source_info,
kind: TerminatorKind::Call {
// FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes)
func: Operand::function_handle(
tcx,
def_id,
Expand Down Expand Up @@ -622,7 +621,6 @@ impl<'tcx> CloneShimBuilder<'tcx> {
let tcx = self.tcx;

// `func == Clone::clone(&ty) -> ty`
// FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes)
let func_ty = tcx.type_of(self.def_id).instantiate(tcx, &[ty.into()]).skip_norm_wip();
let func = Operand::Constant(Box::new(ConstOperand {
span: self.span,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -370,7 +370,6 @@ fn build_adrop_for_adrop_shim<'tcx>(
Some(Terminator {
source_info,
kind: TerminatorKind::Call {
// FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes)
func: Operand::function_handle(tcx, pin_fn, &[cor_ref.into()], span),
args: [dummy_spanned(Operand::Move(cor_ref_place))].into(),
destination: cor_pin_place,
Expand All @@ -392,7 +391,6 @@ fn build_adrop_for_adrop_shim<'tcx>(
Some(Terminator {
source_info,
kind: TerminatorKind::Call {
// FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes)
func: Operand::function_handle(tcx, poll_fn, &[impl_ty.into()], span),
args: [
dummy_spanned(Operand::Move(cor_pin_place)),
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_next_trait_solver/src/canonical/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ where
relate_args_invariantly(self, a_args, b_args)?;
Ok(a_ty)
}

fn relate_with_variance<T: Relate<I>>(
&mut self,
_variance: ty::Variance,
Expand Down
19 changes: 11 additions & 8 deletions compiler/rustc_type_ir/src/relate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ pub trait TypeRelation<I: Interner>: Sized {
a_ty: I::Ty,
b_ty: I::Ty,
ty_def_id: I::DefId,
a_arg: I::GenericArgs,
b_arg: I::GenericArgs,
a_args: I::GenericArgs,
b_args: I::GenericArgs,
mk: impl FnOnce(I::GenericArgs) -> I::Ty,
) -> RelateResult<I, I::Ty>;

Expand Down Expand Up @@ -503,12 +503,15 @@ pub fn structurally_relate_tys<I: Interner, R: TypeRelation<I>>(
if a_args.skip_binder().is_empty() {
Ok(a)
} else {
let a_args = a_args.no_bound_vars().unwrap();
let b_args = b_args.no_bound_vars().unwrap();
relation.relate_ty_args(a, b, a_def_id.into(), a_args, b_args, |args| {
// FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes)
Ty::new_fn_def(cx, a_def_id, ty::Binder::dummy(args))
})
let x = relation.relate_ty_args(
a,
b,
a_def_id.into(),
a_args.skip_binder(),
b_args.skip_binder(),
Comment on lines +510 to +511

@oli-obk oli-obk Jul 28, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to also relate the bound vars first. Check how other places (dyn/fnptr) do this

View changes since the review

|args| Ty::new_fn_def(cx, a_def_id, a_args.rebind(args)),
);
x
}
}

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_type_ir/src/relate/solver_relating.rs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ where
combine_ty_args(self.infcx, self, a_ty, b_ty, variances, a_args, b_args, |_| a_ty)
}
}

fn relate_with_variance<T: Relate<I>>(
&mut self,
variance: ty::Variance,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &Expr<'_>, cast_expr: &Expr<'_>,

if let ty::FnDef(def_id, generics) = cast_from.kind()
&& let Some(method_name) = cx.tcx.opt_item_name(*def_id)
&& let Some((const_name, ty_name)) =
get_const_name_and_ty_name(cx, method_name, *def_id, generics.no_bound_vars().unwrap().as_slice())
&& let Some((const_name, ty_name)) = get_const_name_and_ty_name(cx, method_name, *def_id, generics.no_bound_vars().unwrap().as_slice())
{
let mut applicability = Applicability::MaybeIncorrect;
let from_snippet = snippet_with_applicability(cx, cast_expr.span, "..", &mut applicability);
Expand Down
8 changes: 0 additions & 8 deletions tests/crashes/133613.rs

This file was deleted.

4 changes: 2 additions & 2 deletions tests/incremental/hashes/function_interfaces.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,9 +156,9 @@ pub fn type_parameter<T>() {}
pub fn lifetime_parameter () {}

#[cfg(not(any(bpass1,bpass4)))]
#[rustc_clean(cfg = "bpass2", except = "hir_owner, generics_of,fn_sig")]
#[rustc_clean(cfg = "bpass2", except = "hir_owner, generics_of, fn_sig, type_of")]
#[rustc_clean(cfg = "bpass3")]
#[rustc_clean(cfg = "bpass5", except = "hir_owner, generics_of,fn_sig")]
#[rustc_clean(cfg = "bpass5", except = "hir_owner, generics_of, fn_sig, type_of")]
#[rustc_clean(cfg = "bpass6")]
pub fn lifetime_parameter<'a>() {}

Expand Down
12 changes: 6 additions & 6 deletions tests/incremental/hashes/inherent_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,12 @@ impl Foo {
impl Foo {
#[rustc_clean(
cfg="bpass2",
except="hir_owner,fn_sig,generics_of,typeck_root,associated_item,optimized_mir",
except="hir_owner,fn_sig,type_of,generics_of,typeck_root,associated_item,optimized_mir",
)]
#[rustc_clean(cfg="bpass3")]
#[rustc_clean(
cfg="bpass5",
except="hir_owner,fn_sig,generics_of,typeck_root,associated_item,optimized_mir",
except="hir_owner,fn_sig,type_of,generics_of,typeck_root,associated_item,optimized_mir",
)]
#[rustc_clean(cfg="bpass6")]
pub fn method_selfness(&self) { }
Expand Down Expand Up @@ -421,9 +421,9 @@ impl Foo {
// ----------------------------------------------------------
// -----------------------------------------------------------
// ----------------------------------------------------------
// --------------------------------------------------------------
// ----------------------------------------------------------------------
// -------------------------
// --------------------------------------------------------------------------
// ----------------------------------------------------------------------------------
// -------------------------
pub fn add_lifetime_parameter_to_method (&self) { }
}
Expand All @@ -443,9 +443,9 @@ impl Foo {
// if we lower generics before the body, then the `HirId` for
// things in the body will be affected. So if you start to see
// `typeck_root` appear dirty, that might be the cause. -nmatsakis
#[rustc_clean(cfg="bpass2", except="hir_owner,fn_sig")]
#[rustc_clean(cfg="bpass2", except="hir_owner,fn_sig,type_of")]
#[rustc_clean(cfg="bpass3")]
#[rustc_clean(cfg="bpass5", except="hir_owner,fn_sig,generics_of")]
#[rustc_clean(cfg="bpass5", except="hir_owner,fn_sig,type_of,generics_of")]
#[rustc_clean(cfg="bpass6")]
pub fn add_lifetime_parameter_to_method<'a>(&self) { }
}
Expand Down
8 changes: 4 additions & 4 deletions tests/incremental/hashes/trait_defs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,9 @@ trait TraitChangeModeSelfOwnToRef {
#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")]
#[rustc_clean(cfg="bpass6")]
trait TraitChangeModeSelfOwnToRef {
#[rustc_clean(except="hir_owner,fn_sig,generics_of", cfg="bpass2")]
#[rustc_clean(except="hir_owner,fn_sig,type_of,generics_of", cfg="bpass2")]
#[rustc_clean(cfg="bpass3")]
#[rustc_clean(except="hir_owner,fn_sig,generics_of", cfg="bpass5")]
#[rustc_clean(except="hir_owner,fn_sig,type_of,generics_of", cfg="bpass5")]
#[rustc_clean(cfg="bpass6")]
fn method(&self);
}
Expand Down Expand Up @@ -509,9 +509,9 @@ trait TraitAddLifetimeParameterToMethod {
#[rustc_clean(except="hir_owner,clauses_of", cfg="bpass5")]
#[rustc_clean(cfg="bpass6")]
trait TraitAddLifetimeParameterToMethod {
#[rustc_clean(except="hir_owner,fn_sig,generics_of", cfg="bpass2")]
#[rustc_clean(except="hir_owner,fn_sig,type_of,generics_of", cfg="bpass2")]
#[rustc_clean(cfg="bpass3")]
#[rustc_clean(except="hir_owner,fn_sig,generics_of", cfg="bpass5")]
#[rustc_clean(except="hir_owner,fn_sig,type_of,generics_of", cfg="bpass5")]
#[rustc_clean(cfg="bpass6")]
fn method<'a>();
}
Expand Down
8 changes: 4 additions & 4 deletions tests/incremental/hashes/trait_impls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ pub trait ChangeMethodSelfnessTrait {
#[rustc_clean(cfg="bpass6")]
impl ChangeMethodSelfnessTrait for Foo {
#[rustc_clean(
except="hir_owner,associated_item,generics_of,fn_sig,typeck_root,optimized_mir",
except="hir_owner,associated_item,generics_of,fn_sig,type_of,typeck_root,optimized_mir",
cfg="bpass2",
)]
#[rustc_clean(cfg="bpass3")]
#[rustc_clean(
except="hir_owner,associated_item,generics_of,fn_sig,typeck_root,optimized_mir",
except="hir_owner,associated_item,generics_of,fn_sig,type_of,typeck_root,optimized_mir",
cfg="bpass5",
)]
#[rustc_clean(cfg="bpass6")]
Expand Down Expand Up @@ -186,12 +186,12 @@ pub trait RemoveMethodSelfnessTrait {
#[rustc_clean(cfg="bpass6")]
impl RemoveMethodSelfnessTrait for Foo {
#[rustc_clean(
except="hir_owner,associated_item,generics_of,fn_sig,typeck_root,optimized_mir",
except="hir_owner,associated_item,generics_of,fn_sig,type_of,typeck_root,optimized_mir",
cfg="bpass2",
)]
#[rustc_clean(cfg="bpass3")]
#[rustc_clean(
except="hir_owner,associated_item,generics_of,fn_sig,typeck_root,optimized_mir",
except="hir_owner,associated_item,generics_of,fn_sig,type_of,typeck_root,optimized_mir",
cfg="bpass5",
)]
#[rustc_clean(cfg="bpass6")]
Expand Down
Loading
Loading