Skip to content

Commit e9c965d

Browse files
committed
Auto merge of rust-lang#128812 - nnethercote:shrink-TyKind-FnPtr, r=compiler-errors
Shrink `TyKind::FnPtr`. By splitting the `FnSig` within `TyKind::FnPtr` into `FnSigTys` and `FnHeader`, which can be packed more efficiently. This reduces the size of the hot `TyKind` type from 32 bytes to 24 bytes on 64-bit platforms. This reduces peak memory usage by a few percent on some benchmarks. It also reduces cache misses and page faults similarly, though this doesn't translate to clear cycles or wall-time improvements on CI. r? `@compiler-errors`
2 parents e5b3e68 + bbd1c3a commit e9c965d

File tree

89 files changed

+315
-231
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

89 files changed

+315
-231
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3989,7 +3989,7 @@ impl<'infcx, 'tcx> MirBorrowckCtxt<'_, '_, 'infcx, 'tcx> {
39893989
} else {
39903990
let ty = self.infcx.tcx.type_of(self.mir_def_id()).instantiate_identity();
39913991
match ty.kind() {
3992-
ty::FnDef(_, _) | ty::FnPtr(_) => self.annotate_fn_sig(
3992+
ty::FnDef(_, _) | ty::FnPtr(..) => self.annotate_fn_sig(
39933993
self.mir_def_id(),
39943994
self.infcx.tcx.fn_sig(self.mir_def_id()).instantiate_identity(),
39953995
),

compiler/rustc_borrowck/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1644,7 +1644,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
16441644
| ty::Pat(_, _)
16451645
| ty::Slice(_)
16461646
| ty::FnDef(_, _)
1647-
| ty::FnPtr(_)
1647+
| ty::FnPtr(..)
16481648
| ty::Dynamic(_, _, _)
16491649
| ty::Closure(_, _)
16501650
| ty::CoroutineClosure(_, _)
@@ -1689,7 +1689,7 @@ impl<'mir, 'tcx> MirBorrowckCtxt<'_, 'mir, '_, 'tcx> {
16891689
| ty::RawPtr(_, _)
16901690
| ty::Ref(_, _, _)
16911691
| ty::FnDef(_, _)
1692-
| ty::FnPtr(_)
1692+
| ty::FnPtr(..)
16931693
| ty::Dynamic(_, _, _)
16941694
| ty::CoroutineWitness(..)
16951695
| ty::Never

compiler/rustc_borrowck/src/type_check/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1364,7 +1364,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
13641364
debug!("func_ty.kind: {:?}", func_ty.kind());
13651365

13661366
let sig = match func_ty.kind() {
1367-
ty::FnDef(..) | ty::FnPtr(_) => func_ty.fn_sig(tcx),
1367+
ty::FnDef(..) | ty::FnPtr(..) => func_ty.fn_sig(tcx),
13681368
_ => {
13691369
span_mirbug!(self, term, "call to non-function {:?}", func_ty);
13701370
return;
@@ -2411,7 +2411,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
24112411
let ty_left = left.ty(body, tcx);
24122412
match ty_left.kind() {
24132413
// Types with regions are comparable if they have a common super-type.
2414-
ty::RawPtr(_, _) | ty::FnPtr(_) => {
2414+
ty::RawPtr(_, _) | ty::FnPtr(..) => {
24152415
let ty_right = right.ty(body, tcx);
24162416
let common_ty = self.infcx.next_ty_var(body.source_info(location).span);
24172417
self.sub_types(

compiler/rustc_codegen_cranelift/src/common.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ fn clif_type_from_ty<'tcx>(tcx: TyCtxt<'tcx>, ty: Ty<'tcx>) -> Option<types::Typ
6969
FloatTy::F64 => types::F64,
7070
FloatTy::F128 => unimplemented!("f16_f128"),
7171
},
72-
ty::FnPtr(_) => pointer_ty(tcx),
72+
ty::FnPtr(..) => pointer_ty(tcx),
7373
ty::RawPtr(pointee_ty, _) | ty::Ref(_, pointee_ty, _) => {
7474
if has_ptr_meta(tcx, *pointee_ty) {
7575
return None;

compiler/rustc_codegen_cranelift/src/value_and_place.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -874,7 +874,7 @@ pub(crate) fn assert_assignable<'tcx>(
874874
(ty::Ref(_, a, _), ty::RawPtr(b, _)) | (ty::RawPtr(a, _), ty::Ref(_, b, _)) => {
875875
assert_assignable(fx, *a, *b, limit - 1);
876876
}
877-
(ty::FnPtr(_), ty::FnPtr(_)) => {
877+
(ty::FnPtr(..), ty::FnPtr(..)) => {
878878
let from_sig = fx.tcx.normalize_erasing_late_bound_regions(
879879
ParamEnv::reveal_all(),
880880
from_ty.fn_sig(fx.tcx),

compiler/rustc_codegen_gcc/src/type_of.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,8 @@ impl<'tcx> LayoutGccExt<'tcx> for TyAndLayout<'tcx> {
213213
// NOTE: we cannot remove this match like in the LLVM codegen because the call
214214
// to fn_ptr_backend_type handle the on-stack attribute.
215215
// TODO(antoyo): find a less hackish way to hande the on-stack attribute.
216-
ty::FnPtr(sig) => {
217-
cx.fn_ptr_backend_type(cx.fn_abi_of_fn_ptr(sig, ty::List::empty()))
218-
}
216+
ty::FnPtr(sig_tys, hdr) => cx
217+
.fn_ptr_backend_type(cx.fn_abi_of_fn_ptr(sig_tys.with(hdr), ty::List::empty())),
219218
_ => self.scalar_gcc_type_at(cx, scalar, Size::ZERO),
220219
};
221220
cx.scalar_types.borrow_mut().insert(self.ty, ty);

compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,7 @@ pub fn type_di_node<'ll, 'tcx>(cx: &CodegenCx<'ll, 'tcx>, t: Ty<'tcx>) -> &'ll D
456456
{
457457
build_pointer_or_reference_di_node(cx, t, t.boxed_ty(), unique_type_id)
458458
}
459-
ty::FnDef(..) | ty::FnPtr(_) => build_subroutine_type_di_node(cx, unique_type_id),
459+
ty::FnDef(..) | ty::FnPtr(..) => build_subroutine_type_di_node(cx, unique_type_id),
460460
ty::Closure(..) => build_closure_env_di_node(cx, unique_type_id),
461461
ty::CoroutineClosure(..) => build_closure_env_di_node(cx, unique_type_id),
462462
ty::Coroutine(..) => enums::build_coroutine_di_node(cx, unique_type_id),

compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ fn push_debuginfo_type_name<'tcx>(
331331
output.push(')');
332332
}
333333
}
334-
ty::FnDef(..) | ty::FnPtr(_) => {
334+
ty::FnDef(..) | ty::FnPtr(..) => {
335335
// We've encountered a weird 'recursive type'
336336
// Currently, the only way to generate such a type
337337
// is by using 'impl trait':

compiler/rustc_codegen_ssa/src/mir/block.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -846,7 +846,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
846846
),
847847
None,
848848
),
849-
ty::FnPtr(_) => (None, Some(callee.immediate())),
849+
ty::FnPtr(..) => (None, Some(callee.immediate())),
850850
_ => bug!("{} is not callable", callee.layout.ty),
851851
};
852852

compiler/rustc_const_eval/src/check_consts/check.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ struct LocalReturnTyVisitor<'ck, 'mir, 'tcx> {
171171
impl<'ck, 'mir, 'tcx> TypeVisitor<TyCtxt<'tcx>> for LocalReturnTyVisitor<'ck, 'mir, 'tcx> {
172172
fn visit_ty(&mut self, t: Ty<'tcx>) {
173173
match t.kind() {
174-
ty::FnPtr(_) => {}
174+
ty::FnPtr(..) => {}
175175
ty::Ref(_, _, hir::Mutability::Mut) => {
176176
self.checker.check_op(ops::mut_ref::MutRef(self.kind));
177177
t.super_visit_with(self)
@@ -726,7 +726,7 @@ impl<'tcx> Visitor<'tcx> for Checker<'_, 'tcx> {
726726
let (mut callee, mut fn_args) = match *fn_ty.kind() {
727727
ty::FnDef(def_id, fn_args) => (def_id, fn_args),
728728

729-
ty::FnPtr(_) => {
729+
ty::FnPtr(..) => {
730730
self.check_op(ops::FnCallIndirect);
731731
return;
732732
}

compiler/rustc_const_eval/src/const_eval/valtrees.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ fn const_to_valtree_inner<'tcx>(
132132

133133
// Technically we could allow function pointers (represented as `ty::Instance`), but this is not guaranteed to
134134
// agree with runtime equality tests.
135-
ty::FnPtr(_) => Err(ValTreeCreationError::NonSupportedType(ty)),
135+
ty::FnPtr(..) => Err(ValTreeCreationError::NonSupportedType(ty)),
136136

137137
ty::Ref(_, _, _) => {
138138
let derefd_place = ecx.deref_pointer(place)?;
@@ -353,7 +353,7 @@ pub fn valtree_to_const_value<'tcx>(
353353
| ty::CoroutineClosure(..)
354354
| ty::Coroutine(..)
355355
| ty::CoroutineWitness(..)
356-
| ty::FnPtr(_)
356+
| ty::FnPtr(..)
357357
| ty::Str
358358
| ty::Slice(_)
359359
| ty::Dynamic(..) => bug!("no ValTree should have been created for type {:?}", ty.kind()),

compiler/rustc_const_eval/src/interpret/cast.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
9797
CastKind::PointerCoercion(PointerCoercion::UnsafeFnPointer) => {
9898
let src = self.read_immediate(src)?;
9999
match cast_ty.kind() {
100-
ty::FnPtr(_) => {
100+
ty::FnPtr(..) => {
101101
// No change to value
102102
self.write_immediate(*src, dest)?;
103103
}
@@ -230,7 +230,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
230230
src: &ImmTy<'tcx, M::Provenance>,
231231
cast_to: TyAndLayout<'tcx>,
232232
) -> InterpResult<'tcx, ImmTy<'tcx, M::Provenance>> {
233-
assert_matches!(src.layout.ty.kind(), ty::RawPtr(_, _) | ty::FnPtr(_));
233+
assert_matches!(src.layout.ty.kind(), ty::RawPtr(_, _) | ty::FnPtr(..));
234234
assert!(cast_to.ty.is_integral());
235235

236236
let scalar = src.to_scalar();

compiler/rustc_const_eval/src/interpret/intrinsics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ pub(crate) fn eval_nullary_intrinsic<'tcx>(
8181
| ty::RawPtr(_, _)
8282
| ty::Ref(_, _, _)
8383
| ty::FnDef(_, _)
84-
| ty::FnPtr(_)
84+
| ty::FnPtr(..)
8585
| ty::Dynamic(_, _, _)
8686
| ty::Closure(_, _)
8787
| ty::CoroutineClosure(_, _)

compiler/rustc_const_eval/src/interpret/stack.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
483483
| ty::Bool
484484
| ty::Float(_)
485485
| ty::FnDef(..)
486-
| ty::FnPtr(_)
486+
| ty::FnPtr(..)
487487
| ty::RawPtr(..)
488488
| ty::Char
489489
| ty::Ref(..)

compiler/rustc_const_eval/src/interpret/step.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> {
424424
self.tcx.mk_type_list_from_iter(extra_args.iter().map(|arg| arg.layout().ty));
425425

426426
let (callee, fn_abi, with_caller_location) = match *func.layout.ty.kind() {
427-
ty::FnPtr(_sig) => {
427+
ty::FnPtr(..) => {
428428
let fn_ptr = self.read_pointer(&func)?;
429429
let fn_val = self.get_ptr_fn(fn_ptr)?;
430430
(fn_val, self.fn_abi_of_fn_ptr(fn_sig_binder, extra_args)?, false)

compiler/rustc_const_eval/src/interpret/validity.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,7 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValidityVisitor<'rt, 'tcx, M> {
616616
self.check_safe_pointer(value, PointerKind::Ref(*mutbl))?;
617617
Ok(true)
618618
}
619-
ty::FnPtr(_sig) => {
619+
ty::FnPtr(..) => {
620620
let value = self.read_scalar(value, ExpectedKind::FnPtr)?;
621621

622622
// If we check references recursively, also check that this points to a function.

compiler/rustc_const_eval/src/util/type_name.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ impl<'tcx> Printer<'tcx> for AbsolutePathPrinter<'tcx> {
3535
| ty::Slice(_)
3636
| ty::RawPtr(_, _)
3737
| ty::Ref(_, _, _)
38-
| ty::FnPtr(_)
38+
| ty::FnPtr(..)
3939
| ty::Never
4040
| ty::Tuple(_)
4141
| ty::Dynamic(_, _, _) => self.pretty_print_type(ty),

compiler/rustc_hir_analysis/src/check/intrinsicck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ impl<'a, 'tcx> InlineAsmCtxt<'a, 'tcx> {
6868
ty::Float(FloatTy::F32) => Some(InlineAsmType::F32),
6969
ty::Float(FloatTy::F64) => Some(InlineAsmType::F64),
7070
ty::Float(FloatTy::F128) => Some(InlineAsmType::F128),
71-
ty::FnPtr(_) => Some(asm_ty_isize),
71+
ty::FnPtr(..) => Some(asm_ty_isize),
7272
ty::RawPtr(ty, _) if self.is_thin_ptr_ty(ty) => Some(asm_ty_isize),
7373
ty::Adt(adt, args) if adt.repr().simd() => {
7474
let fields = &adt.non_enum_variant().fields;

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ fn check_param_wf(tcx: TyCtxt<'_>, param: &hir::GenericParam<'_>) -> Result<(),
951951
} else {
952952
let mut diag = match ty.kind() {
953953
ty::Bool | ty::Char | ty::Int(_) | ty::Uint(_) | ty::Error(_) => return Ok(()),
954-
ty::FnPtr(_) => tcx.dcx().struct_span_err(
954+
ty::FnPtr(..) => tcx.dcx().struct_span_err(
955955
hir_ty.span,
956956
"using function pointers as const generic parameters is forbidden",
957957
),

compiler/rustc_hir_analysis/src/coherence/inherent_impls.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ impl<'tcx> InherentCollect<'tcx> {
172172
| ty::RawPtr(_, _)
173173
| ty::Ref(..)
174174
| ty::Never
175-
| ty::FnPtr(_)
175+
| ty::FnPtr(..)
176176
| ty::Tuple(..) => self.check_primitive_impl(id, self_ty),
177177
ty::Alias(ty::Projection | ty::Inherent | ty::Opaque, _) | ty::Param(_) => {
178178
Err(self.tcx.dcx().emit_err(errors::InherentNominal { span: item_span }))

compiler/rustc_hir_analysis/src/variance/constraints.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -317,8 +317,8 @@ impl<'a, 'tcx> ConstraintContext<'a, 'tcx> {
317317
self.add_constraint(current, data.index, variance);
318318
}
319319

320-
ty::FnPtr(sig) => {
321-
self.add_constraints_from_sig(current, sig, variance);
320+
ty::FnPtr(sig_tys, hdr) => {
321+
self.add_constraints_from_sig(current, sig_tys.with(hdr), variance);
322322
}
323323

324324
ty::Error(_) => {

compiler/rustc_hir_typeck/src/callee.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
137137

138138
// If the callee is a bare function or a closure, then we're all set.
139139
match *adjusted_ty.kind() {
140-
ty::FnDef(..) | ty::FnPtr(_) => {
140+
ty::FnDef(..) | ty::FnPtr(..) => {
141141
let adjustments = self.adjust_steps(autoderef);
142142
self.apply_adjustments(callee_expr, adjustments);
143143
return Some(CallStep::Builtin(adjusted_ty));
@@ -467,7 +467,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
467467
(fn_sig, Some(def_id))
468468
}
469469
// FIXME(effects): these arms should error because we can't enforce them
470-
ty::FnPtr(sig) => (sig, None),
470+
ty::FnPtr(sig_tys, hdr) => (sig_tys.with(hdr), None),
471471
_ => {
472472
for arg in arg_exprs {
473473
self.check_expr(arg);

compiler/rustc_hir_typeck/src/closure.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -336,9 +336,9 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
336336
.into_iter()
337337
.map(|obl| (obl.predicate, obl.cause.span)),
338338
),
339-
ty::FnPtr(sig) => match closure_kind {
339+
ty::FnPtr(sig_tys, hdr) => match closure_kind {
340340
hir::ClosureKind::Closure => {
341-
let expected_sig = ExpectedSig { cause_span: None, sig };
341+
let expected_sig = ExpectedSig { cause_span: None, sig: sig_tys.with(hdr) };
342342
(Some(expected_sig), Some(ty::ClosureKind::Fn))
343343
}
344344
hir::ClosureKind::Coroutine(_) | hir::ClosureKind::CoroutineClosure(_) => {

compiler/rustc_hir_typeck/src/coercion.rs

+8-9
Original file line numberDiff line numberDiff line change
@@ -225,10 +225,10 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
225225
// items to drop the unsafe qualifier.
226226
self.coerce_from_fn_item(a, b)
227227
}
228-
ty::FnPtr(a_f) => {
228+
ty::FnPtr(a_sig_tys, a_hdr) => {
229229
// We permit coercion of fn pointers to drop the
230230
// unsafe qualifier.
231-
self.coerce_from_fn_pointer(a, a_f, b)
231+
self.coerce_from_fn_pointer(a, a_sig_tys.with(a_hdr), b)
232232
}
233233
ty::Closure(closure_def_id_a, args_a) => {
234234
// Non-capturing closures are coercible to
@@ -788,9 +788,8 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
788788
self.commit_if_ok(|snapshot| {
789789
let outer_universe = self.infcx.universe();
790790

791-
let result = if let ty::FnPtr(fn_ty_b) = b.kind()
792-
&& let (hir::Safety::Safe, hir::Safety::Unsafe) =
793-
(fn_ty_a.safety(), fn_ty_b.safety())
791+
let result = if let ty::FnPtr(_, hdr_b) = b.kind()
792+
&& let (hir::Safety::Safe, hir::Safety::Unsafe) = (fn_ty_a.safety(), hdr_b.safety)
794793
{
795794
let unsafe_a = self.tcx.safe_to_unsafe_fn_ty(fn_ty_a);
796795
self.unify_and(unsafe_a, b, to_unsafe)
@@ -842,7 +841,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
842841
debug!("coerce_from_fn_item(a={:?}, b={:?})", a, b);
843842

844843
match b.kind() {
845-
ty::FnPtr(b_sig) => {
844+
ty::FnPtr(_, b_hdr) => {
846845
let a_sig = a.fn_sig(self.tcx);
847846
if let ty::FnDef(def_id, _) = *a.kind() {
848847
// Intrinsics are not coercible to function pointers
@@ -852,7 +851,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
852851

853852
// Safe `#[target_feature]` functions are not assignable to safe fn pointers (RFC 2396).
854853

855-
if b_sig.safety() == hir::Safety::Safe
854+
if b_hdr.safety == hir::Safety::Safe
856855
&& !self.tcx.codegen_fn_attrs(def_id).target_features.is_empty()
857856
{
858857
return Err(TypeError::TargetFeatureCast(def_id));
@@ -910,7 +909,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
910909
//
911910
// All we care here is if any variable is being captured and not the exact paths,
912911
// so we check `upvars_mentioned` for root variables being captured.
913-
ty::FnPtr(fn_ty)
912+
ty::FnPtr(_, hdr)
914913
if self
915914
.tcx
916915
.upvars_mentioned(closure_def_id_a.expect_local())
@@ -923,7 +922,7 @@ impl<'f, 'tcx> Coerce<'f, 'tcx> {
923922
// or
924923
// `unsafe fn(arg0,arg1,...) -> _`
925924
let closure_sig = args_a.as_closure().sig();
926-
let safety = fn_ty.safety();
925+
let safety = hdr.safety;
927926
let pointer_ty =
928927
Ty::new_fn_ptr(self.tcx, self.tcx.signature_unclosure(closure_sig, safety));
929928
debug!("coerce_closure_to_fn(a={:?}, b={:?}, pty={:?})", a, b, pointer_ty);

compiler/rustc_hir_typeck/src/fn_ctxt/checks.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1530,7 +1530,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
15301530
ty::Int(_) | ty::Uint(_) => Some(ty),
15311531
ty::Char => Some(tcx.types.u8),
15321532
ty::RawPtr(..) => Some(tcx.types.usize),
1533-
ty::FnDef(..) | ty::FnPtr(_) => Some(tcx.types.usize),
1533+
ty::FnDef(..) | ty::FnPtr(..) => Some(tcx.types.usize),
15341534
_ => None,
15351535
});
15361536
opt_ty.unwrap_or_else(|| self.next_int_var())

compiler/rustc_hir_typeck/src/fn_ctxt/suggestions.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
604604
expected: Ty<'tcx>,
605605
found: Ty<'tcx>,
606606
) -> bool {
607-
if let (ty::FnPtr(_), ty::Closure(def_id, _)) = (expected.kind(), found.kind()) {
607+
if let (ty::FnPtr(..), ty::Closure(def_id, _)) = (expected.kind(), found.kind()) {
608608
if let Some(upvars) = self.tcx.upvars_mentioned(*def_id) {
609609
// Report upto four upvars being captured to reduce the amount error messages
610610
// reported back to the user.

compiler/rustc_hir_typeck/src/method/suggest.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
5050
// Not all of these (e.g., unsafe fns) implement `FnOnce`,
5151
// so we look for these beforehand.
5252
// FIXME(async_closures): These don't impl `FnOnce` by default.
53-
ty::Closure(..) | ty::FnDef(..) | ty::FnPtr(_) => true,
53+
ty::Closure(..) | ty::FnDef(..) | ty::FnPtr(..) => true,
5454
// If it's not a simple function, look for things which implement `FnOnce`.
5555
_ => {
5656
let Some(fn_once) = tcx.lang_items().fn_once_trait() else {

compiler/rustc_infer/src/infer/canonical/canonicalizer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,7 @@ impl<'cx, 'tcx> TypeFolder<TyCtxt<'tcx>> for Canonicalizer<'cx, 'tcx> {
438438
| ty::RawPtr(..)
439439
| ty::Ref(..)
440440
| ty::FnDef(..)
441-
| ty::FnPtr(_)
441+
| ty::FnPtr(..)
442442
| ty::Dynamic(..)
443443
| ty::Never
444444
| ty::Tuple(..)

compiler/rustc_lint/src/types.rs

+5-4
Original file line numberDiff line numberDiff line change
@@ -1022,7 +1022,7 @@ fn ty_is_known_nonnull<'tcx>(
10221022
let ty = tcx.try_normalize_erasing_regions(param_env, ty).unwrap_or(ty);
10231023

10241024
match ty.kind() {
1025-
ty::FnPtr(_) => true,
1025+
ty::FnPtr(..) => true,
10261026
ty::Ref(..) => true,
10271027
ty::Adt(def, _) if def.is_box() && matches!(mode, CItemKind::Definition) => true,
10281028
ty::Adt(def, args) if def.repr().transparent() && !def.is_union() => {
@@ -1473,7 +1473,8 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
14731473

14741474
ty::Array(inner_ty, _) => self.check_type_for_ffi(cache, inner_ty),
14751475

1476-
ty::FnPtr(sig) => {
1476+
ty::FnPtr(sig_tys, hdr) => {
1477+
let sig = sig_tys.with(hdr);
14771478
if self.is_internal_abi(sig.abi()) {
14781479
return FfiUnsafe {
14791480
ty,
@@ -1709,8 +1710,8 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> {
17091710
type Result = ControlFlow<Ty<'tcx>>;
17101711

17111712
fn visit_ty(&mut self, ty: Ty<'tcx>) -> Self::Result {
1712-
if let ty::FnPtr(sig) = ty.kind()
1713-
&& !self.visitor.is_internal_abi(sig.abi())
1713+
if let ty::FnPtr(_, hdr) = ty.kind()
1714+
&& !self.visitor.is_internal_abi(hdr.abi)
17141715
{
17151716
self.tys.push(ty);
17161717
}

0 commit comments

Comments
 (0)