From 0a4f87a144616f35da510b82acc288aceebd5b9b Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Sun, 6 Jul 2025 12:59:42 -0700 Subject: [PATCH 1/4] compiler: rename {ast,hir}::BareFn* to FnPtr* MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix some comments and related types and locals where it is obvious, e.g. - bare_fn -> fn_ptr - LifetimeBinderKind::BareFnType -> LifetimeBinderKind::FnPtrType Co-authored-by: León Orell Valerian Liehr --- compiler/rustc_ast/src/ast.rs | 6 ++--- compiler/rustc_ast/src/util/classify.rs | 2 +- compiler/rustc_ast/src/visit.rs | 4 +-- compiler/rustc_ast_lowering/src/lib.rs | 4 +-- compiler/rustc_ast_passes/messages.ftl | 6 ++--- .../rustc_ast_passes/src/ast_validation.rs | 8 +++--- compiler/rustc_ast_passes/src/errors.rs | 4 +-- compiler/rustc_ast_passes/src/feature_gate.rs | 4 +-- compiler/rustc_ast_pretty/src/pprust/state.rs | 2 +- .../src/deriving/generic/mod.rs | 6 ++--- compiler/rustc_hir/src/def.rs | 2 +- compiler/rustc_hir/src/hir.rs | 8 +++--- compiler/rustc_hir/src/intravisit.rs | 2 +- compiler/rustc_hir_analysis/src/collect.rs | 2 +- .../src/collect/generics_of.rs | 2 +- .../src/collect/resolve_bound_vars.rs | 10 +++---- .../errors/wrong_number_of_generic_args.rs | 4 +-- .../src/hir_ty_lowering/cmse.rs | 20 +++++++------- .../src/hir_ty_lowering/mod.rs | 18 ++++++------- compiler/rustc_hir_pretty/src/lib.rs | 2 +- compiler/rustc_hir_typeck/src/callee.rs | 2 +- compiler/rustc_lint/src/nonstandard_style.rs | 2 +- compiler/rustc_lint/src/types.rs | 2 +- compiler/rustc_lint/src/unused.rs | 2 +- .../rustc_parse/src/parser/diagnostics.rs | 2 +- compiler/rustc_parse/src/parser/ty.rs | 12 ++++----- compiler/rustc_passes/src/check_attr.rs | 4 +-- compiler/rustc_passes/src/input_stats.rs | 4 +-- compiler/rustc_passes/src/stability.rs | 2 +- compiler/rustc_resolve/src/late.rs | 26 ++++++++----------- .../rustc_resolve/src/late/diagnostics.rs | 2 +- .../infer/nice_region_error/find_anon_type.rs | 2 +- 32 files changed, 86 insertions(+), 92 deletions(-) diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 491a9bbda79b1..3c576316f6230 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -2422,7 +2422,7 @@ impl Ty { } #[derive(Clone, Encodable, Decodable, Debug)] -pub struct BareFnTy { +pub struct FnPtrTy { pub safety: Safety, pub ext: Extern, pub generic_params: ThinVec, @@ -2455,8 +2455,8 @@ pub enum TyKind { /// /// Desugars into `Pin<&'a T>` or `Pin<&'a mut T>`. PinnedRef(Option, MutTy), - /// A bare function (e.g., `fn(usize) -> bool`). - BareFn(P), + /// A function pointer type (e.g., `fn(usize) -> bool`). + FnPtr(P), /// An unsafe existential lifetime binder (e.g., `unsafe<'a> &'a ()`). UnsafeBinder(P), /// The never type (`!`). diff --git a/compiler/rustc_ast/src/util/classify.rs b/compiler/rustc_ast/src/util/classify.rs index 989ebe14bf8fc..f7daec4b0648c 100644 --- a/compiler/rustc_ast/src/util/classify.rs +++ b/compiler/rustc_ast/src/util/classify.rs @@ -265,7 +265,7 @@ fn type_trailing_braced_mac_call(mut ty: &ast::Ty) -> Option<&ast::MacCall> { ty = &binder.inner_ty; } - ast::TyKind::BareFn(fn_ty) => match &fn_ty.decl.output { + ast::TyKind::FnPtr(fn_ty) => match &fn_ty.decl.output { ast::FnRetTy::Default(_) => break None, ast::FnRetTy::Ty(ret) => ty = ret, }, diff --git a/compiler/rustc_ast/src/visit.rs b/compiler/rustc_ast/src/visit.rs index f8ecff69a7635..37fcc0d2167b2 100644 --- a/compiler/rustc_ast/src/visit.rs +++ b/compiler/rustc_ast/src/visit.rs @@ -1059,8 +1059,8 @@ macro_rules! common_visitor_and_walkers { TyKind::Tup(tuple_element_types) => { walk_list!(vis, visit_ty, tuple_element_types); } - TyKind::BareFn(function_declaration) => { - let BareFnTy { safety, ext: _, generic_params, decl, decl_span } = + TyKind::FnPtr(function_declaration) => { + let FnPtrTy { safety, ext: _, generic_params, decl, decl_span } = &$($mut)? **function_declaration; try_visit!(visit_safety(vis, safety)); try_visit!(visit_generic_params(vis, generic_params)); diff --git a/compiler/rustc_ast_lowering/src/lib.rs b/compiler/rustc_ast_lowering/src/lib.rs index 0706bdb119f01..348fe2ee40aa2 100644 --- a/compiler/rustc_ast_lowering/src/lib.rs +++ b/compiler/rustc_ast_lowering/src/lib.rs @@ -1269,9 +1269,9 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> { let path = self.make_lang_item_qpath(LangItem::Pin, span, Some(args)); hir::TyKind::Path(path) } - TyKind::BareFn(f) => { + TyKind::FnPtr(f) => { let generic_params = self.lower_lifetime_binder(t.id, &f.generic_params); - hir::TyKind::BareFn(self.arena.alloc(hir::BareFnTy { + hir::TyKind::FnPtr(self.arena.alloc(hir::FnPtrTy { generic_params, safety: self.lower_safety(f.safety, hir::Safety::Safe), abi: self.lower_extern(f.ext), diff --git a/compiler/rustc_ast_passes/messages.ftl b/compiler/rustc_ast_passes/messages.ftl index d58c140c696d8..c5780c957c974 100644 --- a/compiler/rustc_ast_passes/messages.ftl +++ b/compiler/rustc_ast_passes/messages.ftl @@ -48,9 +48,6 @@ ast_passes_auto_super_lifetime = auto traits cannot have super traits or lifetim ast_passes_bad_c_variadic = only foreign, `unsafe extern "C"`, or `unsafe extern "C-unwind"` functions may have a C-variadic arg -ast_passes_bare_fn_invalid_safety = function pointers cannot be declared with `safe` safety qualifier - .suggestion = remove safe from this item - ast_passes_body_in_extern = incorrect `{$kind}` inside `extern` block .cannot_have = cannot have a body .invalid = the invalid body @@ -135,6 +132,9 @@ ast_passes_fn_param_forbidden_self = ast_passes_fn_param_too_many = function can not have more than {$max_num_args} arguments +ast_passes_fn_ptr_invalid_safety = function pointers cannot be declared with `safe` safety qualifier + .suggestion = remove safe from this item + ast_passes_fn_without_body = free function without a body .suggestion = provide a definition for the function diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs index 53e2a1c695a8f..38889d28151b3 100644 --- a/compiler/rustc_ast_passes/src/ast_validation.rs +++ b/compiler/rustc_ast_passes/src/ast_validation.rs @@ -499,9 +499,9 @@ impl<'a> AstValidator<'a> { } } - fn check_bare_fn_safety(&self, span: Span, safety: Safety) { + fn check_fn_ptr_safety(&self, span: Span, safety: Safety) { if matches!(safety, Safety::Safe(_)) { - self.dcx().emit_err(errors::InvalidSafetyOnBareFn { span }); + self.dcx().emit_err(errors::InvalidSafetyOnFnPtr { span }); } } @@ -785,8 +785,8 @@ impl<'a> AstValidator<'a> { fn visit_ty_common(&mut self, ty: &'a Ty) { match &ty.kind { - TyKind::BareFn(bfty) => { - self.check_bare_fn_safety(bfty.decl_span, bfty.safety); + TyKind::FnPtr(bfty) => { + self.check_fn_ptr_safety(bfty.decl_span, bfty.safety); self.check_fn_decl(&bfty.decl, SelfSemantic::No); Self::check_decl_no_pat(&bfty.decl, |span, _, _| { self.dcx().emit_err(errors::PatternFnPointer { span }); diff --git a/compiler/rustc_ast_passes/src/errors.rs b/compiler/rustc_ast_passes/src/errors.rs index d387a4a310ea0..3b2730d4ff9de 100644 --- a/compiler/rustc_ast_passes/src/errors.rs +++ b/compiler/rustc_ast_passes/src/errors.rs @@ -225,8 +225,8 @@ pub(crate) struct InvalidSafetyOnItem { } #[derive(Diagnostic)] -#[diag(ast_passes_bare_fn_invalid_safety)] -pub(crate) struct InvalidSafetyOnBareFn { +#[diag(ast_passes_fn_ptr_invalid_safety)] +pub(crate) struct InvalidSafetyOnFnPtr { #[primary_span] pub span: Span, } diff --git a/compiler/rustc_ast_passes/src/feature_gate.rs b/compiler/rustc_ast_passes/src/feature_gate.rs index 5d8ee07178d2b..8114733f40670 100644 --- a/compiler/rustc_ast_passes/src/feature_gate.rs +++ b/compiler/rustc_ast_passes/src/feature_gate.rs @@ -286,9 +286,9 @@ impl<'a> Visitor<'a> for PostExpansionVisitor<'a> { fn visit_ty(&mut self, ty: &'a ast::Ty) { match &ty.kind { - ast::TyKind::BareFn(bare_fn_ty) => { + ast::TyKind::FnPtr(fn_ptr_ty) => { // Function pointers cannot be `const` - self.check_late_bound_lifetime_defs(&bare_fn_ty.generic_params); + self.check_late_bound_lifetime_defs(&fn_ptr_ty.generic_params); } ast::TyKind::Never => { gate!(&self, never_type, ty.span, "the `!` type is experimental"); diff --git a/compiler/rustc_ast_pretty/src/pprust/state.rs b/compiler/rustc_ast_pretty/src/pprust/state.rs index 9802ac90c9a65..aff98c63bcb41 100644 --- a/compiler/rustc_ast_pretty/src/pprust/state.rs +++ b/compiler/rustc_ast_pretty/src/pprust/state.rs @@ -1285,7 +1285,7 @@ impl<'a> State<'a> { self.print_type(typ); self.pclose(); } - ast::TyKind::BareFn(f) => { + ast::TyKind::FnPtr(f) => { self.print_ty_fn(f.ext, f.safety, &f.decl, None, &f.generic_params); } ast::TyKind::UnsafeBinder(f) => { diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs index d201ca196d694..8422503212f91 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs @@ -414,12 +414,12 @@ fn find_type_parameters( impl<'a, 'b> visit::Visitor<'a> for Visitor<'a, 'b> { fn visit_ty(&mut self, ty: &'a ast::Ty) { let stack_len = self.bound_generic_params_stack.len(); - if let ast::TyKind::BareFn(bare_fn) = &ty.kind - && !bare_fn.generic_params.is_empty() + if let ast::TyKind::FnPtr(fn_ptr) = &ty.kind + && !fn_ptr.generic_params.is_empty() { // Given a field `x: for<'a> fn(T::SomeType<'a>)`, we wan't to account for `'a` so // that we generate `where for<'a> T::SomeType<'a>: ::core::clone::Clone`. #122622 - self.bound_generic_params_stack.extend(bare_fn.generic_params.iter().cloned()); + self.bound_generic_params_stack.extend(fn_ptr.generic_params.iter().cloned()); } if let ast::TyKind::Path(_, path) = &ty.kind diff --git a/compiler/rustc_hir/src/def.rs b/compiler/rustc_hir/src/def.rs index 459fe5935e06e..df010f8709829 100644 --- a/compiler/rustc_hir/src/def.rs +++ b/compiler/rustc_hir/src/def.rs @@ -831,7 +831,7 @@ pub enum LifetimeRes { /// Id of the introducing place. That can be: /// - an item's id, for the item's generic parameters; /// - a TraitRef's ref_id, identifying the `for<...>` binder; - /// - a BareFn type's id. + /// - a FnPtr type's id. /// /// This information is used for impl-trait lifetime captures, to know when to or not to /// capture any given lifetime. diff --git a/compiler/rustc_hir/src/hir.rs b/compiler/rustc_hir/src/hir.rs index 559a771931e9c..0f6f81d7964c4 100644 --- a/compiler/rustc_hir/src/hir.rs +++ b/compiler/rustc_hir/src/hir.rs @@ -3526,7 +3526,7 @@ impl PrimTy { } #[derive(Debug, Clone, Copy, HashStable_Generic)] -pub struct BareFnTy<'hir> { +pub struct FnPtrTy<'hir> { pub safety: Safety, pub abi: ExternAbi, pub generic_params: &'hir [GenericParam<'hir>], @@ -3645,8 +3645,8 @@ pub enum TyKind<'hir, Unambig = ()> { Ptr(MutTy<'hir>), /// A reference (i.e., `&'a T` or `&'a mut T`). Ref(&'hir Lifetime, MutTy<'hir>), - /// A bare function (e.g., `fn(usize) -> bool`). - BareFn(&'hir BareFnTy<'hir>), + /// A function pointer (e.g., `fn(usize) -> bool`). + FnPtr(&'hir FnPtrTy<'hir>), /// An unsafe binder type (e.g. `unsafe<'a> Foo<'a>`). UnsafeBinder(&'hir UnsafeBinderTy<'hir>), /// The never type (`!`). @@ -4498,7 +4498,7 @@ pub enum ForeignItemKind<'hir> { /// /// All argument idents are actually always present (i.e. `Some`), but /// `&[Option]` is used because of code paths shared with `TraitFn` - /// and `BareFnTy`. The sharing is due to all of these cases not allowing + /// and `FnPtrTy`. The sharing is due to all of these cases not allowing /// arbitrary patterns for parameters. Fn(FnSig<'hir>, &'hir [Option], &'hir Generics<'hir>), /// A foreign static item (`static ext: u8`). diff --git a/compiler/rustc_hir/src/intravisit.rs b/compiler/rustc_hir/src/intravisit.rs index a0bc318e2ca66..1bb8f7ad8945a 100644 --- a/compiler/rustc_hir/src/intravisit.rs +++ b/compiler/rustc_hir/src/intravisit.rs @@ -1001,7 +1001,7 @@ pub fn walk_ty<'v, V: Visitor<'v>>(visitor: &mut V, typ: &'v Ty<'v, AmbigArg>) - TyKind::Tup(tuple_element_types) => { walk_list!(visitor, visit_ty_unambig, tuple_element_types); } - TyKind::BareFn(ref function_declaration) => { + TyKind::FnPtr(ref function_declaration) => { walk_list!(visitor, visit_generic_param, function_declaration.generic_params); try_visit!(visitor.visit_fn_decl(function_declaration.decl)); } diff --git a/compiler/rustc_hir_analysis/src/collect.rs b/compiler/rustc_hir_analysis/src/collect.rs index 25064c327d051..a185291887dc7 100644 --- a/compiler/rustc_hir_analysis/src/collect.rs +++ b/compiler/rustc_hir_analysis/src/collect.rs @@ -198,7 +198,7 @@ fn placeholder_type_error_diag<'cx, 'tcx>( let mut is_const_or_static = false; if let Some(hir_ty) = hir_ty - && let hir::TyKind::BareFn(_) = hir_ty.kind + && let hir::TyKind::FnPtr(_) = hir_ty.kind { is_fn = true; diff --git a/compiler/rustc_hir_analysis/src/collect/generics_of.rs b/compiler/rustc_hir_analysis/src/collect/generics_of.rs index 573af01a62d49..31e9c3b80fba2 100644 --- a/compiler/rustc_hir_analysis/src/collect/generics_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/generics_of.rs @@ -454,7 +454,7 @@ fn has_late_bound_regions<'tcx>(tcx: TyCtxt<'tcx>, node: Node<'tcx>) -> Option; fn visit_ty(&mut self, ty: &'tcx hir::Ty<'tcx, AmbigArg>) -> ControlFlow { match ty.kind { - hir::TyKind::BareFn(..) => { + hir::TyKind::FnPtr(..) => { self.outer_index.shift_in(1); let res = intravisit::walk_ty(self, ty); self.outer_index.shift_out(1); diff --git a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs index a0d1273eb8586..8d7ac7db67bdc 100644 --- a/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs +++ b/compiler/rustc_hir_analysis/src/collect/resolve_bound_vars.rs @@ -704,7 +704,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> { #[instrument(level = "debug", skip(self))] fn visit_ty(&mut self, ty: &'tcx hir::Ty<'tcx, AmbigArg>) { match ty.kind { - hir::TyKind::BareFn(c) => { + hir::TyKind::FnPtr(c) => { let (mut bound_vars, binders): (FxIndexMap, Vec<_>) = c .generic_params .iter() @@ -728,8 +728,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> { where_bound_origin: None, }; self.with(scope, |this| { - // a bare fn has no bounds, so everything - // contained within is scoped within its binder. + // a FnPtr has no bounds, so everything within is scoped within its binder intravisit::walk_ty(this, ty); }); } @@ -758,8 +757,7 @@ impl<'a, 'tcx> Visitor<'tcx> for BoundVarContext<'a, 'tcx> { where_bound_origin: None, }; self.with(scope, |this| { - // a bare fn has no bounds, so everything - // contained within is scoped within its binder. + // everything within is scoped within its binder intravisit::walk_ty(this, ty); }); } @@ -1419,7 +1417,7 @@ impl<'a, 'tcx> BoundVarContext<'a, 'tcx> { hir::Node::OpaqueTy(_) => "higher-ranked lifetime from outer `impl Trait`", // Other items are fine. hir::Node::Item(_) | hir::Node::TraitItem(_) | hir::Node::ImplItem(_) => return Ok(()), - hir::Node::Ty(hir::Ty { kind: hir::TyKind::BareFn(_), .. }) => { + hir::Node::Ty(hir::Ty { kind: hir::TyKind::FnPtr(_), .. }) => { "higher-ranked lifetime from function pointer" } hir::Node::Ty(hir::Ty { kind: hir::TyKind::TraitObject(..), .. }) => { diff --git a/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs b/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs index ef789743e06f7..3f928fd056e4e 100644 --- a/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs +++ b/compiler/rustc_hir_analysis/src/errors/wrong_number_of_generic_args.rs @@ -393,9 +393,9 @@ impl<'a, 'tcx> WrongNumberOfGenericArgs<'a, 'tcx> { let params = if let Some(generics) = node.generics() { generics.params } else if let hir::Node::Ty(ty) = node - && let hir::TyKind::BareFn(bare_fn) = ty.kind + && let hir::TyKind::FnPtr(fn_ptr) = ty.kind { - bare_fn.generic_params + fn_ptr.generic_params } else { &[] }; diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/cmse.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/cmse.rs index 82e5f65476ff9..5088c63702e60 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/cmse.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/cmse.rs @@ -21,8 +21,8 @@ pub(crate) fn validate_cmse_abi<'tcx>( ExternAbi::CmseNonSecureCall => { let hir_node = tcx.hir_node(hir_id); let hir::Node::Ty(hir::Ty { - span: bare_fn_span, - kind: hir::TyKind::BareFn(bare_fn_ty), + span: fn_ptr_span, + kind: hir::TyKind::FnPtr(fn_ptr_ty), .. }) = hir_node else { @@ -49,18 +49,18 @@ pub(crate) fn validate_cmse_abi<'tcx>( Ok(Err(index)) => { // fn(x: u32, u32, u32, u16, y: u16) -> u32, // ^^^^^^ - let span = if let Some(ident) = bare_fn_ty.param_idents[index] { - ident.span.to(bare_fn_ty.decl.inputs[index].span) + let span = if let Some(ident) = fn_ptr_ty.param_idents[index] { + ident.span.to(fn_ptr_ty.decl.inputs[index].span) } else { - bare_fn_ty.decl.inputs[index].span + fn_ptr_ty.decl.inputs[index].span } - .to(bare_fn_ty.decl.inputs.last().unwrap().span); - let plural = bare_fn_ty.param_idents.len() - index != 1; + .to(fn_ptr_ty.decl.inputs.last().unwrap().span); + let plural = fn_ptr_ty.param_idents.len() - index != 1; dcx.emit_err(errors::CmseInputsStackSpill { span, plural, abi }); } Err(layout_err) => { if should_emit_generic_error(abi, layout_err) { - dcx.emit_err(errors::CmseCallGeneric { span: *bare_fn_span }); + dcx.emit_err(errors::CmseCallGeneric { span: *fn_ptr_span }); } } } @@ -68,12 +68,12 @@ pub(crate) fn validate_cmse_abi<'tcx>( match is_valid_cmse_output(tcx, fn_sig) { Ok(true) => {} Ok(false) => { - let span = bare_fn_ty.decl.output.span(); + let span = fn_ptr_ty.decl.output.span(); dcx.emit_err(errors::CmseOutputStackSpill { span, abi }); } Err(layout_err) => { if should_emit_generic_error(abi, layout_err) { - dcx.emit_err(errors::CmseCallGeneric { span: *bare_fn_span }); + dcx.emit_err(errors::CmseCallGeneric { span: *fn_ptr_span }); } } }; diff --git a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs index 434375060dffe..20d165897e2a3 100644 --- a/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs +++ b/compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs @@ -2402,7 +2402,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { hir::TyKind::Tup(fields) => { Ty::new_tup_from_iter(tcx, fields.iter().map(|t| self.lower_ty(t))) } - hir::TyKind::BareFn(bf) => { + hir::TyKind::FnPtr(bf) => { require_c_abi_if_c_variadic(tcx, bf.decl, bf.abi, hir_ty.span); Ty::new_fn_ptr( @@ -2660,28 +2660,28 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { debug!(?output_ty); let fn_ty = tcx.mk_fn_sig(input_tys, output_ty, decl.c_variadic, safety, abi); - let bare_fn_ty = ty::Binder::bind_with_vars(fn_ty, bound_vars); + let fn_ptr_ty = ty::Binder::bind_with_vars(fn_ty, bound_vars); - if let hir::Node::Ty(hir::Ty { kind: hir::TyKind::BareFn(bare_fn_ty), span, .. }) = + if let hir::Node::Ty(hir::Ty { kind: hir::TyKind::FnPtr(fn_ptr_ty), span, .. }) = tcx.hir_node(hir_id) { - check_abi(tcx, hir_id, *span, bare_fn_ty.abi); + check_abi(tcx, hir_id, *span, fn_ptr_ty.abi); } // reject function types that violate cmse ABI requirements - cmse::validate_cmse_abi(self.tcx(), self.dcx(), hir_id, abi, bare_fn_ty); + cmse::validate_cmse_abi(self.tcx(), self.dcx(), hir_id, abi, fn_ptr_ty); - if !bare_fn_ty.references_error() { + if !fn_ptr_ty.references_error() { // Find any late-bound regions declared in return type that do // not appear in the arguments. These are not well-formed. // // Example: // for<'a> fn() -> &'a str <-- 'a is bad // for<'a> fn(&'a String) -> &'a str <-- 'a is ok - let inputs = bare_fn_ty.inputs(); + let inputs = fn_ptr_ty.inputs(); let late_bound_in_args = tcx.collect_constrained_late_bound_regions(inputs.map_bound(|i| i.to_owned())); - let output = bare_fn_ty.output(); + let output = fn_ptr_ty.output(); let late_bound_in_ret = tcx.collect_referenced_late_bound_regions(output); self.validate_late_bound_regions(late_bound_in_args, late_bound_in_ret, |br_name| { @@ -2695,7 +2695,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ { }); } - bare_fn_ty + fn_ptr_ty } /// Given a fn_hir_id for a impl function, suggest the type that is found on the diff --git a/compiler/rustc_hir_pretty/src/lib.rs b/compiler/rustc_hir_pretty/src/lib.rs index c523a03e012e4..3a525021f6fc9 100644 --- a/compiler/rustc_hir_pretty/src/lib.rs +++ b/compiler/rustc_hir_pretty/src/lib.rs @@ -405,7 +405,7 @@ impl<'a> State<'a> { } self.pclose(); } - hir::TyKind::BareFn(f) => { + hir::TyKind::FnPtr(f) => { self.print_ty_fn(f.abi, f.safety, f.decl, None, f.generic_params, f.param_idents); } hir::TyKind::UnsafeBinder(unsafe_binder) => { diff --git a/compiler/rustc_hir_typeck/src/callee.rs b/compiler/rustc_hir_typeck/src/callee.rs index 8c1399aec147b..7611f8ac3e1a7 100644 --- a/compiler/rustc_hir_typeck/src/callee.rs +++ b/compiler/rustc_hir_typeck/src/callee.rs @@ -203,7 +203,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> { let adjusted_ty = self.structurally_resolve_type(autoderef.span(), autoderef.final_ty(false)); - // If the callee is a bare function or a closure, then we're all set. + // If the callee is a function pointer or a closure, then we're all set. match *adjusted_ty.kind() { ty::FnDef(..) | ty::FnPtr(..) => { let adjustments = self.adjust_steps(autoderef); diff --git a/compiler/rustc_lint/src/nonstandard_style.rs b/compiler/rustc_lint/src/nonstandard_style.rs index 97e627f2eb29c..b653609fb7d6e 100644 --- a/compiler/rustc_lint/src/nonstandard_style.rs +++ b/compiler/rustc_lint/src/nonstandard_style.rs @@ -431,7 +431,7 @@ impl<'tcx> LateLintPass<'tcx> for NonSnakeCase { } fn check_ty(&mut self, cx: &LateContext<'_>, ty: &hir::Ty<'_, hir::AmbigArg>) { - if let hir::TyKind::BareFn(hir::BareFnTy { param_idents, .. }) = &ty.kind { + if let hir::TyKind::FnPtr(hir::FnPtrTy { param_idents, .. }) = &ty.kind { for param_ident in *param_idents { if let Some(param_ident) = param_ident { self.check_snake_case(cx, "variable", param_ident); diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs index ea5485d8e5da7..e41bc8f852e58 100644 --- a/compiler/rustc_lint/src/types.rs +++ b/compiler/rustc_lint/src/types.rs @@ -1577,7 +1577,7 @@ impl<'a, 'tcx> ImproperCTypesVisitor<'a, 'tcx> { impl<'tcx> hir::intravisit::Visitor<'_> for FnPtrFinder<'tcx> { fn visit_ty(&mut self, ty: &'_ hir::Ty<'_, AmbigArg>) { debug!(?ty); - if let hir::TyKind::BareFn(hir::BareFnTy { abi, .. }) = ty.kind + if let hir::TyKind::FnPtr(hir::FnPtrTy { abi, .. }) = ty.kind && !abi.is_rustic_abi() { self.spans.push(ty.span); diff --git a/compiler/rustc_lint/src/unused.rs b/compiler/rustc_lint/src/unused.rs index 0627f70507c45..d3942a1c81632 100644 --- a/compiler/rustc_lint/src/unused.rs +++ b/compiler/rustc_lint/src/unused.rs @@ -1312,7 +1312,7 @@ impl EarlyLintPass for UnusedParens { None => true, } } - ast::TyKind::BareFn(b) => { + ast::TyKind::FnPtr(b) => { !self.with_self_ty_parens || b.generic_params.is_empty() } _ => true, diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 1df0ccbd8af76..e0f810d8c1e3f 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -1677,7 +1677,7 @@ impl<'a> Parser<'a> { let hi = self.prev_token.span.shrink_to_hi(); BadTypePlusSub::AddParen { suggestion: AddParen { lo, hi } } } - TyKind::Ptr(..) | TyKind::BareFn(..) => { + TyKind::Ptr(..) | TyKind::FnPtr(..) => { BadTypePlusSub::ForgotParen { span: ty.span.to(self.prev_token.span) } } _ => BadTypePlusSub::ExpectPath { span: ty.span }, diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index 0c57a8cc5e1a5..a997be3405d69 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -2,7 +2,7 @@ use rustc_ast::ptr::P; use rustc_ast::token::{self, IdentIsRaw, MetaVarKind, Token, TokenKind}; use rustc_ast::util::case::Case; use rustc_ast::{ - self as ast, BareFnTy, BoundAsyncness, BoundConstness, BoundPolarity, DUMMY_NODE_ID, FnRetTy, + self as ast, BoundAsyncness, BoundConstness, BoundPolarity, DUMMY_NODE_ID, FnPtrTy, FnRetTy, GenericBound, GenericBounds, GenericParam, Generics, Lifetime, MacCall, MutTy, Mutability, Pinnedness, PolyTraitRef, PreciseCapturingArg, TraitBoundModifiers, TraitObjectSyntax, Ty, TyKind, UnsafeBinderTy, @@ -283,14 +283,14 @@ impl<'a> Parser<'a> { TyKind::Infer } else if self.check_fn_front_matter(false, Case::Sensitive) { // Function pointer type - self.parse_ty_bare_fn(lo, ThinVec::new(), None, recover_return_sign)? + self.parse_ty_fn_ptr(lo, ThinVec::new(), None, recover_return_sign)? } else if self.check_keyword(exp!(For)) { // Function pointer type or bound list (trait object type) starting with a poly-trait. // `for<'lt> [unsafe] [extern "ABI"] fn (&'lt S) -> T` // `for<'lt> Trait1<'lt> + Trait2 + 'a` let (lifetime_defs, _) = self.parse_late_bound_lifetime_defs()?; if self.check_fn_front_matter(false, Case::Sensitive) { - self.parse_ty_bare_fn( + self.parse_ty_fn_ptr( lo, lifetime_defs, Some(self.prev_token.span.shrink_to_lo()), @@ -665,7 +665,7 @@ impl<'a> Parser<'a> { Ok(TyKind::Typeof(expr)) } - /// Parses a function pointer type (`TyKind::BareFn`). + /// Parses a function pointer type (`TyKind::FnPtr`). /// ```ignore (illustrative) /// [unsafe] [extern "ABI"] fn (S) -> T /// // ^~~~~^ ^~~~^ ^~^ ^ @@ -674,7 +674,7 @@ impl<'a> Parser<'a> { /// // Function Style ABI Parameter types /// ``` /// We actually parse `FnHeader FnDecl`, but we error on `const` and `async` qualifiers. - fn parse_ty_bare_fn( + fn parse_ty_fn_ptr( &mut self, lo: Span, mut params: ThinVec, @@ -698,7 +698,7 @@ impl<'a> Parser<'a> { let decl = self.parse_fn_decl(|_| false, AllowPlus::No, recover_return_sign)?; let decl_span = span_start.to(self.prev_token.span); - Ok(TyKind::BareFn(P(BareFnTy { ext, safety, generic_params: params, decl, decl_span }))) + Ok(TyKind::FnPtr(P(FnPtrTy { ext, safety, generic_params: params, decl, decl_span }))) } /// Recover from function pointer types with a generic parameter list (e.g. `fn<'a>(&'a str)`). diff --git a/compiler/rustc_passes/src/check_attr.rs b/compiler/rustc_passes/src/check_attr.rs index 18b3ab12e2d36..5de0e005286cb 100644 --- a/compiler/rustc_passes/src/check_attr.rs +++ b/compiler/rustc_passes/src/check_attr.rs @@ -2978,8 +2978,8 @@ fn check_duplicates( fn doc_fake_variadic_is_allowed_self_ty(self_ty: &hir::Ty<'_>) -> bool { matches!(&self_ty.kind, hir::TyKind::Tup([_])) - || if let hir::TyKind::BareFn(bare_fn_ty) = &self_ty.kind { - bare_fn_ty.decl.inputs.len() == 1 + || if let hir::TyKind::FnPtr(fn_ptr_ty) = &self_ty.kind { + fn_ptr_ty.decl.inputs.len() == 1 } else { false } diff --git a/compiler/rustc_passes/src/input_stats.rs b/compiler/rustc_passes/src/input_stats.rs index 40bc18939d636..e38c7b2cbf15c 100644 --- a/compiler/rustc_passes/src/input_stats.rs +++ b/compiler/rustc_passes/src/input_stats.rs @@ -400,7 +400,7 @@ impl<'v> hir_visit::Visitor<'v> for StatCollector<'v> { Array, Ptr, Ref, - BareFn, + FnPtr, UnsafeBinder, Never, Tup, @@ -674,7 +674,7 @@ impl<'v> ast_visit::Visitor<'v> for StatCollector<'v> { Ptr, Ref, PinnedRef, - BareFn, + FnPtr, UnsafeBinder, Never, Tup, diff --git a/compiler/rustc_passes/src/stability.rs b/compiler/rustc_passes/src/stability.rs index 56d9f5bf78577..a30655d32a7e5 100644 --- a/compiler/rustc_passes/src/stability.rs +++ b/compiler/rustc_passes/src/stability.rs @@ -1070,7 +1070,7 @@ impl<'tcx> Visitor<'tcx> for CheckTraitImplStable<'tcx> { if let TyKind::Never = t.kind { self.fully_stable = false; } - if let TyKind::BareFn(function) = t.kind { + if let TyKind::FnPtr(function) = t.kind { if extern_abi_stability(function.abi).is_err() { self.fully_stable = false; } diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 08c4a485f2681..08629090bb109 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -370,7 +370,7 @@ enum LifetimeRibKind { #[derive(Copy, Clone, Debug)] enum LifetimeBinderKind { - BareFnType, + FnPtrType, PolyTrait, WhereBound, Item, @@ -384,7 +384,7 @@ impl LifetimeBinderKind { fn descr(self) -> &'static str { use LifetimeBinderKind::*; match self { - BareFnType => "type", + FnPtrType => "type", PolyTrait => "bound", WhereBound => "bound", Item | ConstItem => "item", @@ -900,16 +900,16 @@ impl<'ast, 'ra, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'ra, 'tc self.diag_metadata.current_trait_object = Some(&bounds[..]); visit::walk_ty(self, ty) } - TyKind::BareFn(bare_fn) => { - let span = ty.span.shrink_to_lo().to(bare_fn.decl_span.shrink_to_lo()); + TyKind::FnPtr(fn_ptr) => { + let span = ty.span.shrink_to_lo().to(fn_ptr.decl_span.shrink_to_lo()); self.with_generic_param_rib( - &bare_fn.generic_params, + &fn_ptr.generic_params, RibKind::Normal, ty.id, - LifetimeBinderKind::BareFnType, + LifetimeBinderKind::FnPtrType, span, |this| { - this.visit_generic_params(&bare_fn.generic_params, false); + this.visit_generic_params(&fn_ptr.generic_params, false); this.with_lifetime_rib( LifetimeRibKind::AnonymousCreateParameter { binder: ty.id, @@ -921,12 +921,8 @@ impl<'ast, 'ra, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'ra, 'tc false, // We don't need to deal with patterns in parameters, because // they are not possible for foreign or bodiless functions. - bare_fn - .decl - .inputs - .iter() - .map(|Param { ty, .. }| (None, &**ty)), - &bare_fn.decl.output, + fn_ptr.decl.inputs.iter().map(|Param { ty, .. }| (None, &**ty)), + &fn_ptr.decl.output, ) }, ); @@ -939,7 +935,7 @@ impl<'ast, 'ra, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'ra, 'tc &unsafe_binder.generic_params, RibKind::Normal, ty.id, - LifetimeBinderKind::BareFnType, + LifetimeBinderKind::FnPtrType, span, |this| { this.visit_generic_params(&unsafe_binder.generic_params, false); @@ -2976,7 +2972,7 @@ impl<'a, 'ast, 'ra, 'tcx> LateResolutionVisitor<'a, 'ast, 'ra, 'tcx> { } } - if let LifetimeBinderKind::BareFnType + if let LifetimeBinderKind::FnPtrType | LifetimeBinderKind::WhereBound | LifetimeBinderKind::Function | LifetimeBinderKind::ImplBlock = generics_kind diff --git a/compiler/rustc_resolve/src/late/diagnostics.rs b/compiler/rustc_resolve/src/late/diagnostics.rs index a4022691995e7..fa04c8bc604b6 100644 --- a/compiler/rustc_resolve/src/late/diagnostics.rs +++ b/compiler/rustc_resolve/src/late/diagnostics.rs @@ -3177,7 +3177,7 @@ impl<'ast, 'ra, 'tcx> LateResolutionVisitor<'_, 'ast, 'ra, 'tcx> { let higher_ranked = matches!( kind, - LifetimeBinderKind::BareFnType + LifetimeBinderKind::FnPtrType | LifetimeBinderKind::PolyTrait | LifetimeBinderKind::WhereBound ); diff --git a/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/find_anon_type.rs b/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/find_anon_type.rs index 139b299713688..8fe4ffebd8655 100644 --- a/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/find_anon_type.rs +++ b/compiler/rustc_trait_selection/src/error_reporting/infer/nice_region_error/find_anon_type.rs @@ -75,7 +75,7 @@ impl<'tcx> Visitor<'tcx> for FindNestedTypeVisitor<'tcx> { fn visit_ty(&mut self, arg: &'tcx hir::Ty<'tcx, AmbigArg>) -> Self::Result { match arg.kind { - hir::TyKind::BareFn(_) => { + hir::TyKind::FnPtr(_) => { self.current_index.shift_in(1); let _ = intravisit::walk_ty(self, arg); self.current_index.shift_out(1); From 5c8ac15dbdebb49f31307a58c0682f91c2db662f Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Sun, 6 Jul 2025 13:30:17 -0700 Subject: [PATCH 2/4] rustdoc: migrate BareFn -> FnPtr --- src/librustdoc/clean/mod.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/librustdoc/clean/mod.rs b/src/librustdoc/clean/mod.rs index 5cd5c434521c0..c2f3da18cd302 100644 --- a/src/librustdoc/clean/mod.rs +++ b/src/librustdoc/clean/mod.rs @@ -1834,7 +1834,7 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T }; DynTrait(bounds, lifetime) } - TyKind::BareFn(barefn) => BareFunction(Box::new(clean_bare_fn_ty(barefn, cx))), + TyKind::FnPtr(barefn) => BareFunction(Box::new(clean_bare_fn_ty(barefn, cx))), TyKind::UnsafeBinder(unsafe_binder_ty) => { UnsafeBinder(Box::new(clean_unsafe_binder_ty(unsafe_binder_ty, cx))) } @@ -2558,7 +2558,7 @@ fn clean_path_segment<'tcx>( } fn clean_bare_fn_ty<'tcx>( - bare_fn: &hir::BareFnTy<'tcx>, + bare_fn: &hir::FnPtrTy<'tcx>, cx: &mut DocContext<'tcx>, ) -> BareFunctionDecl { let (generic_params, decl) = enter_impl_trait(cx, |cx| { From e47f5657e132c7647ee207f71365eaa734551dd2 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Sun, 6 Jul 2025 13:30:42 -0700 Subject: [PATCH 3/4] clippy: migrate BareFn -> FnPtr --- src/tools/clippy/clippy_lints/src/dereference.rs | 2 +- src/tools/clippy/clippy_lints/src/lifetimes.rs | 4 ++-- .../clippy_lints/src/types/type_complexity.rs | 2 +- src/tools/clippy/clippy_utils/src/ast_utils/mod.rs | 2 +- .../clippy/clippy_utils/src/check_proc_macro.rs | 10 +++++----- src/tools/clippy/clippy_utils/src/hir_utils.rs | 14 +++++++------- 6 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/tools/clippy/clippy_lints/src/dereference.rs b/src/tools/clippy/clippy_lints/src/dereference.rs index 7463d7b5c3bda..5099df3fa0239 100644 --- a/src/tools/clippy/clippy_lints/src/dereference.rs +++ b/src/tools/clippy/clippy_lints/src/dereference.rs @@ -824,7 +824,7 @@ impl TyCoercionStability { TyKind::Slice(_) | TyKind::Array(..) | TyKind::Ptr(_) - | TyKind::BareFn(_) + | TyKind::FnPtr(_) | TyKind::Pat(..) | TyKind::Never | TyKind::Tup(_) diff --git a/src/tools/clippy/clippy_lints/src/lifetimes.rs b/src/tools/clippy/clippy_lints/src/lifetimes.rs index 8fe0c9d60f961..caf17c10484ff 100644 --- a/src/tools/clippy/clippy_lints/src/lifetimes.rs +++ b/src/tools/clippy/clippy_lints/src/lifetimes.rs @@ -13,7 +13,7 @@ use rustc_hir::intravisit::{ walk_poly_trait_ref, walk_trait_ref, walk_ty, walk_unambig_ty, walk_where_predicate, }; use rustc_hir::{ - AmbigArg, BareFnTy, BodyId, FnDecl, FnSig, GenericArg, GenericArgs, GenericBound, GenericParam, GenericParamKind, + AmbigArg, BodyId, FnDecl, FnPtrTy, FnSig, GenericArg, GenericArgs, GenericBound, GenericParam, GenericParamKind, Generics, HirId, Impl, ImplItem, ImplItemKind, Item, ItemKind, Lifetime, LifetimeKind, LifetimeParamKind, Node, PolyTraitRef, PredicateOrigin, TraitFn, TraitItem, TraitItemKind, Ty, TyKind, WhereBoundPredicate, WherePredicate, WherePredicateKind, lang_items, @@ -480,7 +480,7 @@ impl<'tcx> Visitor<'tcx> for RefVisitor<'_, 'tcx> { fn visit_ty(&mut self, ty: &'tcx Ty<'_, AmbigArg>) { match ty.kind { - TyKind::BareFn(&BareFnTy { decl, .. }) => { + TyKind::FnPtr(&FnPtrTy { decl, .. }) => { let mut sub_visitor = RefVisitor::new(self.cx); sub_visitor.visit_fn_decl(decl); self.nested_elision_site_lts.append(&mut sub_visitor.all_lts()); diff --git a/src/tools/clippy/clippy_lints/src/types/type_complexity.rs b/src/tools/clippy/clippy_lints/src/types/type_complexity.rs index 0704653385f18..52c6fda80973c 100644 --- a/src/tools/clippy/clippy_lints/src/types/type_complexity.rs +++ b/src/tools/clippy/clippy_lints/src/types/type_complexity.rs @@ -50,7 +50,7 @@ impl<'tcx> Visitor<'tcx> for TypeComplexityVisitor { TyKind::Path(..) | TyKind::Slice(..) | TyKind::Tup(..) | TyKind::Array(..) => (10 * self.nest, 1), // function types bring a lot of overhead - TyKind::BareFn(bare) if bare.abi == ExternAbi::Rust => (50 * self.nest, 1), + TyKind::FnPtr(fn_ptr) if fn_ptr.abi == ExternAbi::Rust => (50 * self.nest, 1), TyKind::TraitObject(param_bounds, _) => { let has_lifetime_parameters = param_bounds.iter().any(|bound| { diff --git a/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs b/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs index e6396987cc6d9..42254ec8e92d1 100644 --- a/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs +++ b/src/tools/clippy/clippy_utils/src/ast_utils/mod.rs @@ -838,7 +838,7 @@ pub fn eq_ty(l: &Ty, r: &Ty) -> bool { (PinnedRef(ll, l), PinnedRef(rl, r)) => { both(ll.as_ref(), rl.as_ref(), |l, r| eq_id(l.ident, r.ident)) && l.mutbl == r.mutbl && eq_ty(&l.ty, &r.ty) }, - (BareFn(l), BareFn(r)) => { + (FnPtr(l), FnPtr(r)) => { l.safety == r.safety && eq_ext(&l.ext, &r.ext) && over(&l.generic_params, &r.generic_params, eq_generic_param) diff --git a/src/tools/clippy/clippy_utils/src/check_proc_macro.rs b/src/tools/clippy/clippy_utils/src/check_proc_macro.rs index 407e92d88fb0a..ce61fffe0def0 100644 --- a/src/tools/clippy/clippy_utils/src/check_proc_macro.rs +++ b/src/tools/clippy/clippy_utils/src/check_proc_macro.rs @@ -372,17 +372,17 @@ fn ty_search_pat(ty: &Ty<'_>) -> (Pat, Pat) { TyKind::Slice(..) | TyKind::Array(..) => (Pat::Str("["), Pat::Str("]")), TyKind::Ptr(MutTy { ty, .. }) => (Pat::Str("*"), ty_search_pat(ty).1), TyKind::Ref(_, MutTy { ty, .. }) => (Pat::Str("&"), ty_search_pat(ty).1), - TyKind::BareFn(bare_fn) => ( - if bare_fn.safety.is_unsafe() { + TyKind::FnPtr(fn_ptr) => ( + if fn_ptr.safety.is_unsafe() { Pat::Str("unsafe") - } else if bare_fn.abi != ExternAbi::Rust { + } else if fn_ptr.abi != ExternAbi::Rust { Pat::Str("extern") } else { Pat::MultiStr(&["fn", "extern"]) }, - match bare_fn.decl.output { + match fn_ptr.decl.output { FnRetTy::DefaultReturn(_) => { - if let [.., ty] = bare_fn.decl.inputs { + if let [.., ty] = fn_ptr.decl.inputs { ty_search_pat(ty).1 } else { Pat::Str("(") diff --git a/src/tools/clippy/clippy_utils/src/hir_utils.rs b/src/tools/clippy/clippy_utils/src/hir_utils.rs index c37231d093129..0ca494f16e31d 100644 --- a/src/tools/clippy/clippy_utils/src/hir_utils.rs +++ b/src/tools/clippy/clippy_utils/src/hir_utils.rs @@ -1283,20 +1283,20 @@ impl<'a, 'tcx> SpanlessHash<'a, 'tcx> { self.hash_ty(mut_ty.ty); mut_ty.mutbl.hash(&mut self.s); }, - TyKind::BareFn(bfn) => { - bfn.safety.hash(&mut self.s); - bfn.abi.hash(&mut self.s); - for arg in bfn.decl.inputs { + TyKind::FnPtr(fn_ptr) => { + fn_ptr.safety.hash(&mut self.s); + fn_ptr.abi.hash(&mut self.s); + for arg in fn_ptr.decl.inputs { self.hash_ty(arg); } - std::mem::discriminant(&bfn.decl.output).hash(&mut self.s); - match bfn.decl.output { + std::mem::discriminant(&fn_ptr.decl.output).hash(&mut self.s); + match fn_ptr.decl.output { FnRetTy::DefaultReturn(_) => {}, FnRetTy::Return(ty) => { self.hash_ty(ty); }, } - bfn.decl.c_variadic.hash(&mut self.s); + fn_ptr.decl.c_variadic.hash(&mut self.s); }, TyKind::Tup(ty_list) => { for ty in *ty_list { From 3c9b98699dae7d99048c07265735b81353cbd8d7 Mon Sep 17 00:00:00 2001 From: Jubilee Young Date: Sun, 6 Jul 2025 14:02:19 -0700 Subject: [PATCH 4/4] rustfmt: migrate BareFn -> FnPtr --- src/tools/rustfmt/src/types.rs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/tools/rustfmt/src/types.rs b/src/tools/rustfmt/src/types.rs index c0df01edd6dee..9ee10d8627030 100644 --- a/src/tools/rustfmt/src/types.rs +++ b/src/tools/rustfmt/src/types.rs @@ -1009,7 +1009,7 @@ impl Rewrite for ast::Ty { }) } } - ast::TyKind::BareFn(ref bare_fn) => rewrite_bare_fn(bare_fn, self.span, context, shape), + ast::TyKind::FnPtr(ref fn_ptr) => rewrite_fn_ptr(fn_ptr, self.span, context, shape), ast::TyKind::Never => Ok(String::from("!")), ast::TyKind::MacCall(ref mac) => { rewrite_macro(mac, context, shape, MacroPosition::Expression) @@ -1105,8 +1105,8 @@ impl Rewrite for ast::TyPat { } } -fn rewrite_bare_fn( - bare_fn: &ast::BareFnTy, +fn rewrite_fn_ptr( + fn_ptr: &ast::FnPtrTy, span: Span, context: &RewriteContext<'_>, shape: Shape, @@ -1115,7 +1115,7 @@ fn rewrite_bare_fn( let mut result = String::with_capacity(128); - if let Some(ref lifetime_str) = rewrite_bound_params(context, shape, &bare_fn.generic_params) { + if let Some(ref lifetime_str) = rewrite_bound_params(context, shape, &fn_ptr.generic_params) { result.push_str("for<"); // 6 = "for<> ".len(), 4 = "for<". // This doesn't work out so nicely for multiline situation with lots of @@ -1124,10 +1124,10 @@ fn rewrite_bare_fn( result.push_str("> "); } - result.push_str(crate::utils::format_safety(bare_fn.safety)); + result.push_str(crate::utils::format_safety(fn_ptr.safety)); result.push_str(&format_extern( - bare_fn.ext, + fn_ptr.ext, context.config.force_explicit_abi(), )); @@ -1145,9 +1145,9 @@ fn rewrite_bare_fn( }; let rewrite = format_function_type( - bare_fn.decl.inputs.iter(), - &bare_fn.decl.output, - bare_fn.decl.c_variadic(), + fn_ptr.decl.inputs.iter(), + &fn_ptr.decl.output, + fn_ptr.decl.c_variadic(), span, context, func_ty_shape,