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
10 changes: 10 additions & 0 deletions common/error_report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,16 @@ pub enum Category {
///
/// As an example, the C++ items `struct Foo{ T* x};` and `void Foo(T* x);` are unsafe.
Unsafe = 1 << 9,

// TODO: Sync past cramertj@'s integer constant CL to get 1 << 10.
//
/// This item is a C++ function with a return type or at least one parameter type that is
/// non-Rust-movable and passed by value.
NonMovableByValue = 1 << 11,

/// This item is a C++ function with a return type or at least one parameter type that is
/// non-Rust-movable and passed by (potentially nested) pointer or reference.
NonMovableByRef = 1 << 12,
// TODO(b/468093766): Abstract? base classes, public inheritance
}

Expand Down
18 changes: 18 additions & 0 deletions rs_bindings_from_cc/generate_bindings/generate_function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1473,6 +1473,24 @@ pub fn generate_function(
let param_value_adjustments =
adjust_param_types_for_trait_impl(db, &impl_kind, &mut param_types, &errors);

// Categorize the Rust-movability of the return type and parameter types.
for mut ty in std::iter::once(&return_type).chain(param_types.iter()) {
// Note that pointers and references are Unpin, so this only fires for value types.
if !ty.is_unpin() {
db.errors().add_category(error_report::Category::NonMovableByValue);
}

// Traverse all the way through any pointers or references to the underlying value type.
let mut was_ref = false;
while let Some(referent) = ty.referent() {
ty = referent;
was_ref = true;
}
if was_ref && !ty.is_unpin() {
db.errors().add_category(error_report::Category::NonMovableByRef);
}
}

// TODO(b/454627672): Possibly amend the logic around lifetime binding here for
// assume_lifetimes.

Expand Down