Rollup merge of #143544 - workingjubilee:rename-bare-fn, r=fmease

compiler: rename BareFn to FnPtr

At some point "BareFn" was the chosen name for a "bare" function, without the niceties of `~fn`, `&fn`, or a few other ways of writing a function type. However, at some point the syntax for a "bare function" and any other function diverged even more. We started calling them what they are: function pointers, denoted by their own syntax.

However, we never changed the *internal* name for these, as this divergence was very gradual. Personally, I have repeatedly searched for "FnPtr" and gotten confused until I find the name is BareFn, only to forget this until the next time, since I don't routinely interact with the higher-level AST and HIR. But even tools that interact with these internal types only touch on them in a few places, making a migration easy enough. Let's use a more intuitive and obvious name, as this 12+ year old name has little to do with current Rust.
This commit is contained in:
Jacob Pratt 2025-07-07 03:26:09 +02:00 committed by GitHub
commit 7eea141b87
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
40 changed files with 114 additions and 120 deletions

View file

@ -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| {

View file

@ -824,7 +824,7 @@ impl TyCoercionStability {
TyKind::Slice(_)
| TyKind::Array(..)
| TyKind::Ptr(_)
| TyKind::BareFn(_)
| TyKind::FnPtr(_)
| TyKind::Pat(..)
| TyKind::Never
| TyKind::Tup(_)

View file

@ -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());

View file

@ -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| {

View file

@ -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)

View file

@ -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("(")

View file

@ -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 {

View file

@ -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,