From 6d44f2a07066402a5a5af1989fc13f4c81b8552e Mon Sep 17 00:00:00 2001 From: carbotaniuman <41451839+carbotaniuman@users.noreply.github.com> Date: Sat, 8 Aug 2026 15:26:48 -0500 Subject: [PATCH 1/9] Initial implementation of `FnPtr` trait This commit is an initial implementation of the `FnPtr` trait as described in the `fn_static` tracking issue, which consists of moving the internally unstable `core::marker::FnPtr` to `core::ops::FnPtr`, as well as changing the API. Because `NonNull` is used in the new `as_ptr` signature, it was also turned into a proper lang item. --- compiler/rustc_attr_ir/src/lang_items.rs | 7 +- .../src/attributes/rustc_internal.rs | 6 +- .../rustc_const_eval/src/interpret/call.rs | 3 +- compiler/rustc_feature/src/unstable.rs | 2 + .../rustc_hir_analysis/src/check/wfcheck.rs | 24 +++-- compiler/rustc_lint/src/types.rs | 2 +- compiler/rustc_middle/src/mir/visit.rs | 3 +- compiler/rustc_middle/src/mono.rs | 3 +- compiler/rustc_middle/src/ty/instance.rs | 22 +++-- compiler/rustc_middle/src/ty/print/mod.rs | 3 +- compiler/rustc_mir_transform/src/inline.rs | 3 +- .../rustc_mir_transform/src/inline/cycle.rs | 2 +- compiler/rustc_mir_transform/src/shim.rs | 89 +++++++++++++++---- compiler/rustc_monomorphize/src/collector.rs | 3 +- .../rustc_monomorphize/src/partitioning.rs | 6 +- compiler/rustc_span/src/symbol.rs | 7 +- compiler/rustc_ty_utils/src/diagnostics.rs | 7 -- compiler/rustc_ty_utils/src/instance.rs | 26 +++--- library/core/src/marker.rs | 19 ---- library/core/src/ops/function.rs | 39 +++++++- library/core/src/ops/mod.rs | 2 + library/core/src/ptr/mod.rs | 9 +- library/core/src/ptr/non_null.rs | 2 +- library/std/src/lib.rs | 2 +- library/std/src/sys/pal/unix/weak/dlsym.rs | 3 +- .../clippy_lints/src/methods/zst_offset.rs | 3 +- .../src/non_send_fields_in_send_ty.rs | 4 +- .../src/nonnull_unchecked_on_box_ptr.rs | 2 +- .../clippy_lints/src/volatile_composites.rs | 4 +- .../crates/hir-def/src/lang_item.rs | 5 +- .../crates/intern/src/symbol/symbols.rs | 5 +- .../feature-gates/feature-gate-fn_static.rs | 4 + .../feature-gate-fn_static.stderr | 13 +++ tests/ui/fn/fn-ptr-trait-run.rs | 15 ++++ tests/ui/fn/fn-ptr-trait.rs | 4 +- .../hygiene/unpretty-debug-lifetimes.stdout | 4 +- .../dont-pick-fnptr-bound-as-leaf.rs | 4 +- 37 files changed, 256 insertions(+), 105 deletions(-) create mode 100644 tests/ui/feature-gates/feature-gate-fn_static.rs create mode 100644 tests/ui/feature-gates/feature-gate-fn_static.stderr create mode 100644 tests/ui/fn/fn-ptr-trait-run.rs diff --git a/compiler/rustc_attr_ir/src/lang_items.rs b/compiler/rustc_attr_ir/src/lang_items.rs index 34f4fba5b0eea..66b93535e3d6a 100644 --- a/compiler/rustc_attr_ir/src/lang_items.rs +++ b/compiler/rustc_attr_ir/src/lang_items.rs @@ -180,11 +180,15 @@ language_item_table! { Metadata, sym::metadata_type, metadata_type, Target::AssocTy, GenericRequirement::None; DynMetadata, sym::dyn_metadata, dyn_metadata, Target::Struct, GenericRequirement::None; + NonNull, sym::non_null, non_null_trait, Target::Struct, GenericRequirement::Exact(1); + Freeze, sym::freeze, freeze_trait, Target::Trait, GenericRequirement::Exact(0); UnsafeUnpin, sym::unsafe_unpin, unsafe_unpin_trait, Target::Trait, GenericRequirement::Exact(0); FnPtrTrait, sym::fn_ptr_trait, fn_ptr_trait, Target::Trait, GenericRequirement::Exact(0); - FnPtrAddr, sym::fn_ptr_addr, fn_ptr_addr, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None; + FnPtrAsPtr, sym::fn_ptr_as_ptr, fn_ptr_as_ptr, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None; + FnPtrFromPtr, sym::fn_ptr_from_ptr, fn_ptr_from_ptr, Target::Method(MethodKind::Trait { body: false }), GenericRequirement::None; + Code, sym::code, code, Target::ForeignTy, GenericRequirement::None; Drop, sym::drop, drop_trait, Target::Trait, GenericRequirement::None; Destruct, sym::destruct, destruct_trait, Target::Trait, GenericRequirement::None; @@ -243,6 +247,7 @@ language_item_table! { Fn, kw::Fn, fn_trait, Target::Trait, GenericRequirement::Exact(1); FnMut, sym::fn_mut, fn_mut_trait, Target::Trait, GenericRequirement::Exact(1); FnOnce, sym::fn_once, fn_once_trait, Target::Trait, GenericRequirement::Exact(1); + FnStatic, sym::fn_static, fn_static_trait, Target::Trait, GenericRequirement::Exact(1); AsyncFn, sym::async_fn, async_fn_trait, Target::Trait, GenericRequirement::Exact(1); AsyncFnMut, sym::async_fn_mut, async_fn_mut_trait, Target::Trait, GenericRequirement::Exact(1); diff --git a/compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs b/compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs index b101d378bab98..1250f914ad0f8 100644 --- a/compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs +++ b/compiler/rustc_attr_parsing/src/attributes/rustc_internal.rs @@ -607,9 +607,9 @@ impl SingleAttributeParser for LangParser { return None; }; - // Only weak lang items may be applied to foreign items - if [Target::ForeignFn, Target::ForeignStatic, Target::ForeignTy, Target::ForeignMod] - .contains(&cx.target) + // Only weak lang items may be applied to foreign items, + // except for `ForeignTy` which can be a normal lang item. + if [Target::ForeignFn, Target::ForeignStatic, Target::ForeignMod].contains(&cx.target) && !lang_item.is_weak() { cx.emit_err(UnknownExternLangItem { span: cx.attr_span, lang_item: lang_item.name() }); diff --git a/compiler/rustc_const_eval/src/interpret/call.rs b/compiler/rustc_const_eval/src/interpret/call.rs index f9c21f42d4e5e..ea05c0575df69 100644 --- a/compiler/rustc_const_eval/src/interpret/call.rs +++ b/compiler/rustc_const_eval/src/interpret/call.rs @@ -730,7 +730,8 @@ impl<'tcx, M: Machine<'tcx>> InterpCx<'tcx, M> { | ty::InstanceKind::Shim(ty::ShimKind::FnPtr(..)) | ty::InstanceKind::Shim(ty::ShimKind::DropGlue(..)) | ty::InstanceKind::Shim(ty::ShimKind::Clone(..)) - | ty::InstanceKind::Shim(ty::ShimKind::FnPtrAddr(..)) + | ty::InstanceKind::Shim(ty::ShimKind::FnPtrAsPtr(..)) + | ty::InstanceKind::Shim(ty::ShimKind::FnPtrFromPtr(..)) | ty::InstanceKind::Shim(ty::ShimKind::ThreadLocal(..)) | ty::InstanceKind::Shim(ty::ShimKind::AsyncDropGlueCtor(..)) | ty::InstanceKind::Shim(ty::ShimKind::AsyncDropGlue(..)) diff --git a/compiler/rustc_feature/src/unstable.rs b/compiler/rustc_feature/src/unstable.rs index b15ea5da6f0cb..39be65765c618 100644 --- a/compiler/rustc_feature/src/unstable.rs +++ b/compiler/rustc_feature/src/unstable.rs @@ -566,6 +566,8 @@ declare_features! ( (unstable, fn_align, "1.53.0", Some(82232)), /// Support delegating implementation of functions to other already implemented functions. (incomplete, fn_delegation, "1.76.0", Some(118212)), + /// Traits for function pointers and items + (unstable, fn_static, "CURRENT_RUSTC_VERSION", Some(148768)), /// Allows impls for the Freeze trait. (internal, freeze_impls, "1.78.0", Some(121675)), /// Frontmatter `---` blocks for use by external tools. diff --git a/compiler/rustc_hir_analysis/src/check/wfcheck.rs b/compiler/rustc_hir_analysis/src/check/wfcheck.rs index 553ee4b9c5a02..6faf4954a68d1 100644 --- a/compiler/rustc_hir_analysis/src/check/wfcheck.rs +++ b/compiler/rustc_hir_analysis/src/check/wfcheck.rs @@ -1800,14 +1800,22 @@ fn check_method_receiver<'tcx>( { match receiver_validity_err { ReceiverValidityError::DoesNotDeref if arbitrary_self_types_level.is_some() => { - let hint = match receiver_ty - .builtin_deref(false) - .unwrap_or(receiver_ty) - .ty_adt_def() - .and_then(|adt_def| tcx.get_diagnostic_name(adt_def.did())) - { - Some(sym::RcWeak | sym::ArcWeak) => Some(InvalidReceiverTyHint::Weak), - Some(sym::NonNull) => Some(InvalidReceiverTyHint::NonNull), + let adt_def = + receiver_ty.builtin_deref(false).unwrap_or(receiver_ty).ty_adt_def(); + + let hint = match adt_def { + Some(adt) => { + if tcx.is_lang_item(adt.did(), LangItem::NonNull) { + Some(InvalidReceiverTyHint::NonNull) + } else { + match tcx.get_diagnostic_name(adt.did()) { + Some(sym::RcWeak | sym::ArcWeak) => { + Some(InvalidReceiverTyHint::Weak) + } + _ => None, + } + } + } _ => None, }; diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs index 083d2e4ee0499..6553b042c0837 100644 --- a/compiler/rustc_lint/src/types.rs +++ b/compiler/rustc_lint/src/types.rs @@ -317,7 +317,7 @@ fn lint_wide_pointer<'tcx>( let mut modifiers = String::new(); ty = match ty.kind() { ty::RawPtr(ty, _) => *ty, - ty::Adt(def, args) if cx.tcx.is_diagnostic_item(sym::NonNull, def.did()) => { + ty::Adt(def, args) if cx.tcx.is_lang_item(def.did(), LangItem::NonNull) => { modifiers.push_str(".as_ptr()"); args.type_at(0) } diff --git a/compiler/rustc_middle/src/mir/visit.rs b/compiler/rustc_middle/src/mir/visit.rs index 429ab7d928fc5..d2921188cc376 100644 --- a/compiler/rustc_middle/src/mir/visit.rs +++ b/compiler/rustc_middle/src/mir/visit.rs @@ -362,7 +362,8 @@ macro_rules! make_mir_visitor { ty::InstanceKind::Shim(ty::ShimKind::FnPtr(_def_id, ty)) | ty::InstanceKind::Shim(ty::ShimKind::DropGlue(_def_id, Some(ty))) | ty::InstanceKind::Shim(ty::ShimKind::Clone(_def_id, ty)) - | ty::InstanceKind::Shim(ty::ShimKind::FnPtrAddr(_def_id, ty)) + | ty::InstanceKind::Shim(ty::ShimKind::FnPtrAsPtr(_def_id, ty)) + | ty::InstanceKind::Shim(ty::ShimKind::FnPtrFromPtr(_def_id, ty)) | ty::InstanceKind::Shim(ty::ShimKind::AsyncDropGlue(_def_id, ty)) | ty::InstanceKind::Shim(ty::ShimKind::AsyncDropGlueCtor(_def_id, ty)) => { // FIXME(eddyb) use a better `TyContext` here. diff --git a/compiler/rustc_middle/src/mono.rs b/compiler/rustc_middle/src/mono.rs index dc9a94f79aa0f..76828cbee60f1 100644 --- a/compiler/rustc_middle/src/mono.rs +++ b/compiler/rustc_middle/src/mono.rs @@ -548,7 +548,8 @@ impl<'tcx> CodegenUnit<'tcx> { | InstanceKind::Shim(ShimKind::DropGlue(..)) | InstanceKind::Shim(ShimKind::Clone(..)) | InstanceKind::Shim(ShimKind::ThreadLocal(..)) - | InstanceKind::Shim(ShimKind::FnPtrAddr(..)) + | InstanceKind::Shim(ShimKind::FnPtrAsPtr(..)) + | InstanceKind::Shim(ShimKind::FnPtrFromPtr(..)) | InstanceKind::Shim(ShimKind::AsyncDropGlue(..)) | InstanceKind::Shim(ShimKind::FutureDropPoll(..)) | InstanceKind::Shim(ShimKind::AsyncDropGlueCtor(..)) => None, diff --git a/compiler/rustc_middle/src/ty/instance.rs b/compiler/rustc_middle/src/ty/instance.rs index 6a04357827360..aada9020989d3 100644 --- a/compiler/rustc_middle/src/ty/instance.rs +++ b/compiler/rustc_middle/src/ty/instance.rs @@ -177,12 +177,19 @@ pub enum ShimKind<'tcx> { /// The `DefId` is for `Clone::clone`, the `Ty` is the type `T` with the builtin `Clone` impl. Clone(DefId, Ty<'tcx>), - /// Compiler-generated `::addr` implementation. + /// Compiler-generated `::as_ptr` implementation. /// /// Automatically generated for all potentially higher-ranked `fn(I) -> R` types. /// - /// The `DefId` is for `FnPtr::addr`, the `Ty` is the type `T`. - FnPtrAddr(DefId, Ty<'tcx>), + /// The `DefId` is for `FnPtr::as_ptr`, the `Ty` is the type `T`. + FnPtrAsPtr(DefId, Ty<'tcx>), + + /// Compiler-generated `::from_ptr` implementation. + /// + /// Automatically generated for all potentially higher-ranked `fn(I) -> R` types. + /// + /// The `DefId` is for `FnPtr::from_ptr`, the `Ty` is the type `T`. + FnPtrFromPtr(DefId, Ty<'tcx>), /// `core::future::async_drop::async_drop_in_place::<'_, T>`. /// @@ -344,7 +351,8 @@ impl<'tcx> ShimKind<'tcx> { } | ShimKind::DropGlue(def_id, _) | ShimKind::Clone(def_id, _) - | ShimKind::FnPtrAddr(def_id, _) + | ShimKind::FnPtrAsPtr(def_id, _) + | ShimKind::FnPtrFromPtr(def_id, _) | ShimKind::FutureDropPoll(def_id, _, _) | ShimKind::AsyncDropGlue(def_id, _) | ShimKind::AsyncDropGlueCtor(def_id, _) => def_id, @@ -366,7 +374,8 @@ impl<'tcx> ShimKind<'tcx> { | ShimKind::ConstructCoroutineInClosure { .. } | ShimKind::DropGlue(..) | ShimKind::Clone(..) - | ShimKind::FnPtrAddr(..) => None, + | ShimKind::FnPtrAsPtr(..) + | ShimKind::FnPtrFromPtr(..) => None, } } @@ -385,8 +394,9 @@ impl<'tcx> ShimKind<'tcx> { match *self { ShimKind::Clone(..) | ShimKind::ThreadLocal(..) - | ShimKind::FnPtrAddr(..) | ShimKind::FnPtr(..) + | ShimKind::FnPtrAsPtr(..) + | ShimKind::FnPtrFromPtr(..) | ShimKind::DropGlue(_, Some(_)) | ShimKind::FutureDropPoll(..) | ShimKind::AsyncDropGlue(_, _) => false, diff --git a/compiler/rustc_middle/src/ty/print/mod.rs b/compiler/rustc_middle/src/ty/print/mod.rs index ccdac57cc8dcd..451a75e52d2d9 100644 --- a/compiler/rustc_middle/src/ty/print/mod.rs +++ b/compiler/rustc_middle/src/ty/print/mod.rs @@ -397,7 +397,8 @@ impl<'tcx, P: Printer<'tcx> + std::fmt::Write> Print

for ty::ShimKind<'tcx> { ty::ShimKind::DropGlue(_, None) => cx.write_str("shim(None)"), ty::ShimKind::DropGlue(_, Some(ty)) => cx.write_str(&format!("shim(Some({ty}))")), ty::ShimKind::Clone(_, ty) => cx.write_str(&format!("shim({ty})")), - ty::ShimKind::FnPtrAddr(_, ty) => cx.write_str(&format!("shim({ty})")), + ty::ShimKind::FnPtrAsPtr(_, ty) => cx.write_str(&format!("shim({ty})")), + ty::ShimKind::FnPtrFromPtr(_, ty) => cx.write_str(&format!("shim({ty})")), ty::ShimKind::FutureDropPoll(_, proxy_ty, impl_ty) => { cx.write_str(&format!("dropshim({proxy_ty}-{impl_ty})")) } diff --git a/compiler/rustc_mir_transform/src/inline.rs b/compiler/rustc_mir_transform/src/inline.rs index 765fd8984b446..6c7dfe750dac5 100644 --- a/compiler/rustc_mir_transform/src/inline.rs +++ b/compiler/rustc_mir_transform/src/inline.rs @@ -764,7 +764,8 @@ fn check_mir_is_available<'tcx, I: Inliner<'tcx>>( | InstanceKind::Shim(ShimKind::DropGlue(..)) | InstanceKind::Shim(ShimKind::Clone(..)) | InstanceKind::Shim(ShimKind::ThreadLocal(..)) - | InstanceKind::Shim(ShimKind::FnPtrAddr(..)) => return Ok(()), + | InstanceKind::Shim(ShimKind::FnPtrAsPtr(..)) + | InstanceKind::Shim(ShimKind::FnPtrFromPtr(..)) => return Ok(()), } if inliner.tcx().is_constructor(callee_def_id) { diff --git a/compiler/rustc_mir_transform/src/inline/cycle.rs b/compiler/rustc_mir_transform/src/inline/cycle.rs index ce34c6ad07758..5d4c4b236deba 100644 --- a/compiler/rustc_mir_transform/src/inline/cycle.rs +++ b/compiler/rustc_mir_transform/src/inline/cycle.rs @@ -37,7 +37,7 @@ fn should_recurse<'tcx>(tcx: TyCtxt<'tcx>, callee: ty::Instance<'tcx>) -> bool { | InstanceKind::Shim(ShimKind::Clone(..)) => {} // This shim does not call any other functions, thus there can be no recursion. - InstanceKind::Shim(ShimKind::FnPtrAddr(..)) => return false, + InstanceKind::Shim(ShimKind::FnPtrAsPtr(..) | ShimKind::FnPtrFromPtr(..)) => return false, // FIXME: A not fully instantiated drop shim can cause ICEs if one attempts to // have its MIR built. Likely oli-obk just screwed up the `ParamEnv`s, so this diff --git a/compiler/rustc_mir_transform/src/shim.rs b/compiler/rustc_mir_transform/src/shim.rs index 9743d7b552862..05322efc65d97 100644 --- a/compiler/rustc_mir_transform/src/shim.rs +++ b/compiler/rustc_mir_transform/src/shim.rs @@ -128,7 +128,8 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, shim: ty::ShimKind<'tcx>) -> Body<'tcx> { } ty::ShimKind::ThreadLocal(..) => build_thread_local_shim(tcx, shim), ty::ShimKind::Clone(def_id, ty) => build_clone_shim(tcx, def_id, ty), - ty::ShimKind::FnPtrAddr(def_id, ty) => build_fn_ptr_addr_shim(tcx, def_id, ty), + ty::ShimKind::FnPtrAsPtr(def_id, ty) => build_fn_ptr_as_ptr_shim(tcx, def_id, ty), + ty::ShimKind::FnPtrFromPtr(def_id, ty) => build_fn_ptr_from_ptr_shim(tcx, def_id, ty), ty::ShimKind::FutureDropPoll(def_id, proxy_ty, impl_ty) => { let mut body = async_destructor_ctor::build_future_drop_poll_shim(tcx, def_id, proxy_ty, impl_ty); @@ -1080,40 +1081,98 @@ pub(super) fn build_adt_ctor(tcx: TyCtxt<'_>, ctor_id: DefId) -> Body<'_> { /// ```ignore (pseudo-impl) /// impl FnPtr for fn(u32) { -/// fn addr(self) -> usize { -/// self as usize +/// fn addr(self) -> NonNull { +/// unsafe { transmute(self as *const Code)} /// } /// } /// ``` -fn build_fn_ptr_addr_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, self_ty: Ty<'tcx>) -> Body<'tcx> { +fn build_fn_ptr_as_ptr_shim<'tcx>( + tcx: TyCtxt<'tcx>, + def_id: DefId, + self_ty: Ty<'tcx>, +) -> Body<'tcx> { assert_matches!(self_ty.kind(), ty::FnPtr(..), "expected fn ptr, found {self_ty}"); + let span = tcx.def_span(def_id); + let nonnull_did = tcx.require_lang_item(LangItem::NonNull, span); + let code_did = tcx.require_lang_item(LangItem::Code, span); + let nonnull_ty = tcx + .type_of(nonnull_did) + .instantiate( + tcx, + &[ty::GenericArg::from(tcx.type_of(code_did).instantiate_identity().skip_norm_wip())], + ) + .skip_norm_wip(); + let Some(sig) = tcx.fn_sig(def_id).instantiate(tcx, &[self_ty.into()]).skip_norm_wip().no_bound_vars() else { - span_bug!(span, "FnPtr::addr with bound vars for `{self_ty}`"); + span_bug!(span, "FnPtr::as_ptr with bound vars for `{self_ty}`"); }; - let locals = local_decls_for_sig(&sig, span); + let mut locals = local_decls_for_sig(&sig, span); let source_info = SourceInfo::outermost(span); + + let mut statements = vec![]; // FIXME: use `expose_provenance` once we figure out whether function pointers have meaningful // provenance. - let rvalue = Rvalue::Cast( - CastKind::FnPtrToPtr, - Operand::Move(Place::from(Local::arg(0))), - Ty::new_imm_ptr(tcx, tcx.types.unit), - ); - let stmt = Statement::new( + let raw_unit_ptr = Ty::new_imm_ptr(tcx, tcx.types.unit); + let cast_to_raw_rvalue = + Rvalue::Cast(CastKind::FnPtrToPtr, Operand::Move(Place::from(Local::arg(0))), raw_unit_ptr); + let raw_ptr = locals.push(LocalDecl::with_source_info(raw_unit_ptr, source_info)).into(); + statements.push(Statement::new( source_info, - StatementKind::Assign(Box::new((Place::return_place(), rvalue))), + StatementKind::Assign(Box::new((raw_ptr, cast_to_raw_rvalue))), + )); + + let transmute_to_nonnull = + Rvalue::Cast(CastKind::Transmute, Operand::Move(Place::from(raw_ptr)), nonnull_ty); + statements.push(Statement::new( + source_info, + StatementKind::Assign(Box::new((Place::return_place(), transmute_to_nonnull))), + )); + + let start_block = BasicBlockData::new_stmts( + statements, + Some(Terminator { source_info, kind: TerminatorKind::Return, attributes: ThinVec::new() }), + false, ); - let statements = vec![stmt]; + let source = MirSource::from_shim(ty::ShimKind::FnPtrAsPtr(def_id, self_ty)); + new_body(source, IndexVec::from_elem_n(start_block, 1), locals, sig.inputs().len(), span) +} + +fn build_fn_ptr_from_ptr_shim<'tcx>( + tcx: TyCtxt<'tcx>, + def_id: DefId, + self_ty: Ty<'tcx>, +) -> Body<'tcx> { + assert_matches!(self_ty.kind(), ty::FnPtr(..), "expected fn ptr, found {self_ty}"); + + let span = tcx.def_span(def_id); + + let Some(sig) = + tcx.fn_sig(def_id).instantiate(tcx, &[self_ty.into()]).skip_norm_wip().no_bound_vars() + else { + span_bug!(span, "FnPtr::as_ptr with bound vars for `{self_ty}`"); + }; + let locals = local_decls_for_sig(&sig, span); + + let source_info = SourceInfo::outermost(span); + + let mut statements = vec![]; + let transmute_to_self = + Rvalue::Cast(CastKind::Transmute, Operand::Move(Place::from(Local::arg(0))), self_ty); + statements.push(Statement::new( + source_info, + StatementKind::Assign(Box::new((Place::return_place(), transmute_to_self))), + )); + let start_block = BasicBlockData::new_stmts( statements, Some(Terminator { source_info, kind: TerminatorKind::Return, attributes: ThinVec::new() }), false, ); - let source = MirSource::from_shim(ty::ShimKind::FnPtrAddr(def_id, self_ty)); + let source = MirSource::from_shim(ty::ShimKind::FnPtrFromPtr(def_id, self_ty)); new_body(source, IndexVec::from_elem_n(start_block, 1), locals, sig.inputs().len(), span) } diff --git a/compiler/rustc_monomorphize/src/collector.rs b/compiler/rustc_monomorphize/src/collector.rs index fae1ee7256683..6c4426979b31c 100644 --- a/compiler/rustc_monomorphize/src/collector.rs +++ b/compiler/rustc_monomorphize/src/collector.rs @@ -1057,7 +1057,8 @@ fn visit_instance_use<'tcx>( | ty::InstanceKind::Shim(ty::ShimKind::ConstructCoroutineInClosure { .. }) | ty::InstanceKind::Shim(ty::ShimKind::FnPtr(..)) | ty::InstanceKind::Shim(ty::ShimKind::Clone(..)) - | ty::InstanceKind::Shim(ty::ShimKind::FnPtrAddr(..)) => { + | ty::InstanceKind::Shim(ty::ShimKind::FnPtrAsPtr(..)) + | ty::InstanceKind::Shim(ty::ShimKind::FnPtrFromPtr(..)) => { output.push(create_fn_mono_item(tcx, instance, source)); } } diff --git a/compiler/rustc_monomorphize/src/partitioning.rs b/compiler/rustc_monomorphize/src/partitioning.rs index 5cfae525d7e5e..5761f5cc8fc0a 100644 --- a/compiler/rustc_monomorphize/src/partitioning.rs +++ b/compiler/rustc_monomorphize/src/partitioning.rs @@ -655,7 +655,8 @@ fn characteristic_def_id_of_mono_item<'tcx>( | ty::InstanceKind::Shim(ty::ShimKind::DropGlue(..)) | ty::InstanceKind::Shim(ty::ShimKind::Clone(..)) | ty::InstanceKind::Shim(ty::ShimKind::ThreadLocal(..)) - | ty::InstanceKind::Shim(ty::ShimKind::FnPtrAddr(..)) + | ty::InstanceKind::Shim(ty::ShimKind::FnPtrAsPtr(..)) + | ty::InstanceKind::Shim(ty::ShimKind::FnPtrFromPtr(..)) | ty::InstanceKind::Shim(ty::ShimKind::FutureDropPoll(..)) | ty::InstanceKind::Shim(ty::ShimKind::AsyncDropGlue(..)) | ty::InstanceKind::Shim(ty::ShimKind::AsyncDropGlueCtor(..)) => return None, @@ -841,7 +842,8 @@ fn mono_item_visibility<'tcx>( | InstanceKind::Shim(ShimKind::ConstructCoroutineInClosure { .. }) | InstanceKind::Shim(ShimKind::DropGlue(..)) | InstanceKind::Shim(ShimKind::Clone(..)) - | InstanceKind::Shim(ShimKind::FnPtrAddr(..)) => return Visibility::Hidden, + | InstanceKind::Shim(ShimKind::FnPtrAsPtr(..)) + | InstanceKind::Shim(ShimKind::FnPtrFromPtr(..)) => return Visibility::Hidden, }; // Both the `start_fn` lang item and `main` itself should not be exported, diff --git a/compiler/rustc_span/src/symbol.rs b/compiler/rustc_span/src/symbol.rs index 8d6661ca1194b..6bd11e83135c9 100644 --- a/compiler/rustc_span/src/symbol.rs +++ b/compiler/rustc_span/src/symbol.rs @@ -256,7 +256,6 @@ symbols! { Mutex, MutexGuard, Named, - NonNull, NonZero, None, Normal, @@ -634,6 +633,7 @@ symbols! { cmp_partialord_lt, cmpxchg16b_target_feature, cmse_nonsecure_entry, + code, coerce_pointee_validated, coerce_shared, coerce_shared_target, @@ -1003,8 +1003,10 @@ symbols! { fn_mut, fn_once, fn_once_output, - fn_ptr_addr, + fn_ptr_as_ptr, + fn_ptr_from_ptr, fn_ptr_trait, + fn_static, forbid, force_target_feature, forget, @@ -1446,6 +1448,7 @@ symbols! { non_exhaustive_omitted_patterns_lint, non_lifetime_binders, non_modrs_mods, + non_null, nonblocking, none, nontemporal_store, diff --git a/compiler/rustc_ty_utils/src/diagnostics.rs b/compiler/rustc_ty_utils/src/diagnostics.rs index 07a2c844a717e..9eb4e0b9686b1 100644 --- a/compiler/rustc_ty_utils/src/diagnostics.rs +++ b/compiler/rustc_ty_utils/src/diagnostics.rs @@ -71,13 +71,6 @@ pub(crate) enum GenericConstantTooComplexSub { OperationNotSupported(#[primary_span] Span), } -#[derive(Diagnostic)] -#[diag("`FnPtr` trait with unexpected associated item")] -pub(crate) struct UnexpectedFnPtrAssociatedItem { - #[primary_span] - pub span: Span, -} - #[derive(Diagnostic)] #[diag( "monomorphising SIMD type `{$ty}` with a non-primitive-scalar (integer/float/pointer) element type `{$e_ty}`" diff --git a/compiler/rustc_ty_utils/src/instance.rs b/compiler/rustc_ty_utils/src/instance.rs index 3862f043fea09..a3e52c91dccf4 100644 --- a/compiler/rustc_ty_utils/src/instance.rs +++ b/compiler/rustc_ty_utils/src/instance.rs @@ -15,8 +15,6 @@ use rustc_trait_selection::traits; use tracing::debug; use traits::translate_args; -use crate::diagnostics::UnexpectedFnPtrAssociatedItem; - fn resolve_instance_raw<'tcx>( tcx: TyCtxt<'tcx>, key: ty::PseudoCanonicalInput<'tcx, (DefId, GenericArgsRef<'tcx>)>, @@ -297,22 +295,28 @@ fn resolve_associated_item<'tcx>( Some(ty::Instance::new_raw(trait_item_id, args)) } } else if tcx.is_lang_item(trait_ref.def_id, LangItem::FnPtrTrait) { - if tcx.is_lang_item(trait_item_id, LangItem::FnPtrAddr) { - let self_ty = trait_ref.self_ty(); - if !matches!(self_ty.kind(), ty::FnPtr(..)) { - return Ok(None); - } + let self_ty = trait_ref.self_ty(); + if !matches!(self_ty.kind(), ty::FnPtr(..)) { + return Ok(None); + } + if tcx.is_lang_item(trait_item_id, LangItem::FnPtrAsPtr) { Some(Instance { - def: ty::InstanceKind::Shim(ty::ShimKind::FnPtrAddr( + def: ty::InstanceKind::Shim(ty::ShimKind::FnPtrAsPtr( trait_item_id, self_ty, )), args: rcvr_args, }) - } else { - tcx.dcx().emit_fatal(UnexpectedFnPtrAssociatedItem { - span: tcx.def_span(trait_item_id), + } else if tcx.is_lang_item(trait_item_id, LangItem::FnPtrFromPtr) { + Some(Instance { + def: ty::InstanceKind::Shim(ty::ShimKind::FnPtrFromPtr( + trait_item_id, + self_ty, + )), + args: rcvr_args, }) + } else { + Some(Instance { def: ty::InstanceKind::Item(trait_item_id), args: rcvr_args }) } } else if let Some(target_kind) = tcx.fn_trait_kind_from_def_id(trait_ref.def_id) { // FIXME: This doesn't check for malformed libcore that defines, e.g., diff --git a/library/core/src/marker.rs b/library/core/src/marker.rs index a1a1ec56d14a1..1cb357e266ee6 100644 --- a/library/core/src/marker.rs +++ b/library/core/src/marker.rs @@ -1136,25 +1136,6 @@ marker_impls! { {T: ConstParamTy_ + ?Sized} &T, } -/// A common trait implemented by all function pointers. -// -// Note that while the trait is internal and unstable it is nevertheless -// exposed as a public bound of the stable `core::ptr::fn_addr_eq` function. -#[unstable( - feature = "fn_ptr_trait", - issue = "none", - reason = "internal trait for implementing various traits for all function pointers" -)] -#[lang = "fn_ptr_trait"] -#[fundamental] -#[rustc_deny_explicit_impl] -#[rustc_dyn_incompatible_trait] -pub trait FnPtr: Copy + Clone { - /// Returns the address of the function pointer. - #[lang = "fn_ptr_addr"] - fn addr(self) -> *const (); -} - /// Derive macro that makes a smart pointer usable with trait objects. /// /// # What this macro does diff --git a/library/core/src/ops/function.rs b/library/core/src/ops/function.rs index 15b54243c1eed..d40603e15bb1b 100644 --- a/library/core/src/ops/function.rs +++ b/library/core/src/ops/function.rs @@ -1,5 +1,5 @@ use crate::marker::Tuple; - +use crate::ptr::NonNull; /// The version of the call operator that takes an immutable receiver. /// /// Instances of `Fn` can be called repeatedly without mutating state. @@ -311,3 +311,40 @@ mod impls { } } } + +unsafe extern "C" { + /// A type representing a pointer to a function pointer. + #[unstable(feature = "fn_static", issue = "148768")] + #[lang = "code"] + pub type Code; +} + +/// A common trait implemented by all function pointers. +#[unstable(feature = "fn_static", issue = "148768")] +#[lang = "fn_ptr_trait"] +#[fundamental] +#[rustc_deny_explicit_impl] +#[rustc_dyn_incompatible_trait] +pub trait FnPtr: Copy { + /// Returns the address of the function pointer. + #[unstable(feature = "fn_static", issue = "148768")] + fn addr(self) -> usize { + self.as_ptr().addr().get() + } + + /// Returns the function pointer as a [`NonNull`]. + #[unstable(feature = "fn_static", issue = "148768")] + #[lang = "fn_ptr_as_ptr"] + fn as_ptr(self) -> NonNull; + + /// Constructs a function pointer from a `NonNull` pointer. + /// + /// # Safety + /// + /// The function pointer must have been obtained + /// from an [`FnPtr::as_ptr`] call from a function + /// pointer type that is ABI compatible. + #[unstable(feature = "fn_static", issue = "148768")] + #[lang = "fn_ptr_from_ptr"] + unsafe fn from_ptr(ptr: NonNull) -> Self; +} diff --git a/library/core/src/ops/mod.rs b/library/core/src/ops/mod.rs index 87dd873fdb57d..6fa96c242fa76 100644 --- a/library/core/src/ops/mod.rs +++ b/library/core/src/ops/mod.rs @@ -176,6 +176,8 @@ pub use self::deref::Receiver; pub use self::deref::{Deref, DerefMut}; #[stable(feature = "rust1", since = "1.0.0")] pub use self::drop::Drop; +#[unstable(feature = "fn_static", issue = "148768")] +pub use self::function::{Code, FnPtr}; #[stable(feature = "rust1", since = "1.0.0")] pub use self::function::{Fn, FnMut, FnOnce}; #[stable(feature = "rust1", since = "1.0.0")] diff --git a/library/core/src/ptr/mod.rs b/library/core/src/ptr/mod.rs index 41f4b837efaea..274d6b73cd323 100644 --- a/library/core/src/ptr/mod.rs +++ b/library/core/src/ptr/mod.rs @@ -428,9 +428,10 @@ use crate::cmp::Ordering; use crate::intrinsics::const_eval_select; -use crate::marker::{Destruct, FnPtr, PointeeSized}; +use crate::marker::{Destruct, PointeeSized}; use crate::mem::{self, MaybeUninit, SizedTypeProperties}; use crate::num::NonZero; +use crate::ops::FnPtr; use crate::{fmt, hash, intrinsics, ub_checks}; #[unstable(feature = "ptr_alignment_type", issue = "102070")] @@ -2660,21 +2661,21 @@ impl Ord for F { #[stable(feature = "fnptr_impls", since = "1.4.0")] impl hash::Hash for F { fn hash(&self, state: &mut HH) { - state.write_usize(self.addr().addr()) + state.write_usize(self.addr()) } } #[stable(feature = "fnptr_impls", since = "1.4.0")] impl fmt::Pointer for F { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::pointer_fmt_inner(self.addr().addr(), f) + fmt::pointer_fmt_inner(self.addr(), f) } } #[stable(feature = "fnptr_impls", since = "1.4.0")] impl fmt::Debug for F { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::pointer_fmt_inner(self.addr().addr(), f) + fmt::pointer_fmt_inner(self.addr(), f) } } diff --git a/library/core/src/ptr/non_null.rs b/library/core/src/ptr/non_null.rs index bf5355ffc141d..5ec875cf47868 100644 --- a/library/core/src/ptr/non_null.rs +++ b/library/core/src/ptr/non_null.rs @@ -75,7 +75,7 @@ use crate::{fmt, hash, intrinsics, mem, ptr}; #[stable(feature = "nonnull", since = "1.25.0")] #[repr(transparent)] #[rustc_nonnull_optimization_guaranteed] -#[rustc_diagnostic_item = "NonNull"] +#[lang = "non_null"] pub struct NonNull { pointer: crate::pattern_type!(*const T is !null), } diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index e1061af1e7d6d..b749142e02991 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -348,7 +348,7 @@ #![feature(float_gamma)] #![feature(float_minimum_maximum)] #![feature(fmt_internals)] -#![feature(fn_ptr_trait)] +#![feature(fn_static)] #![feature(formatting_options)] #![feature(funnel_shifts)] #![feature(generic_atomic)] diff --git a/library/std/src/sys/pal/unix/weak/dlsym.rs b/library/std/src/sys/pal/unix/weak/dlsym.rs index 4967b93cc52b5..170e356dbc72f 100644 --- a/library/std/src/sys/pal/unix/weak/dlsym.rs +++ b/library/std/src/sys/pal/unix/weak/dlsym.rs @@ -1,5 +1,6 @@ use crate::ffi::{CStr, c_char, c_void}; -use crate::marker::{FnPtr, PhantomData}; +use crate::marker::PhantomData; +use crate::ops::FnPtr; use crate::sync::atomic::{Atomic, AtomicPtr, Ordering}; use crate::{mem, ptr}; diff --git a/src/tools/clippy/clippy_lints/src/methods/zst_offset.rs b/src/tools/clippy/clippy_lints/src/methods/zst_offset.rs index 3efb267328984..86b9847929151 100644 --- a/src/tools/clippy/clippy_lints/src/methods/zst_offset.rs +++ b/src/tools/clippy/clippy_lints/src/methods/zst_offset.rs @@ -3,7 +3,6 @@ use clippy_utils::res::MaybeDef as _; use rustc_hir as hir; use rustc_lint::LateContext; use rustc_middle::ty; -use rustc_span::sym; use super::ZST_OFFSET; @@ -11,7 +10,7 @@ pub(super) fn check(cx: &LateContext<'_>, expr: &hir::Expr<'_>, recv: &hir::Expr let recv_ty = cx.typeck_results().expr_ty(recv); let pointee_ty = match recv_ty.kind() { ty::RawPtr(ty, _) => *ty, - ty::Adt(_, args) if recv_ty.is_diag_item(cx, sym::NonNull) => args.type_at(0), + ty::Adt(_, args) if recv_ty.is_lang_item(cx, hir::LangItem::NonNull) => args.type_at(0), _ => return, }; if let Ok(layout) = cx.tcx.layout_of(cx.typing_env().as_query_input(pointee_ty)) diff --git a/src/tools/clippy/clippy_lints/src/non_send_fields_in_send_ty.rs b/src/tools/clippy/clippy_lints/src/non_send_fields_in_send_ty.rs index dc8111a51f1ee..e216c155a8173 100644 --- a/src/tools/clippy/clippy_lints/src/non_send_fields_in_send_ty.rs +++ b/src/tools/clippy/clippy_lints/src/non_send_fields_in_send_ty.rs @@ -5,7 +5,7 @@ use clippy_utils::source::snippet; use clippy_utils::ty::{implements_trait, is_copy}; use rustc_ast::ImplPolarity; use rustc_hir::def_id::DefId; -use rustc_hir::{FieldDef, Item, ItemKind, Node}; +use rustc_hir::{FieldDef, Item, ItemKind, LangItem, Node}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::{self, GenericArgKind, Ty}; use rustc_session::impl_lint_pass; @@ -227,7 +227,7 @@ fn contains_pointer_like<'tcx>(cx: &LateContext<'tcx>, target_ty: Ty<'tcx>) -> b ty::RawPtr(_, _) => { return true; }, - ty::Adt(adt_def, _) if cx.tcx.is_diagnostic_item(sym::NonNull, adt_def.did()) => { + ty::Adt(adt_def, _) if cx.tcx.is_lang_item(adt_def.did(), LangItem::NonNull) => { return true; }, _ => (), diff --git a/src/tools/clippy/clippy_lints/src/nonnull_unchecked_on_box_ptr.rs b/src/tools/clippy/clippy_lints/src/nonnull_unchecked_on_box_ptr.rs index 4ce51dffd6558..fce7fce85b8c5 100644 --- a/src/tools/clippy/clippy_lints/src/nonnull_unchecked_on_box_ptr.rs +++ b/src/tools/clippy/clippy_lints/src/nonnull_unchecked_on_box_ptr.rs @@ -56,7 +56,7 @@ impl<'tcx> LateLintPass<'tcx> for NonnullUncheckedOnBoxPtr { .ty_rel_def_if_named(cx, sym::new_unchecked) .opt_parent(cx) .opt_impl_ty(cx) - .is_diag_item(cx, sym::NonNull) + .is_lang_item(cx, LangItem::NonNull) && box_into_raw .ty_rel_def_if_named(cx, sym::into_raw) .opt_parent(cx) diff --git a/src/tools/clippy/clippy_lints/src/volatile_composites.rs b/src/tools/clippy/clippy_lints/src/volatile_composites.rs index e7eeade451724..e370bc63ea9cf 100644 --- a/src/tools/clippy/clippy_lints/src/volatile_composites.rs +++ b/src/tools/clippy/clippy_lints/src/volatile_composites.rs @@ -1,7 +1,7 @@ use clippy_utils::diagnostics::span_lint; use clippy_utils::res::MaybeDef as _; use clippy_utils::sym; -use rustc_hir::{Expr, ExprKind}; +use rustc_hir::{Expr, ExprKind, LangItem}; use rustc_lint::{LateContext, LateLintPass}; use rustc_middle::ty::layout::LayoutOf as _; use rustc_middle::ty::{self, Ty, TypeVisitableExt as _}; @@ -155,7 +155,7 @@ impl<'tcx> LateLintPass<'tcx> for VolatileComposites { // Raw pointers ty::RawPtr(innerty, _) => report_volatile_safe(cx, expr, *innerty), // std::ptr::NonNull - ty::Adt(_, args) if self_ty.is_diag_item(cx, sym::NonNull) => { + ty::Adt(_, args) if self_ty.is_lang_item(cx, LangItem::NonNull) => { report_volatile_safe(cx, expr, args.type_at(0)); }, _ => (), diff --git a/src/tools/rust-analyzer/crates/hir-def/src/lang_item.rs b/src/tools/rust-analyzer/crates/hir-def/src/lang_item.rs index 534a9c31cd531..ec0dfa155a1b3 100644 --- a/src/tools/rust-analyzer/crates/hir-def/src/lang_item.rs +++ b/src/tools/rust-analyzer/crates/hir-def/src/lang_item.rs @@ -462,8 +462,11 @@ language_item_table! { LangItems => Freeze, sym::freeze, TraitId; + NonNull, sym::non_null, StructId; + FnPtrTrait, sym::fn_ptr_trait, TraitId; - FnPtrAddr, sym::fn_ptr_addr, FunctionId; + FnPtrAsPtr, sym::fn_ptr_as_ptr, FunctionId; + FnPtrFromPtr, sym::fn_ptr_from_ptr, FunctionId; Drop, sym::drop, TraitId; Destruct, sym::destruct, TraitId; diff --git a/src/tools/rust-analyzer/crates/intern/src/symbol/symbols.rs b/src/tools/rust-analyzer/crates/intern/src/symbol/symbols.rs index 9a566ee687e0d..35818ab82b47a 100644 --- a/src/tools/rust-analyzer/crates/intern/src/symbol/symbols.rs +++ b/src/tools/rust-analyzer/crates/intern/src/symbol/symbols.rs @@ -250,6 +250,7 @@ define_symbols! { clone, trivial_clone, Clone, + code, coerce_unsized, column, completion, @@ -327,7 +328,8 @@ define_symbols! { async_fn_kind_upvars, call_ref_future, call_once_future, - fn_ptr_addr, + fn_ptr_as_ptr, + fn_ptr_from_ptr, fn_ptr_trait, format_alignment, format_args_nl, @@ -438,6 +440,7 @@ define_symbols! { no_mangle, no_std, non_exhaustive, + non_null, none, None, not, diff --git a/tests/ui/feature-gates/feature-gate-fn_static.rs b/tests/ui/feature-gates/feature-gate-fn_static.rs new file mode 100644 index 0000000000000..5111c7ab6e785 --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-fn_static.rs @@ -0,0 +1,4 @@ +use std::ops::FnPtr; +//~^ ERROR: use of unstable library feature `fn_static` [E0658] + +fn main() {} diff --git a/tests/ui/feature-gates/feature-gate-fn_static.stderr b/tests/ui/feature-gates/feature-gate-fn_static.stderr new file mode 100644 index 0000000000000..1b4bfd835d617 --- /dev/null +++ b/tests/ui/feature-gates/feature-gate-fn_static.stderr @@ -0,0 +1,13 @@ +error[E0658]: use of unstable library feature `fn_static` + --> $DIR/feature-gate-fn_static.rs:1:5 + | +LL | use std::ops::FnPtr; + | ^^^^^^^^^^^^^^^ + | + = note: see issue #148768 for more information + = help: add `#![feature(fn_static)]` to the crate attributes to enable + = note: this compiler was built on YYYY-MM-DD; consider upgrading it if it is out of date + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0658`. diff --git a/tests/ui/fn/fn-ptr-trait-run.rs b/tests/ui/fn/fn-ptr-trait-run.rs new file mode 100644 index 0000000000000..529deb9be1e0a --- /dev/null +++ b/tests/ui/fn/fn-ptr-trait-run.rs @@ -0,0 +1,15 @@ +#![feature(fn_static)] +//@ run-pass + +use std::ops::FnPtr; + +fn bar(a: u64) -> u64 { + a +} + +fn main() { + type F = fn(u64) -> u64; + let b: F = bar; + assert_eq!(b.addr(), bar as *const () as usize); + assert_eq!(b(42), unsafe { F::from_ptr(b.as_ptr())(42) }); +} diff --git a/tests/ui/fn/fn-ptr-trait.rs b/tests/ui/fn/fn-ptr-trait.rs index b9096d5f303f5..dcd1b38d56047 100644 --- a/tests/ui/fn/fn-ptr-trait.rs +++ b/tests/ui/fn/fn-ptr-trait.rs @@ -1,7 +1,7 @@ -#![feature(fn_ptr_trait)] +#![feature(fn_static)] //@ check-pass -use std::marker::FnPtr; +use std::ops::FnPtr; trait Foo {} impl Foo for T where T: FnPtr {} diff --git a/tests/ui/hygiene/unpretty-debug-lifetimes.stdout b/tests/ui/hygiene/unpretty-debug-lifetimes.stdout index 689453326c0b5..c75cc7b2179d3 100644 --- a/tests/ui/hygiene/unpretty-debug-lifetimes.stdout +++ b/tests/ui/hygiene/unpretty-debug-lifetimes.stdout @@ -15,8 +15,8 @@ macro lifetime_hygiene /* 0#0 */ { - ($f /* 0#0 */:ident /* 0#0 */<$a /* 0#0 */:lifetime /* 0#0 */>) - => + ($f /* 0#0 */:ident /* 0#0 */<$a /* 0#0 */:lifetime /* 0#0 + */>) => { fn /* 0#0 */ $f /* 0#0 */<$a /* 0#0 */, 'a /* 0#0 */>() {} } } fn f /* 0#0 */<'a /* 0#0 */, 'a /* 0#1 */>() {} diff --git a/tests/ui/traits/next-solver/diagnostics/dont-pick-fnptr-bound-as-leaf.rs b/tests/ui/traits/next-solver/diagnostics/dont-pick-fnptr-bound-as-leaf.rs index 0da7bb17a58a2..b7a4c911746de 100644 --- a/tests/ui/traits/next-solver/diagnostics/dont-pick-fnptr-bound-as-leaf.rs +++ b/tests/ui/traits/next-solver/diagnostics/dont-pick-fnptr-bound-as-leaf.rs @@ -6,9 +6,9 @@ // to give as the reason why the bound does not hold. This test checks that we do not // try to tell the user that `Foo: FnPtr` is unimplemented as that would be confusing. -#![feature(fn_ptr_trait)] +#![feature(fn_static)] -use std::marker::FnPtr; +use std::ops::FnPtr; trait Trait {} From 7672b83df3c03681271fd5cbbe0684f860f0e590 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Tue, 4 Aug 2026 14:41:47 -0700 Subject: [PATCH 2/9] Upgrade and deduplicate dependencies - Upgrade from `getrandom v0.4.2` to `v0.4.3` to drop its `wasip2` and `wasip3` dependencies and many transitives. - Upgrade from `gimli v0.33` to `v0.34` as a direct dependency and through a `thorin-dwp` upgrade. - Upgrade from `object v0.37` and `v0.38` to `v0.39` as a direct dependency and via `ar_archive_writer` and `thorin-dwp` upgrades. - Upgrade `libloading` and `wasmparser` to match other dependencies. This also consolidates from `hashbrown v0.15`, `v0.16`, and `v0.17` to just `v0.17.1`, which is the same that `std` currently uses. --- Cargo.lock | 297 +++--------------- compiler/rustc_codegen_gcc/Cargo.lock | 4 +- compiler/rustc_codegen_gcc/Cargo.toml | 2 +- compiler/rustc_codegen_llvm/Cargo.toml | 4 +- compiler/rustc_codegen_ssa/Cargo.toml | 6 +- .../src/back/link/raw_dylib.rs | 6 +- compiler/rustc_metadata/Cargo.toml | 2 +- compiler/rustc_metadata/src/host_dylib.rs | 2 +- compiler/rustc_target/Cargo.toml | 2 +- src/bootstrap/Cargo.lock | 4 +- src/bootstrap/Cargo.toml | 2 +- src/bootstrap/src/utils/proc_macro_deps.rs | 19 +- src/tools/run-make-support/Cargo.toml | 6 +- src/tools/tidy/src/deps.rs | 3 +- .../duplicated-path-in-error.gnu.stderr | 2 +- 15 files changed, 71 insertions(+), 290 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 60988e0ff4bc1..e63c0027f449a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -177,11 +177,11 @@ checksum = "7f202df86484c868dbad7eaa557ef785d5c66295e41b460ef922eca0723b842c" [[package]] name = "ar_archive_writer" -version = "0.5.2" +version = "0.5.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4087686b4b0a3427190bae57a1d9a478dbb2d40c5dc1bd6e2b6d797913bdd348" +checksum = "73cd58deff2140a0a8eae87e417bd01db68a33e148aa93d1e8cd837e55e312b6" dependencies = [ - "object 0.37.3", + "object 0.39.1", ] [[package]] @@ -1603,16 +1603,14 @@ dependencies = [ [[package]] name = "getrandom" -version = "0.4.2" +version = "0.4.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0de51e6874e94e7bf76d726fc5d13ba782deca734ff60d5bb2fb2607c7406555" +checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" dependencies = [ "cfg-if", "libc", "r-efi 6.0.0", "rand_core 0.10.1", - "wasip2", - "wasip3", ] [[package]] @@ -1623,12 +1621,12 @@ checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" [[package]] name = "gimli" -version = "0.33.0" +version = "0.34.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0bf7f043f89559805f8c7cacc432749b2fa0d0a0a9ee46ce47164ed5ba7f126c" +checksum = "1033caf0b349c518623b5396bfb2cf0bddf44f0306d543a250e5743297aafd10" dependencies = [ "fnv", - "hashbrown 0.16.1", + "hashbrown", "indexmap", "stable_deref_trait", ] @@ -1678,31 +1676,13 @@ dependencies = [ [[package]] name = "hashbrown" -version = "0.15.5" +version = "0.17.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9229cfe53dfd69f0609a49f65461bd93001ea1ef889cd5529dd176593f5338a1" -dependencies = [ - "foldhash 0.1.5", -] - -[[package]] -name = "hashbrown" -version = "0.16.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "841d1cc9bed7f9236f321df977030373f4a4163ae1a7dbfe1a51a2c1a51d9100" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" dependencies = [ "allocator-api2", "equivalent", "foldhash 0.2.0", -] - -[[package]] -name = "hashbrown" -version = "0.17.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4f467dd6dccf739c208452f8014c75c18bb8301b050ad1cfb27153803edb0f51" -dependencies = [ - "foldhash 0.2.0", "serde", "serde_core", ] @@ -1996,7 +1976,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" dependencies = [ "equivalent", - "hashbrown 0.17.0", + "hashbrown", "serde", "serde_core", ] @@ -2319,16 +2299,6 @@ dependencies = [ "pkg-config", ] -[[package]] -name = "libloading" -version = "0.8.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7c4b02199fee7c5d21a5ae7d8cfa79a6ef5bb2fc834d6e9058e89c825efdc55" -dependencies = [ - "cfg-if", - "windows-link 0.2.1", -] - [[package]] name = "libloading" version = "0.9.0" @@ -2563,11 +2533,11 @@ dependencies = [ "colored", "directories", "genmc-sys", - "getrandom 0.4.2", + "getrandom 0.4.3", "ipc-channel", "libc", "libffi", - "libloading 0.9.0", + "libloading", "measureme", "mio", "nix", @@ -2779,26 +2749,17 @@ dependencies = [ [[package]] name = "object" -version = "0.37.3" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ff76201f031d8863c38aa7f905eca4f53abbfa15f609db4277d44cd8938f33fe" -dependencies = [ - "memchr", -] - -[[package]] -name = "object" -version = "0.38.1" +version = "0.39.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "271638cd5fa9cca89c4c304675ca658efc4e64a66c716b7cfe1afb4b9611dbbc" +checksum = "2e5a6c098c7a3b6547378093f5cc30bc54fd361ce711e05293a5cc589562739b" dependencies = [ "crc32fast", "flate2", - "hashbrown 0.16.1", + "hashbrown", "indexmap", "memchr", "ruzstd", - "wasmparser 0.243.0", + "wasmparser 0.247.0", ] [[package]] @@ -3162,16 +3123,6 @@ dependencies = [ "owo-colors", ] -[[package]] -name = "prettyplease" -version = "0.2.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "479ca8adacdd7ce8f1fb39ce9ecccbfe93a3f1344b3d0d97f20bc0196208f62b" -dependencies = [ - "proc-macro2", - "syn 2.0.117", -] - [[package]] name = "proc-macro-hack" version = "0.5.20+deprecated" @@ -3293,7 +3244,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d2e8e8bcc7961af1fdac401278c6a831614941f6164ee3bf4ce61b7edb162207" dependencies = [ "chacha20", - "getrandom 0.4.2", + "getrandom 0.4.3", "rand_core 0.10.1", ] @@ -3477,7 +3428,7 @@ checksum = "d9776093b7ca170454ab1406954f7b7d97a57c51dc6c0642957fb2ef25c2d399" dependencies = [ "bytecheck", "bytes", - "hashbrown 0.17.0", + "hashbrown", "indexmap", "munge", "ptr_meta", @@ -3505,15 +3456,15 @@ version = "0.0.0" dependencies = [ "bstr", "build_helper", - "gimli 0.33.0", + "gimli 0.34.0", "libc", - "object 0.38.1", + "object 0.39.1", "regex", "rustdoc-json-types", "serde_json", "similar", "tempfile", - "wasmparser 0.243.0", + "wasmparser 0.247.0", ] [[package]] @@ -3807,12 +3758,12 @@ name = "rustc_codegen_llvm" version = "0.0.0" dependencies = [ "bitflags", - "gimli 0.33.0", + "gimli 0.34.0", "itertools", "libc", - "libloading 0.9.0", + "libloading", "measureme", - "object 0.38.1", + "object 0.39.1", "rustc-demangle", "rustc_abi", "rustc_ast", @@ -3846,7 +3797,7 @@ dependencies = [ "find-msvc-tools", "itertools", "libc", - "object 0.38.1", + "object 0.39.1", "pathdiff", "regex", "rustc_abi", @@ -3876,7 +3827,7 @@ dependencies = [ "tempfile", "thorin-dwp", "tracing", - "wasm-encoder 0.219.2", + "wasm-encoder 0.247.0", "windows 0.61.3", ] @@ -3912,7 +3863,7 @@ dependencies = [ "either", "elsa", "ena", - "hashbrown 0.17.0", + "hashbrown", "indexmap", "jobserver", "libc", @@ -4376,7 +4327,7 @@ version = "0.0.0" dependencies = [ "bitflags", "libc", - "libloading 0.8.9", + "libloading", "odht", "rustc_abi", "rustc_ast", @@ -4809,7 +4760,7 @@ version = "0.0.0" dependencies = [ "arrayvec", "bitflags", - "object 0.38.1", + "object 0.39.1", "rustc_abi", "rustc_data_structures", "rustc_error_messages", @@ -5650,13 +5601,14 @@ dependencies = [ [[package]] name = "thorin-dwp" -version = "0.10.0" +version = "0.11.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6ce6b46108e50803d2c10216929e49fa3eda07ee3dc246310c18c4a1e3b1fa58" +checksum = "b5938a79ecf9cb8198d525ddb37cd8841f66ab98073f6a123af7ed7cdcbb73ae" dependencies = [ - "gimli 0.33.0", - "hashbrown 0.16.1", - "object 0.38.1", + "gimli 0.34.0", + "hashbrown", + "itertools", + "object 0.39.1", "tracing", ] @@ -6301,24 +6253,6 @@ version = "46.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1b6c48003fe59c201c97a7786ff55feabe6b6f83b598aa9ff5bcc4f94d940bf3" -[[package]] -name = "wasip2" -version = "1.0.3+wasi-0.2.9" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "20064672db26d7cdc89c7798c48a0fdfac8213434a1186e5ef29fd560ae223d6" -dependencies = [ - "wit-bindgen 0.57.1", -] - -[[package]] -name = "wasip3" -version = "0.4.0+wasi-0.3.0-rc-2026-01-06" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5428f8bf88ea5ddc08faddef2ac4a67e390b88186c703ce6dbd955e1c145aca5" -dependencies = [ - "wit-bindgen 0.51.0", -] - [[package]] name = "wasm-bindgen" version = "0.2.105" @@ -6381,8 +6315,8 @@ dependencies = [ "wat", "windows-sys 0.61.2", "winsplit", - "wit-component 0.254.0", - "wit-parser 0.254.0", + "wit-component", + "wit-parser", ] [[package]] @@ -6394,22 +6328,12 @@ dependencies = [ [[package]] name = "wasm-encoder" -version = "0.219.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "8aa79bcd666a043b58f5fa62b221b0b914dd901e6f620e8ab7371057a797f3e1" -dependencies = [ - "leb128", - "wasmparser 0.219.2", -] - -[[package]] -name = "wasm-encoder" -version = "0.244.0" +version = "0.247.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "990065f2fe63003fe337b932cfb5e3b80e0b4d0f5ff650e6985b1048f62c8319" +checksum = "30b6733b8b91d010a6ac5b0fb237dc46a19650bc4c67db66857e2e787d437204" dependencies = [ "leb128fmt", - "wasmparser 0.244.0", + "wasmparser 0.247.0", ] [[package]] @@ -6422,18 +6346,6 @@ dependencies = [ "wasmparser 0.254.0", ] -[[package]] -name = "wasm-metadata" -version = "0.244.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "bb0e353e6a2fbdc176932bbaab493762eb1255a7900fe0fea1a2f96c296cc909" -dependencies = [ - "anyhow", - "indexmap", - "wasm-encoder 0.244.0", - "wasmparser 0.244.0", -] - [[package]] name = "wasm-metadata" version = "0.254.0" @@ -6448,33 +6360,12 @@ dependencies = [ [[package]] name = "wasmparser" -version = "0.219.2" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5220ee4c6ffcc0cb9d7c47398052203bc902c8ef3985b0c8134118440c0b2921" -dependencies = [ - "bitflags", - "indexmap", -] - -[[package]] -name = "wasmparser" -version = "0.243.0" +version = "0.247.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f6d8db401b0528ec316dfbe579e6ab4152d61739cfe076706d2009127970159d" +checksum = "8e6fb4c2bee46c5ea4d40f8cdb5c131725cd976718ec56f1c8e82fbde5fa2a80" dependencies = [ "bitflags", "indexmap", -] - -[[package]] -name = "wasmparser" -version = "0.244.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "47b807c72e1bac69382b3a6fb3dbe8ea4c0ed87ff5629b8685ae6b9a611028fe" -dependencies = [ - "bitflags", - "hashbrown 0.15.5", - "indexmap", "semver", ] @@ -6485,7 +6376,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d5769a29f799fbab136aaf65b4fe5384cd7d93fe6fc9ba0dcb6c8382a1f16e27" dependencies = [ "bitflags", - "hashbrown 0.17.0", + "hashbrown", "indexmap", "semver", "serde", @@ -6869,32 +6760,6 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "3ab703352da6a72f35c39a533526393725640575bb211f61987a2748323ad956" -[[package]] -name = "wit-bindgen" -version = "0.51.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7249219f66ced02969388cf2bb044a09756a083d0fab1e566056b04d9fbcaa5" -dependencies = [ - "wit-bindgen-rust-macro", -] - -[[package]] -name = "wit-bindgen" -version = "0.57.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e" - -[[package]] -name = "wit-bindgen-core" -version = "0.51.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea61de684c3ea68cb082b7a88508a8b27fcc8b797d738bfc99a82facf1d752dc" -dependencies = [ - "anyhow", - "heck", - "wit-parser 0.244.0", -] - [[package]] name = "wit-bindgen-rt" version = "0.39.0" @@ -6904,56 +6769,6 @@ dependencies = [ "bitflags", ] -[[package]] -name = "wit-bindgen-rust" -version = "0.51.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "b7c566e0f4b284dd6561c786d9cb0142da491f46a9fbed79ea69cdad5db17f21" -dependencies = [ - "anyhow", - "heck", - "indexmap", - "prettyplease", - "syn 2.0.117", - "wasm-metadata 0.244.0", - "wit-bindgen-core", - "wit-component 0.244.0", -] - -[[package]] -name = "wit-bindgen-rust-macro" -version = "0.51.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0c0f9bfd77e6a48eccf51359e3ae77140a7f50b1e2ebfe62422d8afdaffab17a" -dependencies = [ - "anyhow", - "prettyplease", - "proc-macro2", - "quote", - "syn 2.0.117", - "wit-bindgen-core", - "wit-bindgen-rust", -] - -[[package]] -name = "wit-component" -version = "0.244.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d66ea20e9553b30172b5e831994e35fbde2d165325bec84fc43dbf6f4eb9cb2" -dependencies = [ - "anyhow", - "bitflags", - "indexmap", - "log", - "serde", - "serde_derive", - "serde_json", - "wasm-encoder 0.244.0", - "wasm-metadata 0.244.0", - "wasmparser 0.244.0", - "wit-parser 0.244.0", -] - [[package]] name = "wit-component" version = "0.254.0" @@ -6968,27 +6783,9 @@ dependencies = [ "serde_derive", "serde_json", "wasm-encoder 0.254.0", - "wasm-metadata 0.254.0", + "wasm-metadata", "wasmparser 0.254.0", - "wit-parser 0.254.0", -] - -[[package]] -name = "wit-parser" -version = "0.244.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ecc8ac4bc1dc3381b7f59c34f00b67e18f910c2c0f50015669dde7def656a736" -dependencies = [ - "anyhow", - "id-arena", - "indexmap", - "log", - "semver", - "serde", - "serde_derive", - "serde_json", - "unicode-xid", - "wasmparser 0.244.0", + "wit-parser", ] [[package]] @@ -6998,7 +6795,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "1655131e4f7d3f0cb141f6eca71315ca40eff0f3d4de7cff0a82bacedd8c89b4" dependencies = [ "anyhow", - "hashbrown 0.17.0", + "hashbrown", "id-arena", "indexmap", "log", diff --git a/compiler/rustc_codegen_gcc/Cargo.lock b/compiler/rustc_codegen_gcc/Cargo.lock index a283ea4cb0b05..7ce94b58c0516 100644 --- a/compiler/rustc_codegen_gcc/Cargo.lock +++ b/compiler/rustc_codegen_gcc/Cargo.lock @@ -145,9 +145,9 @@ dependencies = [ [[package]] name = "object" -version = "0.37.1" +version = "0.39.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "03fd943161069e1768b4b3d050890ba48730e590f57e56d4aa04e7e090e61b4a" +checksum = "2e5a6c098c7a3b6547378093f5cc30bc54fd361ce711e05293a5cc589562739b" dependencies = [ "memchr", ] diff --git a/compiler/rustc_codegen_gcc/Cargo.toml b/compiler/rustc_codegen_gcc/Cargo.toml index 8956bd6948979..ac5e94b9454e2 100644 --- a/compiler/rustc_codegen_gcc/Cargo.toml +++ b/compiler/rustc_codegen_gcc/Cargo.toml @@ -18,7 +18,7 @@ master = ["gccjit/master"] default = ["master"] [dependencies] -object = { version = "0.37.0", default-features = false, features = ["std", "read"] } +object = { version = "0.39.0", default-features = false, features = ["std", "read"] } tempfile = "3.20" gccjit = { version = "3.3.0", features = ["dlopen"] } #gccjit = { git = "https://github.com/rust-lang/gccjit.rs", branch = "error-dlopen", features = ["dlopen"] } diff --git a/compiler/rustc_codegen_llvm/Cargo.toml b/compiler/rustc_codegen_llvm/Cargo.toml index f085eba9d5307..f2b0d2f36dc78 100644 --- a/compiler/rustc_codegen_llvm/Cargo.toml +++ b/compiler/rustc_codegen_llvm/Cargo.toml @@ -11,12 +11,12 @@ test = false bitflags = "2.4.1" # To avoid duplicate dependencies, this should match the version of gimli used # by `rustc_codegen_ssa` via its `thorin-dwp` dependency. -gimli = "0.33" +gimli = "0.34" itertools = "0.15" libc = "0.2" libloading = { version = "0.9.0" } measureme = "12.0.1" -object = { version = "0.38.1", default-features = false, features = ["std", "read"] } +object = { version = "0.39.1", default-features = false, features = ["std", "read"] } rustc-demangle = "0.1.28" rustc_abi = { path = "../rustc_abi" } rustc_ast = { path = "../rustc_ast" } diff --git a/compiler/rustc_codegen_ssa/Cargo.toml b/compiler/rustc_codegen_ssa/Cargo.toml index f33d144ac5c63..01c9e09a56544 100644 --- a/compiler/rustc_codegen_ssa/Cargo.toml +++ b/compiler/rustc_codegen_ssa/Cargo.toml @@ -37,9 +37,9 @@ rustc_trait_selection = { path = "../rustc_trait_selection" } serde_json = "1.0.59" smallvec = { version = "1.8.1", features = ["union", "may_dangle"] } tempfile = "3.2" -thorin-dwp = "0.10" +thorin-dwp = "0.11" tracing = "0.1" -wasm-encoder = "0.219" +wasm-encoder = "0.247" # tidy-alphabetical-end [target.'cfg(unix)'.dependencies] @@ -48,7 +48,7 @@ libc = "0.2.50" # tidy-alphabetical-end [dependencies.object] -version = "0.38.1" +version = "0.39.1" default-features = false features = ["read_core", "elf", "macho", "pe", "xcoff", "unaligned", "archive", "write", "wasm"] diff --git a/compiler/rustc_codegen_ssa/src/back/link/raw_dylib.rs b/compiler/rustc_codegen_ssa/src/back/link/raw_dylib.rs index f8cc07201d10f..778133466610e 100644 --- a/compiler/rustc_codegen_ssa/src/back/link/raw_dylib.rs +++ b/compiler/rustc_codegen_ssa/src/back/link/raw_dylib.rs @@ -477,13 +477,13 @@ fn create_elf_raw_dylib_stub(sess: &Session, soname: &str, symbols: &[DllImport] // the DT_SONAME will be used by the linker to populate DT_NEEDED // which the loader uses to find the library. stub.write_align_dynamic(); - stub.write_dynamic_string(elf::DT_SONAME, soname); + stub.write_dynamic_string(elf::DT_SONAME, soname).unwrap(); // LSB section "2.7. Symbol Versioning" requires `DT_VERDEFNUM` to be reliable. if verdef_count > 1 { - stub.write_dynamic(elf::DT_VERDEFNUM, verdef_count as u64); + stub.write_dynamic(elf::DT_VERDEFNUM, verdef_count as u64).unwrap(); } // DT_NULL terminates the .dynamic table. - stub.write_dynamic(elf::DT_NULL, 0); + stub.write_dynamic(elf::DT_NULL, 0).unwrap(); stub_buf } diff --git a/compiler/rustc_metadata/Cargo.toml b/compiler/rustc_metadata/Cargo.toml index 2fce131e08b6a..1bb01e08a207d 100644 --- a/compiler/rustc_metadata/Cargo.toml +++ b/compiler/rustc_metadata/Cargo.toml @@ -6,7 +6,7 @@ edition = "2024" [dependencies] # tidy-alphabetical-start bitflags = "2.4.1" -libloading = "0.8.0" +libloading = "0.9.0" odht = { version = "0.3.1", features = ["nightly"] } rustc_abi = { path = "../rustc_abi" } rustc_ast = { path = "../rustc_ast" } diff --git a/compiler/rustc_metadata/src/host_dylib.rs b/compiler/rustc_metadata/src/host_dylib.rs index 9bd2a57fcd285..8f446d2651207 100644 --- a/compiler/rustc_metadata/src/host_dylib.rs +++ b/compiler/rustc_metadata/src/host_dylib.rs @@ -33,7 +33,7 @@ fn attempt_load_dylib(path: &Path) -> Result pub static CRATES: &[&str] = &[ // tidy-alphabetical-start - "anyhow", + "allocator_api2", "askama_derive", "askama_parser", "basic_toml", - "bitflags", "block_buffer", "bumpalo", "cfg_if", @@ -27,32 +26,24 @@ pub static CRATES: &[&str] = &[ "glob", "hashbrown", "heck", - "id_arena", "ident_case", "indexmap", "intl_memoizer", "intl_pluralrules", - "itoa", - "leb128fmt", "libc", - "log", "memchr", "minimal_lexical", "nom", "pest", "pest_generator", "pest_meta", - "prettyplease", "proc_macro2", "quote", "rustc_hash", - "ryu", "self_cell", - "semver", "serde", "serde_core", "serde_derive_internals", - "serde_json", "sha2", "smallvec", "stable_deref_trait", @@ -68,18 +59,10 @@ pub static CRATES: &[&str] = &[ "unic_langid_impl", "unic_langid_macros", "unicode_ident", - "unicode_xid", "version_check", "wasm_bindgen_macro_support", "wasm_bindgen_shared", - "wasm_encoder", - "wasm_metadata", - "wasmparser", "winnow", - "wit_bindgen_core", - "wit_bindgen_rust", - "wit_component", - "wit_parser", "yoke", "zerofrom", "zerovec", diff --git a/src/tools/run-make-support/Cargo.toml b/src/tools/run-make-support/Cargo.toml index 697652012d48c..0e1310862589d 100644 --- a/src/tools/run-make-support/Cargo.toml +++ b/src/tools/run-make-support/Cargo.toml @@ -11,14 +11,14 @@ edition = "2024" # tidy-alphabetical-start bstr = "1.12" -gimli = "0.33" +gimli = "0.34" libc = "0.2" -object = { version = "0.38.1", features = ["wasm"] } +object = { version = "0.39.1", features = ["wasm"] } regex = "1.11" serde_json = "1.0" similar = "2.7" tempfile = "3" -wasmparser = { version = "0.243", default-features = false, features = ["std", "features", "validate"] } +wasmparser = { version = "0.247", default-features = false, features = ["std", "features", "validate"] } # tidy-alphabetical-end # Shared with bootstrap and compiletest diff --git a/src/tools/tidy/src/deps.rs b/src/tools/tidy/src/deps.rs index 3d2f118de1b93..721dcb851035a 100644 --- a/src/tools/tidy/src/deps.rs +++ b/src/tools/tidy/src/deps.rs @@ -370,7 +370,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[ "jiff-tzdb-platform", "jobserver", "lazy_static", - "leb128", + "leb128fmt", "libc", "libloading", "linux-raw-sys", @@ -432,6 +432,7 @@ const PERMITTED_RUSTC_DEPENDENCIES: &[&str] = &[ "scoped-tls", "scopeguard", "self_cell", + "semver", "serde", "serde_core", "serde_derive", diff --git a/tests/ui/codegen/duplicated-path-in-error.gnu.stderr b/tests/ui/codegen/duplicated-path-in-error.gnu.stderr index d0d34e2f93468..ed8b9f6a962d1 100644 --- a/tests/ui/codegen/duplicated-path-in-error.gnu.stderr +++ b/tests/ui/codegen/duplicated-path-in-error.gnu.stderr @@ -1,2 +1,2 @@ -error: couldn't load codegen backend /non-existing-one.so: cannot open shared object file: No such file or directory +error: couldn't load codegen backend /non-existing-one.so: dlopen failed: /non-existing-one.so: cannot open shared object file: No such file or directory From c234ba35f6a14aa3ff6374e16f9af672be672d2e Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Sun, 9 Aug 2026 14:56:55 -0700 Subject: [PATCH 3/9] Update run-make/wasm tests --- tests/run-make/wasm-import-module/rmake.rs | 2 +- tests/run-make/wasm-spurious-import/rmake.rs | 2 +- tests/run-make/wasm-symbols-different-module/rmake.rs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/run-make/wasm-import-module/rmake.rs b/tests/run-make/wasm-import-module/rmake.rs index 3b74cb205589d..77614ce1ceb86 100644 --- a/tests/run-make/wasm-import-module/rmake.rs +++ b/tests/run-make/wasm-import-module/rmake.rs @@ -15,7 +15,7 @@ fn main() { for payload in wasmparser::Parser::new(0).parse_all(&file) { let payload = payload.unwrap(); if let wasmparser::Payload::ImportSection(s) = payload { - for i in s { + for i in s.into_imports() { let i = i.unwrap(); imports.entry(i.module).or_insert(Vec::new()).push((i.name, i.ty)); } diff --git a/tests/run-make/wasm-spurious-import/rmake.rs b/tests/run-make/wasm-spurious-import/rmake.rs index 8fde8d295c7e2..435c6219aa502 100644 --- a/tests/run-make/wasm-spurious-import/rmake.rs +++ b/tests/run-make/wasm-spurious-import/rmake.rs @@ -20,7 +20,7 @@ fn main() { for payload in wasmparser::Parser::new(0).parse_all(&file) { let payload = payload.unwrap(); if let wasmparser::Payload::ImportSection(s) = payload { - for i in s { + for i in s.into_imports() { let i = i.unwrap(); imports.entry(i.module).or_insert(Vec::new()).push((i.name, i.ty)); } diff --git a/tests/run-make/wasm-symbols-different-module/rmake.rs b/tests/run-make/wasm-symbols-different-module/rmake.rs index 3cd459db02fae..0e7113c3df8f9 100644 --- a/tests/run-make/wasm-symbols-different-module/rmake.rs +++ b/tests/run-make/wasm-symbols-different-module/rmake.rs @@ -30,7 +30,7 @@ fn test(file: &str, args: &[&str], expected_imports: &[(&str, &[&str])]) { for payload in wasmparser::Parser::new(0).parse_all(&file) { let payload = payload.unwrap(); if let wasmparser::Payload::ImportSection(s) = payload { - for i in s { + for i in s.into_imports() { let i = i.unwrap(); imports.entry(i.module).or_insert(HashSet::new()).insert(i.name); } From 46eb4fde6a9eee926c46550031d8bd1b49c03d97 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Wed, 12 Aug 2026 18:52:28 +0000 Subject: [PATCH 4/9] clippy::needless_borrow --- library/alloc/src/boxed.rs | 2 +- library/alloc/src/collections/btree/map.rs | 6 +++--- library/alloc/src/collections/btree/node.rs | 2 +- library/alloc/src/collections/btree/set.rs | 4 ++-- library/alloc/src/io/impls.rs | 4 ++-- library/alloc/src/vec/splice.rs | 2 +- library/alloc/src/wtf8/mod.rs | 4 ++-- library/core/src/ffi/c_str.rs | 4 ++-- library/core/src/iter/traits/iterator.rs | 2 +- library/core/src/slice/ascii.rs | 2 +- library/core/src/slice/iter.rs | 2 +- library/core/src/str/iter.rs | 2 +- library/core/src/task/wake.rs | 4 ++-- library/std/src/ffi/os_str.rs | 10 +++++----- library/std/src/net/socket_addr.rs | 2 +- library/std/src/os/unix/net/ancillary.rs | 4 ++-- library/std/src/path.rs | 2 +- library/std/src/sync/nonpoison/rwlock.rs | 8 ++++---- library/std/src/sync/poison/rwlock.rs | 8 ++++---- library/std/src/sys/fs/common.rs | 2 +- library/std/src/sys/fs/unix.rs | 4 ++-- library/std/src/sys/fs/unix/dir.rs | 2 +- library/std/src/sys/fs/windows.rs | 10 +++++----- library/std/src/sys/process/unix/common.rs | 2 +- 24 files changed, 47 insertions(+), 47 deletions(-) diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index cd2508a76a10e..c25a06968e293 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -2141,7 +2141,7 @@ impl Clone for Box<[T], A> { /// ``` fn clone_from(&mut self, source: &Self) { if self.len() == source.len() { - self.clone_from_slice(&source); + self.clone_from_slice(source); } else { *self = source.clone(); } diff --git a/library/alloc/src/collections/btree/map.rs b/library/alloc/src/collections/btree/map.rs index 0a1f7738632c1..d8421d3c3f70a 100644 --- a/library/alloc/src/collections/btree/map.rs +++ b/library/alloc/src/collections/btree/map.rs @@ -1572,7 +1572,7 @@ impl BTreeMap { let right_root = left_root.split_off(key, (*self.alloc).clone()); - let (new_left_len, right_len) = Root::calc_split_length(total_num, &left_root, &right_root); + let (new_left_len, right_len) = Root::calc_split_length(total_num, left_root, &right_root); self.length = new_left_len; BTreeMap { @@ -2208,8 +2208,8 @@ impl<'a, K, V, R> ExtractIfInner<'a, K, V, R> { // On creation, we navigated directly to the left bound, so we need only check the // right bound here to decide whether to stop. match self.range.end_bound() { - Bound::Included(ref end) if (*k).le(end) => (), - Bound::Excluded(ref end) if (*k).lt(end) => (), + Bound::Included(end) if (*k).le(end) => (), + Bound::Excluded(end) if (*k).lt(end) => (), Bound::Unbounded => (), _ => return None, } diff --git a/library/alloc/src/collections/btree/node.rs b/library/alloc/src/collections/btree/node.rs index 84dd4b7e49def..0c7afcc63b9b7 100644 --- a/library/alloc/src/collections/btree/node.rs +++ b/library/alloc/src/collections/btree/node.rs @@ -1430,7 +1430,7 @@ impl<'a, K: 'a, V: 'a> BalancingContext<'a, K, V> { left_node.val_area_mut(old_left_len + 1..new_left_len), ); - slice_remove(&mut parent_node.edge_area_mut(..old_parent_len + 1), parent_idx + 1); + slice_remove(parent_node.edge_area_mut(..old_parent_len + 1), parent_idx + 1); parent_node.correct_childrens_parent_links(parent_idx + 1..old_parent_len); *parent_node.len_mut() -= 1; diff --git a/library/alloc/src/collections/btree/set.rs b/library/alloc/src/collections/btree/set.rs index 2a483b3d3982e..d06daa7c6c1b7 100644 --- a/library/alloc/src/collections/btree/set.rs +++ b/library/alloc/src/collections/btree/set.rs @@ -1971,7 +1971,7 @@ impl<'a, T: Ord, A: Allocator + Clone> Iterator for Difference<'a, T, A> { } DifferenceInner::Search { self_iter, other_set } => loop { let self_next = self_iter.next()?; - if !other_set.contains(&self_next) { + if !other_set.contains(self_next) { return Some(self_next); } }, @@ -2068,7 +2068,7 @@ impl<'a, T: Ord, A: Allocator + Clone> Iterator for Intersection<'a, T, A> { } IntersectionInner::Search { small_iter, large_set } => loop { let small_next = small_iter.next()?; - if large_set.contains(&small_next) { + if large_set.contains(small_next) { return Some(small_next); } }, diff --git a/library/alloc/src/io/impls.rs b/library/alloc/src/io/impls.rs index a6c9428ba62dc..dae6b3aa3371d 100644 --- a/library/alloc/src/io/impls.rs +++ b/library/alloc/src/io/impls.rs @@ -625,7 +625,7 @@ where #[inline] fn is_read_vectored(&self) -> bool { - (&**self).is_read_vectored() + (**self).is_read_vectored() } #[inline] @@ -667,7 +667,7 @@ where #[inline] fn is_write_vectored(&self) -> bool { - (&**self).is_write_vectored() + (**self).is_write_vectored() } #[inline] diff --git a/library/alloc/src/vec/splice.rs b/library/alloc/src/vec/splice.rs index 99ebcb4ada296..6436afd1ba12f 100644 --- a/library/alloc/src/vec/splice.rs +++ b/library/alloc/src/vec/splice.rs @@ -59,7 +59,7 @@ impl Drop for Splice<'_, I, A> { // Which means we can replace the slice::Iter with pointers that won't point to deallocated // memory, so that Drain::drop is still allowed to call iter.len(), otherwise it would break // the ptr.offset_from_unsigned contract. - self.drain.iter = (&[]).iter(); + self.drain.iter = [].iter(); unsafe { if self.drain.tail_len == 0 { diff --git a/library/alloc/src/wtf8/mod.rs b/library/alloc/src/wtf8/mod.rs index 394c41bf36727..36ec32c549763 100644 --- a/library/alloc/src/wtf8/mod.rs +++ b/library/alloc/src/wtf8/mod.rs @@ -284,7 +284,7 @@ impl Wtf8Buf { /// like concatenating ill-formed UTF-16 strings effectively would. #[inline] pub fn push_wtf8(&mut self, other: &Wtf8) { - match ((&*self).final_lead_surrogate(), other.initial_trail_surrogate()) { + match ((*self).final_lead_surrogate(), other.initial_trail_surrogate()) { // Replace newly paired surrogates by a supplementary code point. (Some(lead), Some(trail)) => { let len_without_lead_surrogate = self.len() - 3; @@ -322,7 +322,7 @@ impl Wtf8Buf { #[inline] pub fn push(&mut self, code_point: CodePoint) { if let Some(trail) = code_point.to_trail_surrogate() { - if let Some(lead) = (&*self).final_lead_surrogate() { + if let Some(lead) = (*self).final_lead_surrogate() { let len_without_lead_surrogate = self.len() - 3; self.bytes.truncate(len_without_lead_surrogate); self.push_char(decode_surrogate_pair(lead, trail)); diff --git a/library/core/src/ffi/c_str.rs b/library/core/src/ffi/c_str.rs index d3318b0863e6e..ae25e09230faa 100644 --- a/library/core/src/ffi/c_str.rs +++ b/library/core/src/ffi/c_str.rs @@ -682,7 +682,7 @@ impl PartialEq<&Self> for CStr { impl PartialOrd for CStr { #[inline] fn partial_cmp(&self, other: &CStr) -> Option { - self.to_bytes().partial_cmp(&other.to_bytes()) + self.to_bytes().partial_cmp(other.to_bytes()) } } @@ -690,7 +690,7 @@ impl PartialOrd for CStr { impl Ord for CStr { #[inline] fn cmp(&self, other: &CStr) -> Ordering { - self.to_bytes().cmp(&other.to_bytes()) + self.to_bytes().cmp(other.to_bytes()) } } diff --git a/library/core/src/iter/traits/iterator.rs b/library/core/src/iter/traits/iterator.rs index 3867a44099f6d..e3fadd2363911 100644 --- a/library/core/src/iter/traits/iterator.rs +++ b/library/core/src/iter/traits/iterator.rs @@ -4082,7 +4082,7 @@ pub const trait Iterator { mut compare: impl FnMut(&T, &T) -> bool + 'a, ) -> impl FnMut(T) -> bool + 'a { move |curr| { - if !compare(&last, &curr) { + if !compare(last, &curr) { return false; } *last = curr; diff --git a/library/core/src/slice/ascii.rs b/library/core/src/slice/ascii.rs index bc99290a38dfc..2b6037b2ee53e 100644 --- a/library/core/src/slice/ascii.rs +++ b/library/core/src/slice/ascii.rs @@ -91,7 +91,7 @@ impl [u8] { let mut b = other; while let ([first_a, rest_a @ ..], [first_b, rest_b @ ..]) = (a, b) { - if first_a.eq_ignore_ascii_case(&first_b) { + if first_a.eq_ignore_ascii_case(first_b) { a = rest_a; b = rest_b; } else { diff --git a/library/core/src/slice/iter.rs b/library/core/src/slice/iter.rs index 6f75808015e71..a054c9d742c88 100644 --- a/library/core/src/slice/iter.rs +++ b/library/core/src/slice/iter.rs @@ -424,7 +424,7 @@ impl<'a, T: 'a, P: FnMut(&T) -> bool> Split<'a, T, P> { /// ``` #[unstable(feature = "split_as_slice", issue = "96137")] pub fn as_slice(&self) -> &'a [T] { - if self.finished { &[] } else { &self.v } + if self.finished { &[] } else { self.v } } } diff --git a/library/core/src/str/iter.rs b/library/core/src/str/iter.rs index 70d9c7aef2a74..26c48d48d211e 100644 --- a/library/core/src/str/iter.rs +++ b/library/core/src/str/iter.rs @@ -1410,7 +1410,7 @@ impl<'a> SplitAsciiWhitespace<'a> { } // SAFETY: Slice is created from str. - Some(unsafe { crate::str::from_utf8_unchecked(&self.inner.iter.iter.v) }) + Some(unsafe { crate::str::from_utf8_unchecked(self.inner.iter.iter.v) }) } } diff --git a/library/core/src/task/wake.rs b/library/core/src/task/wake.rs index 63b7691582a7d..473b185d24652 100644 --- a/library/core/src/task/wake.rs +++ b/library/core/src/task/wake.rs @@ -245,14 +245,14 @@ impl<'a> Context<'a> { #[stable(feature = "futures_api", since = "1.36.0")] #[rustc_const_stable(feature = "const_waker", since = "1.82.0")] pub const fn waker(&self) -> &'a Waker { - &self.waker + self.waker } /// Returns a reference to the [`LocalWaker`] for the current task. #[inline] #[unstable(feature = "local_waker", issue = "118959")] pub const fn local_waker(&self) -> &'a LocalWaker { - &self.local_waker + self.local_waker } /// Returns a reference to the extension data for the current task. diff --git a/library/std/src/ffi/os_str.rs b/library/std/src/ffi/os_str.rs index 73fb3f54097fa..937bf0f119d3d 100644 --- a/library/std/src/ffi/os_str.rs +++ b/library/std/src/ffi/os_str.rs @@ -762,7 +762,7 @@ impl Eq for OsString {} impl PartialOrd for OsString { #[inline] fn partial_cmp(&self, other: &OsString) -> Option { - (&**self).partial_cmp(&**other) + (**self).partial_cmp(&**other) } #[inline] fn lt(&self, other: &OsString) -> bool { @@ -786,7 +786,7 @@ impl PartialOrd for OsString { impl PartialOrd for OsString { #[inline] fn partial_cmp(&self, other: &str) -> Option { - (&**self).partial_cmp(other) + (**self).partial_cmp(other) } } @@ -794,7 +794,7 @@ impl PartialOrd for OsString { impl Ord for OsString { #[inline] fn cmp(&self, other: &OsString) -> cmp::Ordering { - (&**self).cmp(&**other) + (**self).cmp(&**other) } } @@ -802,7 +802,7 @@ impl Ord for OsString { impl Hash for OsString { #[inline] fn hash(&self, state: &mut H) { - (&**self).hash(state) + (**self).hash(state) } } @@ -1777,7 +1777,7 @@ impl AsRef for str { impl AsRef for String { #[inline] fn as_ref(&self) -> &OsStr { - (&**self).as_ref() + (**self).as_ref() } } diff --git a/library/std/src/net/socket_addr.rs b/library/std/src/net/socket_addr.rs index 2dab8c26f1f6b..6aa625d66a363 100644 --- a/library/std/src/net/socket_addr.rs +++ b/library/std/src/net/socket_addr.rs @@ -257,6 +257,6 @@ impl ToSocketAddrs for &T { impl ToSocketAddrs for String { type Iter = vec::IntoIter; fn to_socket_addrs(&self) -> io::Result> { - (&**self).to_socket_addrs() + (**self).to_socket_addrs() } } diff --git a/library/std/src/os/unix/net/ancillary.rs b/library/std/src/os/unix/net/ancillary.rs index a9029f7fa0bfb..5d2cbd403ad20 100644 --- a/library/std/src/os/unix/net/ancillary.rs +++ b/library/std/src/os/unix/net/ancillary.rs @@ -744,7 +744,7 @@ impl<'a> SocketAncillary<'a> { pub fn add_fds(&mut self, fds: &[RawFd]) -> bool { self.truncated = false; add_to_ancillary_data( - &mut self.buffer, + self.buffer, &mut self.length, fds, libc::SOL_SOCKET, @@ -771,7 +771,7 @@ impl<'a> SocketAncillary<'a> { pub fn add_creds(&mut self, creds: &[SocketCred]) -> bool { self.truncated = false; add_to_ancillary_data( - &mut self.buffer, + self.buffer, &mut self.length, creds, libc::SOL_SOCKET, diff --git a/library/std/src/path.rs b/library/std/src/path.rs index be216d87f3241..8b41a3792ac9a 100644 --- a/library/std/src/path.rs +++ b/library/std/src/path.rs @@ -2673,7 +2673,7 @@ impl Path { #[stable(feature = "path_ancestors", since = "1.28.0")] #[inline] pub fn ancestors(&self) -> Ancestors<'_> { - Ancestors { next: Some(&self) } + Ancestors { next: Some(self) } } /// Returns the final component of the `Path`, if there is one. diff --git a/library/std/src/sync/nonpoison/rwlock.rs b/library/std/src/sync/nonpoison/rwlock.rs index dc5d9479ba5a9..19064fdd1ce10 100644 --- a/library/std/src/sync/nonpoison/rwlock.rs +++ b/library/std/src/sync/nonpoison/rwlock.rs @@ -636,7 +636,7 @@ impl<'rwlock, T: ?Sized> RwLockReadGuard<'rwlock, T> { // reference passed to it. If the closure panics, the guard will be dropped. let data = NonNull::from(f(unsafe { orig.data.as_ref() })); let orig = ManuallyDrop::new(orig); - MappedRwLockReadGuard { data, inner_lock: &orig.inner_lock } + MappedRwLockReadGuard { data, inner_lock: orig.inner_lock } } /// Makes a [`MappedRwLockReadGuard`] for a component of the borrowed data. The @@ -668,7 +668,7 @@ impl<'rwlock, T: ?Sized> RwLockReadGuard<'rwlock, T> { Some(data) => { let data = NonNull::from(data); let orig = ManuallyDrop::new(orig); - Ok(MappedRwLockReadGuard { data, inner_lock: &orig.inner_lock }) + Ok(MappedRwLockReadGuard { data, inner_lock: orig.inner_lock }) } None => Err(orig), } @@ -861,7 +861,7 @@ impl<'rwlock, T: ?Sized> MappedRwLockReadGuard<'rwlock, T> { // reference passed to it. If the closure panics, the guard will be dropped. let data = NonNull::from(f(unsafe { orig.data.as_ref() })); let orig = ManuallyDrop::new(orig); - MappedRwLockReadGuard { data, inner_lock: &orig.inner_lock } + MappedRwLockReadGuard { data, inner_lock: orig.inner_lock } } /// Makes a [`MappedRwLockReadGuard`] for a component of the borrowed data. @@ -893,7 +893,7 @@ impl<'rwlock, T: ?Sized> MappedRwLockReadGuard<'rwlock, T> { Some(data) => { let data = NonNull::from(data); let orig = ManuallyDrop::new(orig); - Ok(MappedRwLockReadGuard { data, inner_lock: &orig.inner_lock }) + Ok(MappedRwLockReadGuard { data, inner_lock: orig.inner_lock }) } None => Err(orig), } diff --git a/library/std/src/sync/poison/rwlock.rs b/library/std/src/sync/poison/rwlock.rs index 4cfd9d19df74a..de1fedf88f63a 100644 --- a/library/std/src/sync/poison/rwlock.rs +++ b/library/std/src/sync/poison/rwlock.rs @@ -770,7 +770,7 @@ impl<'rwlock, T: ?Sized> RwLockReadGuard<'rwlock, T> { // reference passed to it. If the closure panics, the guard will be dropped. let data = NonNull::from(f(unsafe { orig.data.as_ref() })); let orig = ManuallyDrop::new(orig); - MappedRwLockReadGuard { data, inner_lock: &orig.inner_lock } + MappedRwLockReadGuard { data, inner_lock: orig.inner_lock } } /// Makes a [`MappedRwLockReadGuard`] for a component of the borrowed data. The @@ -802,7 +802,7 @@ impl<'rwlock, T: ?Sized> RwLockReadGuard<'rwlock, T> { Some(data) => { let data = NonNull::from(data); let orig = ManuallyDrop::new(orig); - Ok(MappedRwLockReadGuard { data, inner_lock: &orig.inner_lock }) + Ok(MappedRwLockReadGuard { data, inner_lock: orig.inner_lock }) } None => Err(orig), } @@ -996,7 +996,7 @@ impl<'rwlock, T: ?Sized> MappedRwLockReadGuard<'rwlock, T> { // reference passed to it. If the closure panics, the guard will be dropped. let data = NonNull::from(f(unsafe { orig.data.as_ref() })); let orig = ManuallyDrop::new(orig); - MappedRwLockReadGuard { data, inner_lock: &orig.inner_lock } + MappedRwLockReadGuard { data, inner_lock: orig.inner_lock } } /// Makes a [`MappedRwLockReadGuard`] for a component of the borrowed data. @@ -1028,7 +1028,7 @@ impl<'rwlock, T: ?Sized> MappedRwLockReadGuard<'rwlock, T> { Some(data) => { let data = NonNull::from(data); let orig = ManuallyDrop::new(orig); - Ok(MappedRwLockReadGuard { data, inner_lock: &orig.inner_lock }) + Ok(MappedRwLockReadGuard { data, inner_lock: orig.inner_lock }) } None => Err(orig), } diff --git a/library/std/src/sys/fs/common.rs b/library/std/src/sys/fs/common.rs index 68aed39d1dcdf..edc31d21ca1fa 100644 --- a/library/std/src/sys/fs/common.rs +++ b/library/std/src/sys/fs/common.rs @@ -72,7 +72,7 @@ impl Dir { } pub fn open_file(&self, path: &Path, opts: &OpenOptions) -> io::Result { - File::open(&self.path.join(path), &opts) + File::open(&self.path.join(path), opts) } pub fn metadata(&self) -> io::Result { diff --git a/library/std/src/sys/fs/unix.rs b/library/std/src/sys/fs/unix.rs index cdd1ef6146fd9..393a4d13b603b 100644 --- a/library/std/src/sys/fs/unix.rs +++ b/library/std/src/sys/fs/unix.rs @@ -2415,7 +2415,7 @@ mod remove_dir_impl { fn remove_dir_all_recursive(parent_fd: Option, path: &CStr) -> io::Result<()> { // try opening as directory - let fd = match openat_nofollow_dironly(parent_fd, &path) { + let fd = match openat_nofollow_dironly(parent_fd, path) { Err(err) if matches!(err.raw_os_error(), Some(libc::ENOTDIR | libc::ELOOP)) => { // not a directory - don't traverse further // (for symlinks, older Linux kernels may return ELOOP instead of ENOTDIR) @@ -2485,7 +2485,7 @@ mod remove_dir_impl { if attr.file_type().is_symlink() { super::unlink(p) } else { - remove_dir_all_recursive(None, &p) + remove_dir_all_recursive(None, p) } } diff --git a/library/std/src/sys/fs/unix/dir.rs b/library/std/src/sys/fs/unix/dir.rs index f3f612a225ed1..13a17350ff7b9 100644 --- a/library/std/src/sys/fs/unix/dir.rs +++ b/library/std/src/sys/fs/unix/dir.rs @@ -38,7 +38,7 @@ impl Dir { } pub fn open_file(&self, path: &Path, opts: &OpenOptions) -> io::Result { - run_path_with_cstr(path.as_ref(), &|path| self.open_file_c(path, &opts)) + run_path_with_cstr(path.as_ref(), &|path| self.open_file_c(path, opts)) } pub fn metadata(&self) -> io::Result { diff --git a/library/std/src/sys/fs/windows.rs b/library/std/src/sys/fs/windows.rs index ef76a038c1fb5..9023d1f1c8338 100644 --- a/library/std/src/sys/fs/windows.rs +++ b/library/std/src/sys/fs/windows.rs @@ -339,7 +339,7 @@ impl File { let path = maybe_verbatim(path)?; // SAFETY: maybe_verbatim returns null-terminated strings let path = unsafe { WCStr::from_wchars_with_null_unchecked(&path) }; - Self::open_native(&path, opts) + Self::open_native(path, opts) } fn open_native(path: &WCStr, opts: &OpenOptions) -> io::Result { @@ -1305,7 +1305,7 @@ pub fn unlink(path: &WCStr) -> io::Result<()> { let mut opts = OpenOptions::new(); opts.access_mode(c::DELETE); opts.custom_flags(c::FILE_FLAG_OPEN_REPARSE_POINT); - if let Ok(f) = File::open_native(&path, &opts) { + if let Ok(f) = File::open_native(path, &opts) { if f.posix_delete().is_ok() { return Ok(()); } @@ -1328,7 +1328,7 @@ pub fn rename(old: &WCStr, new: &WCStr) -> io::Result<()> { let mut opts = OpenOptions::new(); opts.access_mode(c::DELETE); opts.custom_flags(c::FILE_FLAG_OPEN_REPARSE_POINT | c::FILE_FLAG_BACKUP_SEMANTICS); - let Ok(f) = File::open_native(&old, &opts) else { return Err(err).io_result() }; + let Ok(f) = File::open_native(old, &opts) else { return Err(err).io_result() }; // Calculate the layout of the `FILE_RENAME_INFO` we pass to `SetFileInformation` // This is a dynamically sized struct so we need to get the position of the last field to calculate the actual size. @@ -1419,7 +1419,7 @@ pub fn readlink(path: &WCStr) -> io::Result { let mut opts = OpenOptions::new(); opts.access_mode(0); opts.custom_flags(c::FILE_FLAG_OPEN_REPARSE_POINT | c::FILE_FLAG_BACKUP_SEMANTICS); - let file = File::open_native(&path, &opts)?; + let file = File::open_native(path, &opts)?; file.readlink() } @@ -1506,7 +1506,7 @@ fn metadata(path: &WCStr, reparse: ReparsePoint) -> io::Result { // Attempt to open the file normally. // If that fails with `ERROR_SHARING_VIOLATION` then retry using `FindFirstFileExW`. // If the fallback fails for any reason we return the original error. - match File::open_native(&path, &opts) { + match File::open_native(path, &opts) { Ok(file) => file.file_attr(), Err(e) if [Some(c::ERROR_SHARING_VIOLATION as _), Some(c::ERROR_ACCESS_DENIED as _)] diff --git a/library/std/src/sys/process/unix/common.rs b/library/std/src/sys/process/unix/common.rs index 2e32770e90e77..a67c14b58faf1 100644 --- a/library/std/src/sys/process/unix/common.rs +++ b/library/std/src/sys/process/unix/common.rs @@ -218,7 +218,7 @@ impl Command { pub fn chroot(&mut self, dir: &Path) { self.chroot = Some(os2c(dir.as_os_str(), &mut self.saw_nul)); if self.cwd.is_none() { - self.cwd(&OsStr::new("/")); + self.cwd(OsStr::new("/")); } } pub fn setsid(&mut self, setsid: bool) { From ddd8fa08135bb6d006fcc7e3f2c5bd4be849c426 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Wed, 12 Aug 2026 14:16:16 +0000 Subject: [PATCH 5/9] clippy::op_ref --- library/core/src/bstr/traits.rs | 2 +- library/std/src/ffi/os_str.rs | 10 +++++----- library/std/src/sys/path/windows.rs | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/library/core/src/bstr/traits.rs b/library/core/src/bstr/traits.rs index bcfffd52d7419..1d8d0e29e9a5a 100644 --- a/library/core/src/bstr/traits.rs +++ b/library/core/src/bstr/traits.rs @@ -25,7 +25,7 @@ impl PartialOrd for ByteStr { impl PartialEq for ByteStr { #[inline] fn eq(&self, other: &ByteStr) -> bool { - &self.0 == &other.0 + self.0 == other.0 } } diff --git a/library/std/src/ffi/os_str.rs b/library/std/src/ffi/os_str.rs index 937bf0f119d3d..27039f0d3d2eb 100644 --- a/library/std/src/ffi/os_str.rs +++ b/library/std/src/ffi/os_str.rs @@ -719,7 +719,7 @@ impl fmt::Debug for OsString { impl PartialEq for OsString { #[inline] fn eq(&self, other: &OsString) -> bool { - &**self == &**other + **self == **other } } @@ -766,19 +766,19 @@ impl PartialOrd for OsString { } #[inline] fn lt(&self, other: &OsString) -> bool { - &**self < &**other + **self < **other } #[inline] fn le(&self, other: &OsString) -> bool { - &**self <= &**other + **self <= **other } #[inline] fn gt(&self, other: &OsString) -> bool { - &**self > &**other + **self > **other } #[inline] fn ge(&self, other: &OsString) -> bool { - &**self >= &**other + **self >= **other } } diff --git a/library/std/src/sys/path/windows.rs b/library/std/src/sys/path/windows.rs index 1c7bf50d1907f..2dbe33e2cf8b0 100644 --- a/library/std/src/sys/path/windows.rs +++ b/library/std/src/sys/path/windows.rs @@ -251,6 +251,6 @@ pub(crate) fn is_absolute_exact(path: &[u16]) -> bool { unsafe { new_path.set_len((result as usize) + 1); } - path == &new_path + path == new_path } } From fafcb2be486f2c24bbeb8417e5d32335df5d9a34 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Thu, 13 Aug 2026 01:51:53 +0000 Subject: [PATCH 6/9] clippy::borrow_deref_ref --- library/core/src/cell.rs | 2 +- library/core/src/fmt/mod.rs | 2 +- library/core/src/mem/maybe_uninit.rs | 2 +- library/core/src/pin.rs | 2 +- library/std/src/fs.rs | 4 ++-- library/std/src/io/stdio.rs | 4 ++-- library/std/src/os/unix/net/stream.rs | 4 ++-- library/std/src/process.rs | 2 +- 8 files changed, 11 insertions(+), 11 deletions(-) diff --git a/library/core/src/cell.rs b/library/core/src/cell.rs index 2dc2c5981cafd..e8cd3a500084a 100644 --- a/library/core/src/cell.rs +++ b/library/core/src/cell.rs @@ -704,7 +704,7 @@ impl AsRef<[Cell; N]> for Cell<[T; N]> { impl AsRef<[Cell]> for Cell<[T; N]> { #[inline] fn as_ref(&self) -> &[Cell] { - &*self.as_array_of_cells() + self.as_array_of_cells() } } diff --git a/library/core/src/fmt/mod.rs b/library/core/src/fmt/mod.rs index 47886aa7165d9..6a4c58afc16f3 100644 --- a/library/core/src/fmt/mod.rs +++ b/library/core/src/fmt/mod.rs @@ -3189,7 +3189,7 @@ impl Debug for Ref<'_, T> { #[stable(feature = "rust1", since = "1.0.0")] impl Debug for RefMut<'_, T> { fn fmt(&self, f: &mut Formatter<'_>) -> Result { - Debug::fmt(&*(self.deref()), f) + Debug::fmt(self.deref(), f) } } diff --git a/library/core/src/mem/maybe_uninit.rs b/library/core/src/mem/maybe_uninit.rs index 6275d7cd59a2c..94703940baa1f 100644 --- a/library/core/src/mem/maybe_uninit.rs +++ b/library/core/src/mem/maybe_uninit.rs @@ -1639,7 +1639,7 @@ impl AsRef<[MaybeUninit; N]> for MaybeUninit<[T; N]> { impl AsRef<[MaybeUninit]> for MaybeUninit<[T; N]> { #[inline] fn as_ref(&self) -> &[MaybeUninit] { - &*AsRef::<[MaybeUninit; N]>::as_ref(self) + AsRef::<[MaybeUninit; N]>::as_ref(self) } } diff --git a/library/core/src/pin.rs b/library/core/src/pin.rs index 52a84082f3b92..58e63ff04af15 100644 --- a/library/core/src/pin.rs +++ b/library/core/src/pin.rs @@ -1540,7 +1540,7 @@ impl<'a, T: ?Sized> Pin<&'a T> { U: ?Sized, F: FnOnce(&T) -> &U, { - let pointer = &*self.pointer; + let pointer = self.pointer; let new_pointer = func(pointer); // SAFETY: the safety contract for `new_unchecked` must be diff --git a/library/std/src/fs.rs b/library/std/src/fs.rs index 58874a27f8ae5..61e62e2064952 100644 --- a/library/std/src/fs.rs +++ b/library/std/src/fs.rs @@ -1497,7 +1497,7 @@ impl Read for File { } #[inline] fn is_read_vectored(&self) -> bool { - (&&*self).is_read_vectored() + (&self).is_read_vectored() } fn read_to_end(&mut self, buf: &mut Vec) -> io::Result { (&*self).read_to_end(buf) @@ -1516,7 +1516,7 @@ impl Write for File { } #[inline] fn is_write_vectored(&self) -> bool { - (&&*self).is_write_vectored() + (&self).is_write_vectored() } #[inline] fn flush(&mut self) -> io::Result<()> { diff --git a/library/std/src/io/stdio.rs b/library/std/src/io/stdio.rs index 957235f9f3fb0..b104ea69cd1fc 100644 --- a/library/std/src/io/stdio.rs +++ b/library/std/src/io/stdio.rs @@ -796,7 +796,7 @@ impl Write for Stdout { } #[inline] fn is_write_vectored(&self) -> bool { - io::Write::is_write_vectored(&&*self) + io::Write::is_write_vectored(&self) } fn flush(&mut self) -> io::Result<()> { (&*self).flush() @@ -1028,7 +1028,7 @@ impl Write for Stderr { } #[inline] fn is_write_vectored(&self) -> bool { - io::Write::is_write_vectored(&&*self) + io::Write::is_write_vectored(&self) } fn flush(&mut self) -> io::Result<()> { (&*self).flush() diff --git a/library/std/src/os/unix/net/stream.rs b/library/std/src/os/unix/net/stream.rs index 8567e2fbb783d..9a17f9e0b8b9b 100644 --- a/library/std/src/os/unix/net/stream.rs +++ b/library/std/src/os/unix/net/stream.rs @@ -642,7 +642,7 @@ impl io::Read for UnixStream { #[inline] fn is_read_vectored(&self) -> bool { - io::Read::is_read_vectored(&&*self) + io::Read::is_read_vectored(&self) } } @@ -678,7 +678,7 @@ impl io::Write for UnixStream { #[inline] fn is_write_vectored(&self) -> bool { - io::Write::is_write_vectored(&&*self) + io::Write::is_write_vectored(&self) } fn flush(&mut self) -> io::Result<()> { diff --git a/library/std/src/process.rs b/library/std/src/process.rs index a398363cf4bf9..59480aa79fe9e 100644 --- a/library/std/src/process.rs +++ b/library/std/src/process.rs @@ -333,7 +333,7 @@ impl Write for ChildStdin { } fn is_write_vectored(&self) -> bool { - io::Write::is_write_vectored(&&*self) + io::Write::is_write_vectored(&self) } #[inline] From d9d6acfad73e941bcf08fbbb278e3c77903f6c31 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Thu, 13 Aug 2026 02:01:47 +0000 Subject: [PATCH 7/9] clippy::explicit_auto_deref --- library/alloc/src/borrow.rs | 2 +- library/alloc/src/boxed.rs | 12 ++++++------ library/alloc/src/io/impls.rs | 4 ++-- library/alloc/src/rc.rs | 12 ++++++------ library/alloc/src/sync.rs | 14 +++++++------- library/alloc/src/vec/mod.rs | 2 +- library/core/src/clone.rs | 2 +- library/core/src/mem/drop_guard.rs | 4 ++-- library/core/src/str/pattern.rs | 2 +- library/std/src/os/unix/net/ancillary.rs | 8 ++++---- library/std/src/sync/lazy_lock.rs | 2 +- 11 files changed, 32 insertions(+), 32 deletions(-) diff --git a/library/alloc/src/borrow.rs b/library/alloc/src/borrow.rs index d1c7cd47da0f0..b6a7a1eae2a70 100644 --- a/library/alloc/src/borrow.rs +++ b/library/alloc/src/borrow.rs @@ -188,7 +188,7 @@ impl<'a, B: ?Sized + ToOwned> Borrow for Cow<'a, B> // B::Owned: [const] Borrow, { fn borrow(&self) -> &B { - &**self + self } } diff --git a/library/alloc/src/boxed.rs b/library/alloc/src/boxed.rs index c25a06968e293..8c790d1105050 100644 --- a/library/alloc/src/boxed.rs +++ b/library/alloc/src/boxed.rs @@ -2293,14 +2293,14 @@ impl Deref for Box { type Target = T; fn deref(&self) -> &T { - &**self + self } } #[stable(feature = "rust1", since = "1.0.0")] impl DerefMut for Box { fn deref_mut(&mut self) -> &mut T { - &mut **self + self } } @@ -2396,28 +2396,28 @@ impl, U: ?Sized> DispatchFromDyn> for Box Borrow for Box { fn borrow(&self) -> &T { - &**self + self } } #[stable(feature = "box_borrow", since = "1.1.0")] impl BorrowMut for Box { fn borrow_mut(&mut self) -> &mut T { - &mut **self + self } } #[stable(since = "1.5.0", feature = "smart_ptr_as_ref")] impl AsRef for Box { fn as_ref(&self) -> &T { - &**self + self } } #[stable(since = "1.5.0", feature = "smart_ptr_as_ref")] impl AsMut for Box { fn as_mut(&mut self) -> &mut T { - &mut **self + self } } diff --git a/library/alloc/src/io/impls.rs b/library/alloc/src/io/impls.rs index dae6b3aa3371d..0296cada74171 100644 --- a/library/alloc/src/io/impls.rs +++ b/library/alloc/src/io/impls.rs @@ -327,7 +327,7 @@ impl Read for &[u8] { fn read_buf_exact(&mut self, mut cursor: BorrowedCursor<'_, u8>) -> io::Result<()> { if cursor.capacity() > self.len() { // Append everything we can to the cursor. - cursor.append(*self); + cursor.append(self); *self = &self[self.len()..]; return Err(io::Error::READ_EXACT_EOF); } @@ -349,7 +349,7 @@ impl Read for &[u8] { buf.try_extend_from_slice_of_bytes(*self)?; } _ => { - buf.extend_from_slice(*self); + buf.extend_from_slice(self); } } diff --git a/library/alloc/src/rc.rs b/library/alloc/src/rc.rs index 38ba8d64f900e..73dabb3b02b60 100644 --- a/library/alloc/src/rc.rs +++ b/library/alloc/src/rc.rs @@ -3858,14 +3858,14 @@ impl<'a> RcInnerPtr for WeakInner<'a> { #[stable(feature = "rust1", since = "1.0.0")] impl borrow::Borrow for Rc { fn borrow(&self) -> &T { - &**self + self } } #[stable(since = "1.5.0", feature = "smart_ptr_as_ref")] impl AsRef for Rc { fn as_ref(&self) -> &T { - &**self + self } } @@ -3990,28 +3990,28 @@ impl fmt::Pointer for UniqueRc { #[unstable(feature = "unique_rc_arc", issue = "112566")] impl borrow::Borrow for UniqueRc { fn borrow(&self) -> &T { - &**self + self } } #[unstable(feature = "unique_rc_arc", issue = "112566")] impl borrow::BorrowMut for UniqueRc { fn borrow_mut(&mut self) -> &mut T { - &mut **self + self } } #[unstable(feature = "unique_rc_arc", issue = "112566")] impl AsRef for UniqueRc { fn as_ref(&self) -> &T { - &**self + self } } #[unstable(feature = "unique_rc_arc", issue = "112566")] impl AsMut for UniqueRc { fn as_mut(&mut self) -> &mut T { - &mut **self + self } } diff --git a/library/alloc/src/sync.rs b/library/alloc/src/sync.rs index 5e1344c0994cb..a3356b423288f 100644 --- a/library/alloc/src/sync.rs +++ b/library/alloc/src/sync.rs @@ -3836,7 +3836,7 @@ impl Default for Arc { #[inline] fn default() -> Self { let arc: Arc<[u8]> = Default::default(); - debug_assert!(core::str::from_utf8(&*arc).is_ok()); + debug_assert!(core::str::from_utf8(&arc).is_ok()); let (ptr, alloc) = Arc::into_inner_with_allocator(arc); unsafe { Arc::from_ptr_in(ptr.as_ptr() as *mut ArcInner, alloc) } } @@ -4246,14 +4246,14 @@ impl> ToArcSlice for I { #[stable(feature = "rust1", since = "1.0.0")] impl borrow::Borrow for Arc { fn borrow(&self) -> &T { - &**self + self } } #[stable(since = "1.5.0", feature = "smart_ptr_as_ref")] impl AsRef for Arc { fn as_ref(&self) -> &T { - &**self + self } } @@ -4463,28 +4463,28 @@ impl fmt::Pointer for UniqueArc { #[unstable(feature = "unique_rc_arc", issue = "112566")] impl borrow::Borrow for UniqueArc { fn borrow(&self) -> &T { - &**self + self } } #[unstable(feature = "unique_rc_arc", issue = "112566")] impl borrow::BorrowMut for UniqueArc { fn borrow_mut(&mut self) -> &mut T { - &mut **self + self } } #[unstable(feature = "unique_rc_arc", issue = "112566")] impl AsRef for UniqueArc { fn as_ref(&self) -> &T { - &**self + self } } #[unstable(feature = "unique_rc_arc", issue = "112566")] impl AsMut for UniqueArc { fn as_mut(&mut self) -> &mut T { - &mut **self + self } } diff --git a/library/alloc/src/vec/mod.rs b/library/alloc/src/vec/mod.rs index a619aa6e5427b..898ed0378bb80 100644 --- a/library/alloc/src/vec/mod.rs +++ b/library/alloc/src/vec/mod.rs @@ -3875,7 +3875,7 @@ impl Clone for Vec { /// capacity of the original. fn clone(&self) -> Self { let alloc = self.allocator().clone(); - <[T]>::to_vec_in(&**self, alloc) + <[T]>::to_vec_in(self, alloc) } /// Overwrites the contents of `self` with a clone of the contents of `source`. diff --git a/library/core/src/clone.rs b/library/core/src/clone.rs index 2996c753faea4..f124b8bceaded 100644 --- a/library/core/src/clone.rs +++ b/library/core/src/clone.rs @@ -781,7 +781,7 @@ mod impls { #[inline(always)] #[rustc_diagnostic_item = "noop_method_clone"] fn clone(&self) -> Self { - *self + self } } diff --git a/library/core/src/mem/drop_guard.rs b/library/core/src/mem/drop_guard.rs index 70658f0efb242..8e6655f785466 100644 --- a/library/core/src/mem/drop_guard.rs +++ b/library/core/src/mem/drop_guard.rs @@ -116,7 +116,7 @@ where type Target = T; fn deref(&self) -> &T { - &*self.inner + &self.inner } } @@ -127,7 +127,7 @@ where F: FnOnce(T), { fn deref_mut(&mut self) -> &mut T { - &mut *self.inner + &mut self.inner } } diff --git a/library/core/src/str/pattern.rs b/library/core/src/str/pattern.rs index 38006b638fdcd..e157ab588e701 100644 --- a/library/core/src/str/pattern.rs +++ b/library/core/src/str/pattern.rs @@ -1051,7 +1051,7 @@ impl<'b> Pattern for &'b str { #[inline] fn as_utf8_pattern(&self) -> Option> { - Some(Utf8Pattern::StringPattern(*self)) + Some(Utf8Pattern::StringPattern(self)) } } diff --git a/library/std/src/os/unix/net/ancillary.rs b/library/std/src/os/unix/net/ancillary.rs index 5d2cbd403ad20..bdf0384e34f80 100644 --- a/library/std/src/os/unix/net/ancillary.rs +++ b/library/std/src/os/unix/net/ancillary.rs @@ -506,12 +506,12 @@ impl<'a> AncillaryData<'a> { fn try_from_cmsghdr(cmsg: &'a libc::cmsghdr) -> Result { unsafe { let cmsg_len_zero = libc::CMSG_LEN(0) as usize; - let data_len = (*cmsg).cmsg_len as usize - cmsg_len_zero; + let data_len = cmsg.cmsg_len as usize - cmsg_len_zero; let data = libc::CMSG_DATA(cmsg).cast(); let data = from_raw_parts(data, data_len); - match (*cmsg).cmsg_level { - libc::SOL_SOCKET => match (*cmsg).cmsg_type { + match cmsg.cmsg_level { + libc::SOL_SOCKET => match cmsg.cmsg_type { libc::SCM_RIGHTS => Ok(AncillaryData::as_rights(data)), #[cfg(any(target_os = "android", target_os = "linux", target_os = "cygwin"))] libc::SCM_CREDENTIALS => Ok(AncillaryData::as_credentials(data)), @@ -524,7 +524,7 @@ impl<'a> AncillaryData<'a> { } }, cmsg_level => { - Err(AncillaryError::Unknown { cmsg_level, cmsg_type: (*cmsg).cmsg_type }) + Err(AncillaryError::Unknown { cmsg_level, cmsg_type: cmsg.cmsg_type }) } } } diff --git a/library/std/src/sync/lazy_lock.rs b/library/std/src/sync/lazy_lock.rs index 9bb25287275b2..f150d42a3137c 100644 --- a/library/std/src/sync/lazy_lock.rs +++ b/library/std/src/sync/lazy_lock.rs @@ -258,7 +258,7 @@ impl T> LazyLock { // * the closure was not called, but a previous call initialized `value`. // * the closure was not called because the Once is poisoned, which we handled above. // So `value` has definitely been initialized and will not be modified again. - unsafe { &*(*this.data.get()).value } + unsafe { &(*this.data.get()).value } } } From 5653e8f78d16dfe364de15d217d535c90bb3c4f5 Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Thu, 13 Aug 2026 02:22:22 +0000 Subject: [PATCH 8/9] Library: enforce clippy deref lints in CI --- src/bootstrap/src/core/build_steps/clippy.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/bootstrap/src/core/build_steps/clippy.rs b/src/bootstrap/src/core/build_steps/clippy.rs index 6f6c76d23a454..95a850e3984f2 100644 --- a/src/bootstrap/src/core/build_steps/clippy.rs +++ b/src/bootstrap/src/core/build_steps/clippy.rs @@ -588,6 +588,10 @@ impl CommandLineStep for CI { "clippy::ptr_offset_with_cast".into(), "clippy::let_and_return".into(), "clippy::needless_return".into(), + "clippy::needless_borrow".into(), + "clippy::op_ref".into(), + "clippy::borrow_deref_ref".into(), + "clippy::explicit_auto_deref".into(), ], forbid: vec![], }; From 7f74e595a84d917c0b8bcbf8e6ed64fac4c3ef4d Mon Sep 17 00:00:00 2001 From: Chris Denton Date: Thu, 13 Aug 2026 03:22:53 +0000 Subject: [PATCH 9/9] Ignore clippy lint in backtrace submodule --- library/std/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/std/src/lib.rs b/library/std/src/lib.rs index 22ac7443f464b..d3bbb7c2353cd 100644 --- a/library/std/src/lib.rs +++ b/library/std/src/lib.rs @@ -740,7 +740,7 @@ mod panicking; #[path = "../../backtrace/src/lib.rs"] #[allow(dead_code, unused_attributes, implicit_provenance_casts, unsafe_op_in_unsafe_fn)] -#[allow(clippy::len_zero)] // FIXME +#[allow(clippy::len_zero, clippy::needless_borrow)] // FIXME mod backtrace_rs; #[stable(feature = "cfg_select", since = "1.95.0")]