Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions examples/cpp/method/example_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ pub mod foo {
/// Generated from: examples/cpp/method/example.h;l=14
#[inline(always)]
pub unsafe fn MyMethod(__this: *mut Self) {
self::bar::MyMethod(__this)
unsafe { self::bar::MyMethod(__this) }
}
}

Expand All @@ -62,7 +62,7 @@ pub mod foo {
/// Generated from: examples/cpp/method/example.h;l=14
#[inline(always)]
pub unsafe fn MyMethod(__this: *mut crate::foo::Bar) {
crate::detail::__rust_thunk___ZN3foo3Bar8MyMethodEv(__this)
unsafe { crate::detail::__rust_thunk___ZN3foo3Bar8MyMethodEv(__this) }
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions examples/cpp/unsafe_attributes/example_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pub fn SafeSignatureWithoutAnnotation() {
/// Generated from: examples/cpp/unsafe_attributes/example.h;l=11
#[inline(always)]
pub unsafe fn SafeSignatureButAnnotatedUnsafe() {
crate::detail::__rust_thunk___Z31SafeSignatureButAnnotatedUnsafev()
unsafe { crate::detail::__rust_thunk___Z31SafeSignatureButAnnotatedUnsafev() }
}

/// # Safety
Expand All @@ -38,7 +38,7 @@ pub unsafe fn SafeSignatureButAnnotatedUnsafe() {
/// Generated from: examples/cpp/unsafe_attributes/example.h;l=13
#[inline(always)]
pub unsafe fn UnsafeSignatureWithoutAnnotation(__param_0: *mut ::ffi_11::c_void) {
crate::detail::__rust_thunk___Z32UnsafeSignatureWithoutAnnotationPv(__param_0)
unsafe { crate::detail::__rust_thunk___Z32UnsafeSignatureWithoutAnnotationPv(__param_0) }
}

/// Generated from: examples/cpp/unsafe_attributes/example.h;l=14
Expand All @@ -64,7 +64,7 @@ pub fn SafeBasedOnBoolean() {
/// Generated from: examples/cpp/unsafe_attributes/example.h;l=17
#[inline(always)]
pub unsafe fn UnsafeBasedOnBoolean() {
crate::detail::__rust_thunk___Z20UnsafeBasedOnBooleanv()
unsafe { crate::detail::__rust_thunk___Z20UnsafeBasedOnBooleanv() }
}

// Generated from: nowhere/llvm/src/libcxx/include/__type_traits/integral_constant.h;l=21
Expand Down
14 changes: 8 additions & 6 deletions examples/cpp/virtual/example_generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ impl RustDerived {
/// Generated from: examples/cpp/virtual/example.h;l=16
#[inline(always)]
pub unsafe fn Method1(__this: *const Self) -> ::ffi_11::c_int {
self::rust_derived::Method1(__this)
unsafe { self::rust_derived::Method1(__this) }
}
/// # Safety
///
Expand All @@ -49,7 +49,7 @@ impl RustDerived {
/// Generated from: examples/cpp/virtual/example.h;l=18
#[inline(always)]
pub unsafe fn Upcast(__this: *mut Self) -> *mut ::base::ExampleBase {
self::rust_derived::Upcast(__this)
unsafe { self::rust_derived::Upcast(__this) }
}
}

Expand Down Expand Up @@ -84,7 +84,7 @@ impl<'__unelided> ::ctor::CtorNew<(::ctor::RvalueReference<'__unelided, Self>,)>
impl ::ctor::PinnedDrop for RustDerived {
#[inline(always)]
unsafe fn pinned_drop<'a>(self: ::core::pin::Pin<&'a mut Self>) {
crate::detail::__rust_thunk___ZN11RustDerivedD1Ev(self)
unsafe { crate::detail::__rust_thunk___ZN11RustDerivedD1Ev(self) }
}
}

Expand Down Expand Up @@ -128,7 +128,9 @@ impl ::ctor::CtorNew<(::definition::RustDerived,)> for RustDerived {
unsafe impl ::operator::Delete for crate::RustDerived {
#[inline(always)]
unsafe fn delete(p: *mut Self) {
crate::detail::__crubit_operator_delete__11RustDerived___2f_2fthird_5fparty_2fcrubit_2fexamples_2fcpp_2fvirtual_3aexample_5flib(p);
unsafe {
crate::detail::__crubit_operator_delete__11RustDerived___2f_2fthird_5fparty_2fcrubit_2fexamples_2fcpp_2fvirtual_3aexample_5flib(p);
}
}
}

Expand All @@ -141,7 +143,7 @@ pub mod rust_derived {
/// Generated from: examples/cpp/virtual/example.h;l=16
#[inline(always)]
pub unsafe fn Method1(__this: *const crate::RustDerived) -> ::ffi_11::c_int {
crate::detail::__rust_thunk___ZNK11RustDerived7Method1Ev(__this)
unsafe { crate::detail::__rust_thunk___ZNK11RustDerived7Method1Ev(__this) }
}
/// # Safety
///
Expand All @@ -151,7 +153,7 @@ pub mod rust_derived {
/// Generated from: examples/cpp/virtual/example.h;l=18
#[inline(always)]
pub unsafe fn Upcast(__this: *mut crate::RustDerived) -> *mut ::base::ExampleBase {
crate::detail::__rust_thunk___ZN11RustDerived6UpcastEv(__this)
unsafe { crate::detail::__rust_thunk___ZN11RustDerived6UpcastEv(__this) }
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@ pub fn generated_items_to_tokens<'db>(
quote! {
unsafe impl oops::Inherits<#base_name> for #derived_name {
unsafe fn upcast_ptr(derived: *const Self) -> *const #base_name {
#body
unsafe { #body }
}
}
__NEWLINE__
Expand All @@ -797,7 +797,7 @@ pub fn generated_items_to_tokens<'db>(
unsafe impl ::operator::Delete for #record_type {
#[inline(always)]
unsafe fn delete(p: *mut Self) {
#crate_root_path::detail::#thunk_ident(p);
unsafe { #crate_root_path::detail::#thunk_ident(p); }
}
}
__NEWLINE__
Expand Down Expand Up @@ -902,7 +902,7 @@ pub fn generated_items_to_tokens<'db>(
link_name.as_deref().map(|link_name| quote! { #[link_name = #link_name] });
let mut_kw = if *is_mut { Some(quote! { mut }) } else { None };
quote! {
extern "C" {
unsafe extern "C" {
#link_name_attr
#visibility static #mut_kw #ident: #type_tokens;
}
Expand Down
10 changes: 4 additions & 6 deletions rs_bindings_from_cc/generate_bindings/generate_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1194,11 +1194,9 @@ fn generate_func_body(
// return_type = RsTypeKind::Primitive(PrimitiveType::Unit);
let _ = return_type; // proof that we don't need to update it.
}
// Only need to wrap everything in an `unsafe { ... }` block if
// the *whole* api function is safe.
if !impl_kind.is_unsafe() {
body = quote! { unsafe { #body } };
}
// Rust 2024 requires that bodies of unsafe functions are not exempt from having unsafe
// blocks.
body = quote! { unsafe { #body } };
Ok(quote! {
#thunk_prepare
#body
Expand Down Expand Up @@ -1773,7 +1771,7 @@ pub fn generate_function(
fn #bracketed_func_name #fn_generic_params(
#( #api_params ),*
) #arrow #quoted_return_type #unsatisfied_where_clause {
self::#mod_name::#func_name(#( #method_delegation_args ),*)
unsafe { self::#mod_name::#func_name(#( #method_delegation_args ),*) }
}
}],
);
Expand Down
10 changes: 5 additions & 5 deletions rs_bindings_from_cc/generate_bindings/generate_function_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@ fn test_ptr_func() -> Result<()> {
quote! {
#[inline(always)]
pub unsafe fn Deref(p: *const *mut ::ffi_11::c_int) -> *mut ::ffi_11::c_int {
crate::detail::__rust_thunk___Z5DerefPKPi(p)
unsafe { crate::detail::__rust_thunk___Z5DerefPKPi(p) }
}
}
);
Expand Down Expand Up @@ -280,7 +280,7 @@ fn test_const_char_ptr_func() -> Result<()> {
quote! {
#[inline(always)]
pub unsafe fn f(str: *const ::ffi_11::c_schar) {
crate::detail::__rust_thunk___Z1fPKa(str)
unsafe { crate::detail::__rust_thunk___Z1fPKa(str) }
}
}
);
Expand Down Expand Up @@ -1714,7 +1714,7 @@ fn test_unpin_rvalue_ref_qualified_method() -> Result<()> {
quote! {
#[inline(always)]
pub fn rvalue_ref_qualified_method<'a>(self: ::ctor::RvalueReference<'a, Self>) {
self::trivial_with_rvalue_ref_qualified_method::rvalue_ref_qualified_method(self)
unsafe { self::trivial_with_rvalue_ref_qualified_method::rvalue_ref_qualified_method(self) }
}
}
);
Expand Down Expand Up @@ -1744,7 +1744,7 @@ fn test_unpin_rvalue_ref_const_qualified_method() -> Result<()> {
quote! {
#[inline(always)]
pub fn rvalue_ref_const_qualified_method<'a>(self: ::ctor::ConstRvalueReference<'a, Self>) {
self::trivial_with_rvalue_ref_const_qualified_method::rvalue_ref_const_qualified_method(self)
unsafe { self::trivial_with_rvalue_ref_const_qualified_method::rvalue_ref_const_qualified_method(self) }
}
}
);
Expand Down Expand Up @@ -1903,7 +1903,7 @@ fn test_function_returning_rvalue_reference() -> Result<()> {
#[inline(always)]
pub fn GetRValueReference<'a>(&'a mut self)
-> ::ctor::RvalueReference<'a, crate::SomeStruct> {
self::some_struct::GetRValueReference(self)
unsafe { self::some_struct::GetRValueReference(self) }
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ fn test_template_in_dependency_and_alias_in_current_target() -> Result<()> {
#[doc = " Generated from: test/dependency_header.h;l=5"]
#[inline(always)]
pub fn GetValue<'a>(self: ... Pin<&'a mut Self>) -> ::ffi_11::c_int {
self::cc_template_inst10_my_template_ii_e::GetValue(self)
unsafe { self::cc_template_inst10_my_template_ii_e::GetValue(self) }
}
}
}
Expand Down Expand Up @@ -1361,7 +1361,7 @@ fn test_unambiguous_public_bases() -> Result<()> {
quote! {
unsafe impl oops::Inherits<crate::VirtualBase> for crate::Derived {
unsafe fn upcast_ptr(derived: *const Self) -> *const crate::VirtualBase {
crate::detail::__crubit_dynamic_upcast__7Derived__to__11VirtualBase___2f_2ftest_3atesting_5ftarget(derived)
unsafe { crate::detail::__crubit_dynamic_upcast__7Derived__to__11VirtualBase___2f_2ftest_3atesting_5ftarget(derived) }
}
}
}
Expand Down Expand Up @@ -1638,7 +1638,7 @@ fn test_derived_class_inherits_unambiguous_public_functions_bases() -> Result<()
...
#[inline(always)]
pub unsafe fn NonColliding(__this: *mut Self) {
self::derived::NonColliding(__this)
unsafe { self::derived::NonColliding(__this) }
}
}
...
Expand Down Expand Up @@ -1674,7 +1674,7 @@ fn test_member_in_derived_class_overwrites_inherited_ones() -> Result<()> {
...
#[inline(always)]
pub unsafe fn Colliding(__this: *mut Self) {
self::derived::Colliding(__this)
unsafe { self::derived::Colliding(__this) }
}
}
...
Expand Down Expand Up @@ -1879,17 +1879,17 @@ fn test_multiple_member_functions_grouped_in_impl() -> Result<()> {
...
#[inline(always)]
pub fn Method1<'a>(&'a mut self) {
self::some_struct::Method1(self)
unsafe { self::some_struct::Method1(self) }
}
...
#[inline(always)]
pub fn Method2<'a>(&'a mut self) {
self::some_struct::Method2(self)
unsafe { self::some_struct::Method2(self) }
}
...
#[inline(always)]
pub fn Method3<'a>(&'a mut self) {
self::some_struct::Method3(self)
unsafe { self::some_struct::Method3(self) }
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions rs_bindings_from_cc/test/annotations/do_not_bind_rs_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ pub mod crubit {
__this: *mut Self,
mut __param_0: crate::crubit::test::ArgumentToBoundOverload,
) {
self::struct_with_do_not_bind_method::DoNotBindMethod(__this, __param_0)
unsafe { self::struct_with_do_not_bind_method::DoNotBindMethod(__this, __param_0) }
}
}

Expand Down Expand Up @@ -176,7 +176,9 @@ pub mod crubit {
__this: *mut crate::crubit::test::StructWithDoNotBindMethod,
mut __param_0: crate::crubit::test::ArgumentToBoundOverload,
) {
crate::detail::__rust_thunk___ZN6crubit4test25StructWithDoNotBindMethod15DoNotBindMethodENS0_23ArgumentToBoundOverloadE(__this,&mut __param_0)
unsafe {
crate::detail::__rust_thunk___ZN6crubit4test25StructWithDoNotBindMethod15DoNotBindMethodENS0_23ArgumentToBoundOverloadE(__this,&mut __param_0)
}
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions rs_bindings_from_cc/test/annotations/owned_ptr_rs_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl RawThing {
/// Generated from: rs_bindings_from_cc/test/annotations/owned_ptr.h;l=21
#[inline(always)]
pub unsafe fn Close(__this: *mut Self) {
self::raw_thing::Close(__this)
unsafe { self::raw_thing::Close(__this) }
}
}

Expand Down Expand Up @@ -95,7 +95,7 @@ pub mod raw_thing {
/// Generated from: rs_bindings_from_cc/test/annotations/owned_ptr.h;l=21
#[inline(always)]
pub unsafe fn Close(__this: *mut crate::RawThing) {
crate::detail::__rust_thunk___ZN5Thing5CloseEv(__this)
unsafe { crate::detail::__rust_thunk___ZN5Thing5CloseEv(__this) }
}
}

Expand Down
6 changes: 4 additions & 2 deletions rs_bindings_from_cc/test/annotations/owned_ptr_user_rs_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ pub fn MakeThing(value: ::ffi_11::c_int) -> *mut ::owned_ptr::RawThing {
/// Generated from: rs_bindings_from_cc/test/annotations/owned_ptr_user.h;l=18
#[inline(always)]
pub unsafe fn ThingToValue(thingptr: ::owned_ptr::OwnedThing) -> ::ffi_11::c_int {
crate::detail::__rust_thunk___Z12ThingToValueP5Thing(::core::mem::transmute(thingptr))
unsafe {
crate::detail::__rust_thunk___Z12ThingToValueP5Thing(::core::mem::transmute(thingptr))
}
}

/// # Safety
Expand All @@ -48,7 +50,7 @@ pub unsafe fn ThingToValue(thingptr: ::owned_ptr::OwnedThing) -> ::ffi_11::c_int
/// Generated from: rs_bindings_from_cc/test/annotations/owned_ptr_user.h;l=20
#[inline(always)]
pub unsafe fn GetThingValue(thingptr: *mut ::owned_ptr::RawThing) -> ::ffi_11::c_int {
crate::detail::__rust_thunk___Z13GetThingValueP5Thing(thingptr)
unsafe { crate::detail::__rust_thunk___Z13GetThingValueP5Thing(thingptr) }
}

// Generated from: nowhere/llvm/src/libcxx/include/__type_traits/integral_constant.h;l=21
Expand Down
10 changes: 7 additions & 3 deletions rs_bindings_from_cc/test/annotations/rust_name_rs_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ pub mod crubit {
b: ::ffi_11::c_int,
c: ::ffi_11::c_int,
) -> Self {
self::some_struct::ConstructorNewName(a, b, c)
unsafe { self::some_struct::ConstructorNewName(a, b, c) }
}
/// # Safety
///
Expand All @@ -84,7 +84,7 @@ pub mod crubit {
/// Expanded at: rs_bindings_from_cc/test/annotations/rust_name.h;l=21
#[inline(always)]
pub unsafe fn MethodNewName(__this: *const Self) {
self::some_struct::MethodNewName(__this)
unsafe { self::some_struct::MethodNewName(__this) }
}
}

Expand Down Expand Up @@ -131,7 +131,11 @@ pub mod crubit {
/// Expanded at: rs_bindings_from_cc/test/annotations/rust_name.h;l=21
#[inline(always)]
pub unsafe fn MethodNewName(__this: *const crate::crubit::test::SomeStruct) {
crate::detail::__rust_thunk___ZNK6crubit4test10SomeStruct13MethodOldNameEv(__this)
unsafe {
crate::detail::__rust_thunk___ZNK6crubit4test10SomeStruct13MethodOldNameEv(
__this,
)
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,12 +31,12 @@ impl S {
/// Generated from: rs_bindings_from_cc/test/assume_lifetimes/member_function.h;l=9
#[inline(always)]
pub fn int_accessor<'__this>(&'__this self) -> ::cref::CRef<'__this, ::ffi_11::c_int> {
self::s::int_accessor(self)
unsafe { self::s::int_accessor(self) }
}
/// Generated from: rs_bindings_from_cc/test/assume_lifetimes/member_function.h;l=10
#[inline(always)]
pub fn me<'__this>(&'__this mut self) -> ::cref::CMut<'__this, crate::S> {
self::s::me(self)
unsafe { self::s::me(self) }
}
}

Expand Down
Loading