Skip to content
Merged
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
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,7 +680,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
hir::ExprKind::Call(callee, _)
if let &ty::FnDef(_, args) = typeck.node_type(callee.hir_id).kind() =>
{
args
args.no_bound_vars().unwrap()
}
_ => return None,
};
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_borrowck/src/diagnostics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -985,6 +985,8 @@ impl<'tcx> BorrowedContentSource<'tcx> {
ty::FnDef(def_id, args) => {
let trait_id = tcx.trait_of_assoc(def_id)?;

let args = args.no_bound_vars().unwrap();

if tcx.is_lang_item(trait_id, LangItem::Deref)
|| tcx.is_lang_item(trait_id, LangItem::DerefMut)
{
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/diagnostics/move_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
hir::ExprKind::Call(callee, _) => {
let ty = typeck_result.node_type_opt(callee.hir_id)?;
let ty::FnDef(fn_def_id, args) = *ty.kind() else { return None };
tcx.predicates_of(fn_def_id).instantiate(tcx, args)
tcx.predicates_of(fn_def_id).instantiate(tcx, args.no_bound_vars().unwrap())
}
hir::ExprKind::MethodCall(..) => {
let (_, method) = typeck_result.type_dependent_def(parent.hir_id)?;
Expand Down
10 changes: 8 additions & 2 deletions compiler/rustc_borrowck/src/diagnostics/mutability_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1241,7 +1241,13 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
typeck_results.node_type_opt(expr.hir_id).as_ref().map(|ty| ty.kind())
{
let arg_pos = args.iter().position(|arg| arg.hir_id == closure_id)?;
Some((*def_id, expr.span, arg_pos, arg_pos, generic_args))
Some((
*def_id,
expr.span,
arg_pos,
arg_pos,
generic_args.no_bound_vars().unwrap(),
))
} else {
None
}
Expand Down Expand Up @@ -1914,7 +1920,7 @@ fn suggest_ampmut<'tcx>(
let trait_ref = ty::TraitRef::from_assoc(
tcx,
tcx.require_lang_item(hir::LangItem::IndexMut, rhs_span),
method_args,
method_args.no_bound_vars().unwrap(),
);
// The type only implements `Index` but not `IndexMut`, we must not suggest `&mut`.
if !infcx
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/diagnostics/region_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -960,7 +960,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, 'infcx, 'tcx> {
tcx,
self.infcx.typing_env(self.infcx.param_env),
fn_did,
self.infcx.resolve_vars_if_possible(args),
self.infcx.resolve_vars_if_possible(args.no_bound_vars().unwrap()),
) else {
return;
};
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_borrowck/src/type_check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1828,6 +1828,7 @@ impl<'a, 'tcx> Visitor<'tcx> for TypeChecker<'a, 'tcx> {
}

if let ty::FnDef(def_id, args) = *constant.const_.ty().kind() {
let args = args.no_bound_vars().unwrap();
let instantiated_predicates = tcx.predicates_of(def_id).instantiate(tcx, args);
self.normalize_and_prove_instantiated_predicates(
def_id,
Expand Down
4 changes: 3 additions & 1 deletion compiler/rustc_borrowck/src/universal_regions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -603,7 +603,9 @@ impl<'cx, 'tcx> UniversalRegionsBuilder<'cx, 'tcx> {
ty::CoroutineClosure(def_id, args) => {
DefiningTy::CoroutineClosure(def_id, args)
}
ty::FnDef(def_id, args) => DefiningTy::FnDef(def_id, args),
ty::FnDef(def_id, args) => {
DefiningTy::FnDef(def_id, args.no_bound_vars().unwrap())
}
_ => span_bug!(
tcx.def_span(self.mir_def),
"expected defining type for `{:?}`: `{:?}`",
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/abi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
fx.tcx,
ty::TypingEnv::fully_monomorphized(),
def_id,
fn_args,
fn_args.no_bound_vars().unwrap(),
source_info.span,
);

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,7 @@ fn codegen_stmt<'tcx>(fx: &mut FunctionCx<'_, '_, 'tcx>, cur_block: Block, stmt:
fx.tcx,
ty::TypingEnv::fully_monomorphized(),
def_id,
args,
args.no_bound_vars().unwrap(),
)
.unwrap(),
);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/src/inline_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ pub(crate) fn codegen_inline_asm_terminator<'tcx>(
fx.tcx,
ty::TypingEnv::fully_monomorphized(),
def_id,
args,
args.no_bound_vars().unwrap(),
)
.unwrap();
let symbol = fx.tcx.symbol_name(instance);
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_llvm/src/intrinsic.rs

@addiesh addiesh Jul 1, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

this change has nothing to do with LLVM and as such should probably not have A-LLVM

View changes since the review

Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
let fn_ty = instance.ty(tcx, self.typing_env());
let fn_sig = match *fn_ty.kind() {
ty::FnDef(def_id, args) => tcx.instantiate_bound_regions_with_erased(
tcx.fn_sig(def_id).instantiate(tcx, args).skip_norm_wip(),
tcx.fn_sig(def_id).instantiate(tcx, args.no_bound_vars().unwrap()).skip_norm_wip(),
),
_ => unreachable!(),
};
Expand Down Expand Up @@ -1762,7 +1762,7 @@ fn codegen_autodiff<'ll, 'tcx>(
let fn_to_diff = args[0].immediate();

let (diff_id, diff_args) = match fn_args.into_type_list(tcx)[1].kind() {
ty::FnDef(def_id, diff_args) => (def_id, diff_args),
ty::FnDef(def_id, diff_args) => (def_id, diff_args.no_bound_vars().unwrap()),
_ => bug!("invalid args"),
};

Expand Down Expand Up @@ -1825,7 +1825,7 @@ fn codegen_offload<'ll, 'tcx>(
let fn_args = instance.args;

let (target_id, target_args) = match fn_args.into_type_list(tcx)[0].kind() {
ty::FnDef(def_id, params) => (def_id, params),
ty::FnDef(def_id, params) => (def_id, params.no_bound_vars().unwrap()),
_ => bug!("invalid offload intrinsic arg"),
};

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ where
cx.tcx(),
ty::TypingEnv::fully_monomorphized(),
def_id,
args,
args.no_bound_vars().unwrap(),
expr.span,
),
_ => span_bug!(*op_sp, "asm sym is not a function"),
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_codegen_ssa/src/mir/block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
bx.tcx(),
bx.typing_env(),
def_id,
generic_args,
generic_args.no_bound_vars().unwrap(),
fn_span,
);

Expand Down Expand Up @@ -1098,7 +1098,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
bx.tcx(),
bx.typing_env(),
def_id,
generic_args,
generic_args.no_bound_vars().unwrap(),
)
.unwrap();

Expand Down Expand Up @@ -1486,7 +1486,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
bx.tcx(),
bx.typing_env(),
def_id,
args,
args.no_bound_vars().unwrap(),
)
.unwrap();
InlineAsmOperandRef::SymFn { instance }
Expand Down
10 changes: 7 additions & 3 deletions compiler/rustc_codegen_ssa/src/mir/naked_asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,13 @@ fn inline_to_global_operand<'a, 'tcx, Cx: LayoutOf<'tcx, LayoutOfResult = TyAndL
);

