Skip to content

Commit 8f7f000

Browse files
authored
Merge pull request #1463 from google/cppref-improvements-min2
CppRef<T> changes.
2 parents 35349e7 + 9940ead commit 8f7f000

File tree

7 files changed

+158
-154
lines changed

7 files changed

+158
-154
lines changed

Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ rust-version = "1.77"
2626
resolver = "2"
2727

2828
[features]
29-
arbitrary_self_types_pointers = []
29+
arbitrary_self_types = []
3030

3131
[dependencies]
3232
autocxx-macro = { path="macro", version="0.29.0" }

engine/src/conversion/codegen_rs/function_wrapper_rs.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,12 @@ impl TypeConversionPolicy {
172172
_ => panic!("Not a pointer"),
173173
};
174174
let (ty, wrapper_name) = if is_mut {
175-
(parse_quote! { autocxx::CppMutRef<'a, #ty> }, "CppMutRef")
175+
(
176+
parse_quote! { autocxx::CppMutLtRef<'a, #ty> },
177+
"CppMutLtRef",
178+
)
176179
} else {
177-
(parse_quote! { autocxx::CppRef<'a, #ty> }, "CppRef")
180+
(parse_quote! { autocxx::CppLtRef<'a, #ty> }, "CppLtRef")
178181
};
179182
let wrapper_name = make_ident(wrapper_name);
180183
RustParamConversion::Param {
@@ -194,9 +197,9 @@ impl TypeConversionPolicy {
194197
_ => panic!("Not a pointer"),
195198
};
196199
let ty = if is_mut {
197-
parse_quote! { &mut autocxx::CppMutRef<'a, #ty> }
200+
parse_quote! { autocxx::CppMutRef<#ty> }
198201
} else {
199-
parse_quote! { &autocxx::CppRef<'a, #ty> }
202+
parse_quote! { autocxx::CppRef<#ty> }
200203
};
201204
RustParamConversion::Param {
202205
ty,

examples/reference-wrappers/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
// Necessary to be able to call methods on reference wrappers.
2727
// For that reason, this example only builds on nightly Rust.
28-
#![feature(arbitrary_self_types_pointers)]
28+
#![feature(arbitrary_self_types)]
2929

3030
use autocxx::prelude::*;
3131
use std::pin::Pin;

integration-tests/tests/cpprefs_test.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn run_cpprefs_test(
2727
generate_pods: &[&str],
2828
) {
2929
if !arbitrary_self_types_supported() {
30-
// "unsafe_references_wrapped" requires arbitrary_self_types_pointers, which requires nightly.
30+
// "unsafe_references_wrapped" requires arbitrary_self_types, which requires nightly.
3131
return;
3232
}
3333
do_run_test(
@@ -127,7 +127,7 @@ fn test_return_reference_cpprefs() {
127127
let rs = quote! {
128128
let b = CppPin::new(ffi::Bob { a: 3, b: 4 });
129129
let b_ref = b.as_cpp_ref();
130-
let bob = ffi::give_bob(&b_ref);
130+
let bob = ffi::give_bob(b_ref);
131131
let val = unsafe { bob.as_ref() };
132132
assert_eq!(val.b, 4);
133133
};

src/lib.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#![doc = include_str!("../README.md")]
22
#![cfg_attr(nightly, feature(unsize))]
33
#![cfg_attr(nightly, feature(dispatch_from_dyn))]
4+
#![cfg_attr(nightly, feature(arbitrary_self_types))]
45

56
// Copyright 2020 Google LLC
67
//
@@ -21,7 +22,9 @@ mod rvalue_param;
2122
pub mod subclass;
2223
mod value_param;
2324

24-
pub use reference_wrapper::{AsCppMutRef, AsCppRef, CppMutRef, CppPin, CppRef, CppUniquePtrPin};
25+
pub use reference_wrapper::{
26+
AsCppMutRef, AsCppRef, CppLtRef, CppMutLtRef, CppMutRef, CppPin, CppRef, CppUniquePtrPin,
27+
};
2528

2629
#[cfg_attr(doc, aquamarine::aquamarine)]
2730
/// Include some C++ headers in your Rust project.
@@ -300,7 +303,7 @@ macro_rules! concrete {
300303
/// them to be wrapped in a `CppRef` type: see [`CppRef`].
301304
/// This only works on nightly Rust because it
302305
/// depends upon an unstable feature
303-
/// (`arbitrary_self_types_pointers`). However, it should
306+
/// (`arbitrary_self_types`). However, it should
304307
/// eliminate all undefined behavior related to Rust's
305308
/// stricter aliasing rules than C++.
306309
#[macro_export]
@@ -624,10 +627,7 @@ pub trait WithinBox {
624627
fn within_box(self) -> Pin<Box<Self::Inner>>;
625628
/// Create this item inside a [`CppPin`]. This is a good option if you
626629
/// want to own this option within Rust, but you want to create [`CppRef`]
627-
/// C++ references to it. You'd only want to choose that option if you have
628-
/// enabled the C++ reference wrapper support by using the
629-
/// `safety!(unsafe_references_wrapped`) directive. If you haven't done
630-
/// that, ignore this function.
630+
/// C++ references to it.
631631
fn within_cpp_pin(self) -> CppPin<Self::Inner>;
632632
}
633633

0 commit comments

Comments
 (0)