let instance = match mono_type.kind() {
&ty::FnDef(def_id, args) => {
Instance::expect_resolve(cx.tcx(), cx.typing_env(), def_id, args, value.span)
}
&ty::FnDef(def_id, args) => Instance::expect_resolve(
cx.tcx(),
cx.typing_env(),
def_id,
args.no_bound_vars().unwrap(),
value.span,
),
_ => bug!("asm sym is not a function"),
};

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_ssa/src/mir/rvalue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
bx.tcx(),
bx.typing_env(),
def_id,
args,
args.no_bound_vars().unwrap(),
)
.unwrap();
OperandValue::Immediate(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/check_consts/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -757,7 +757,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
let fn_ty = func.ty(body, tcx);

let (callee, fn_args) = match *fn_ty.kind() {
ty::FnDef(def_id, fn_args) => (def_id, fn_args),
ty::FnDef(def_id, fn_args) => (def_id, fn_args.no_bound_vars().unwrap()),

ty::FnPtr(..) => {
self.check_op(ops::FnCallIndirect);
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/interpret/cast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
*self.tcx,
self.typing_env,
def_id,
args,
args.no_bound_vars().unwrap(),
)
.ok_or_else(|| err_inval!(TooGeneric))?
};
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/interpret/step.rs
Original file line number Diff line number Diff line change
Expand Up @@ -483,7 +483,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
(fn_val, self.fn_abi_of_fn_ptr(fn_sig_binder, extra_args)?, false)
}
ty::FnDef(def_id, args) => {
let instance = self.resolve(def_id, args)?;
let instance = self.resolve(def_id, args.no_bound_vars().unwrap())?;
(
FnVal::Instance(instance),
self.fn_abi_of_instance_no_deduced_attrs(instance, extra_args)?,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_const_eval/src/util/type_name.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ impl<'tcx> Printer<'tcx> for TypeNamePrinter<'tcx> {

// Types with identity (print the module path).
ty::Adt(ty::AdtDef(Interned(&ty::AdtDefData { did: def_id, .. }, _)), args)
| ty::FnDef(def_id, args)
| ty::Alias(
_,
ty::AliasTy {
Expand All @@ -64,6 +63,7 @@ impl<'tcx> Printer<'tcx> for TypeNamePrinter<'tcx> {
| ty::Coroutine(def_id, args) => self.print_def_path(def_id, args),
ty::Foreign(def_id) => self.print_def_path(def_id, &[]),

ty::FnDef(def_id, args) => self.print_def_path(def_id, args.no_bound_vars().unwrap()),
ty::Alias(_, ty::AliasTy { kind: ty::Free { .. }, .. }) => {
bug!("type_name: unexpected free alias")
}
Expand Down
5 changes: 3 additions & 2 deletions compiler/rustc_hir_analysis/src/collect/generics_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -253,8 +253,9 @@ pub(super) fn generics_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Generics {
let generics = tcx.generics_of(def_id);
assert!(!has_self);
parent_has_self = generics.has_self;
own_start = generics.count() as u32;
generics.parent_count + generics.own_params.len()
let count = generics.count();
own_start = count as u32;
count
});

let mut own_params: Vec<_> = Vec::with_capacity(hir_generics.params.len() + has_self as usize);
Expand Down
15 changes: 10 additions & 5 deletions compiler/rustc_hir_analysis/src/collect/type_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
Node::TraitItem(item) => match item.kind {
TraitItemKind::Fn(..) => {
let args = ty::GenericArgs::identity_for_item(tcx, def_id);
Ty::new_fn_def(tcx, def_id.to_def_id(), args)
// 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::Const(ty, rhs) => rhs
.and_then(|rhs| {
Expand All @@ -93,7 +94,8 @@ 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);
Ty::new_fn_def(tcx, def_id.to_def_id(), args)
// 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::Const(ty, rhs) => {
if ty.is_suggestable_infer_ty() {
Expand Down Expand Up @@ -171,7 +173,8 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
},
ItemKind::Fn { .. } => {
let args = ty::GenericArgs::identity_for_item(tcx, def_id);
Ty::new_fn_def(tcx, def_id.to_def_id(), args)
// 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::Enum(..) | ItemKind::Struct(..) | ItemKind::Union(..) => {
let def = tcx.adt_def(def_id);
Expand All @@ -195,7 +198,8 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
Node::ForeignItem(foreign_item) => match foreign_item.kind {
ForeignItemKind::Fn(..) => {
let args = ty::GenericArgs::identity_for_item(tcx, def_id);
Ty::new_fn_def(tcx, def_id.to_def_id(), args)
// 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::Static(ty, _, _) => {
let ty = icx.lower_ty(ty);
Expand All @@ -217,7 +221,8 @@ pub(super) fn type_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::EarlyBinder<'_
}
VariantData::Tuple(_, _, ctor) => {
let args = ty::GenericArgs::identity_for_item(tcx, def_id);
Ty::new_fn_def(tcx, ctor.to_def_id(), args)
// FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes)
Ty::new_fn_def(tcx, ctor.to_def_id(), ty::Binder::dummy(args))
}
},

Expand Down
24 changes: 18 additions & 6 deletions compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1480,7 +1480,11 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
}
TypeRelativePath::Ctor { ctor_def_id, args } => match tcx.def_kind(ctor_def_id) {
DefKind::Ctor(_, CtorKind::Fn) => {
Ok(ty::Const::zero_sized(tcx, Ty::new_fn_def(tcx, ctor_def_id, args)))
// FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes)
Ok(ty::Const::zero_sized(
tcx,
Ty::new_fn_def(tcx, ctor_def_id, ty::Binder::dummy(args)),
))
}
DefKind::Ctor(ctor_of, CtorKind::Const) => {
Ok(self.construct_const_ctor_value(ctor_def_id, ctor_of, args))
Expand Down Expand Up @@ -2578,7 +2582,9 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
.map(|(field_def, arg)| {
self.lower_const_arg(
arg,
tcx.type_of(field_def.did).instantiate(tcx, adt_args).skip_norm_wip(),
tcx.type_of(field_def.did)
.instantiate(tcx, adt_args.no_bound_vars().unwrap())
.skip_norm_wip(),
)
})
.collect::<Vec<_>>();
Expand All @@ -2591,7 +2597,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
};

let valtree = ty::ValTree::from_branches(tcx, opt_discr_const.into_iter().chain(fields));
let adt_ty = Ty::new_adt(tcx, adt_def, adt_args);
let adt_ty = Ty::new_adt(tcx, adt_def, adt_args.no_bound_vars().unwrap());
ty::Const::new_value(tcx, valtree, adt_ty)
}

Expand Down Expand Up @@ -2903,7 +2909,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
&path.segments[generic_segments[0].1],
);

ty::Const::zero_sized(tcx, Ty::new_fn_def(tcx, did, args))
// FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes)
ty::Const::zero_sized(tcx, Ty::new_fn_def(tcx, did, ty::Binder::dummy(args)))
}
Res::Def(DefKind::AssocConst { .. }, did) => {
let trait_segment = if let [modules @ .., trait_, _item] = path.segments {
Expand Down Expand Up @@ -2934,7 +2941,8 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
);

if self.tcx().generics_of(did).own_synthetic_params_count() == 0 {
ty::Const::zero_sized(tcx, Ty::new_fn_def(tcx, did, args))
// FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes)
ty::Const::zero_sized(tcx, Ty::new_fn_def(tcx, did, ty::Binder::dummy(args)))
} else {
let tcx = self.tcx();
let generics = tcx.generics_of(did);
Expand All @@ -2951,7 +2959,11 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
}
});

ty::Const::zero_sized(tcx, Ty::new_fn_def(tcx, did, args))
// FIXME(156581): actually instantiate the binder correctly (turbofishing/fndef changes)
ty::Const::zero_sized(
tcx,
Ty::new_fn_def(tcx, did, ty::Binder::dummy(args.collect::<Box<_>>())),
Comment thread
oli-obk marked this conversation as resolved.
)
}
}

Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_hir_typeck/src/callee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
) -> Ty<'tcx> {
let (fn_sig, def_id, callee_generic_args) = match *callee_ty.kind() {
ty::FnDef(def_id, args) => {
let args = args.no_bound_vars().unwrap();
self.enforce_context_effects(Some(call_expr.hir_id), call_expr.span, def_id, args);
let fn_sig = self.tcx.fn_sig(def_id).instantiate(self.tcx, args).skip_norm_wip();

Expand Down
8 changes: 7 additions & 1 deletion compiler/rustc_lint/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,13 @@ fn get_callee_span_generic_args_and_args<'tcx>(
&& let callee_ty = cx.typeck_results().expr_ty(callee)
&& let ty::FnDef(callee_def_id, generic_args) = callee_ty.kind()
{
return Some((*callee_def_id, callee.span, generic_args, None, args));
return Some((
*callee_def_id,
callee.span,
generic_args.no_bound_vars().unwrap(),
None,
args,
));
}
if let ExprKind::MethodCall(segment, recv, args, _) = expr.kind
&& let Some(method_def_id) = cx.typeck_results().type_dependent_def_id(expr.hir_id)
Expand Down
2 changes: 2 additions & 0 deletions compiler/rustc_middle/src/mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1701,6 +1701,8 @@ pub fn find_self_call<'tcx>(
&& let [Spanned { node: Operand::Move(self_place) | Operand::Copy(self_place), .. }, ..] =
**args
{
let fn_args = fn_args.no_bound_vars().unwrap();

if self_place.as_local() == Some(local) {
return Some((def_id, fn_args));
}
Expand Down
Loading
Loading