Skip to content
Merged
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
8 changes: 4 additions & 4 deletions cc_bindings_from_rs/generate_bindings/format_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ pub fn format_ty_for_cc<'tcx>(
bail!("The never type `!` is only supported as a return type (b/254507801)");
}
},
ty::TyKind::Tuple(ref types) => {
ty::TyKind::Tuple(types) => {
if types.is_empty() && matches!(location, TypeLocation::FnReturn { .. }) {
keyword(quote! { void })
} else if !location.is_bridgeable() {
Expand All @@ -168,7 +168,7 @@ pub fn format_ty_for_cc<'tcx>(
prereqs.includes.insert(CcInclude::tuple());

let mut cc_types = Vec::with_capacity(types.len());
for element_type in *types {
for element_type in types {
cc_types.push(
db.format_ty_for_cc(element_type, TypeLocation::NestedBridgeable)?
.into_tokens(&mut prereqs),
Expand Down Expand Up @@ -273,7 +273,7 @@ pub fn format_ty_for_cc<'tcx>(
bail!("C++ doesn't have a standard equivalent of `{ty}` (b/254094650)");
}

ty::TyKind::Adt(adt, ref substs) => {
ty::TyKind::Adt(adt, substs) => {
let def_id = adt.did();
let mut prereqs = CcPrerequisites::default();

Expand Down Expand Up @@ -305,7 +305,7 @@ pub fn format_ty_for_cc<'tcx>(
let mut tokens = composable.cpp_type.to_token_stream();
if !substs.is_empty() {
let mut generic_types_tokens = Vec::with_capacity(substs.len());
for subst in *substs {
for subst in substs {
let snippet = format_ty_for_cc(
db,
subst.expect_ty(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ pub fn generate_thunk_decl<'tcx>(
sig_mid
.inputs()
.iter()
.zip(cpp_types.into_iter())
.zip(cpp_types)
.map(|(&ty, cpp_type)| -> Result<TokenStream> {
let cpp_type = cpp_type.snippet.into_tokens(&mut prereqs);
let bridged_type_opt = is_bridged_type(db, ty)?;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ pub(crate) fn generate_associated_item<'tcx>(
}
crate::error_scope!(db, def_id);
let result = match assoc_item.kind {
ty::AssocKind::Fn { .. } => db.generate_function(def_id).and_then(|binding| {
ty::AssocKind::Fn { .. } => db.generate_function(def_id).inspect(|_binding| {
// If `generate_function` succeeds, record the method in `member_function_names`.
let unqualified_name = db
.symbol_unqualified_name(def_id)
.expect("Associated item should have an unqualified name: {def_id:?}");
Expand All @@ -302,7 +303,6 @@ pub(crate) fn generate_associated_item<'tcx>(
was_inserted, // Bindings for Rust/user-named items are given priority.
"Unexpected (user-named 'members' are handled first) naming conflict: {cpp_name}",
);
Ok(binding)
}),
ty::AssocKind::Const { .. } => generate_const(db, def_id),
// TODO: b/405132277 - Rust does not support inherent associated types, but should support
Expand Down Expand Up @@ -1365,11 +1365,12 @@ pub(crate) fn generate_fields<'tcx>(
(field.offset, field_size, field.index)
});
}
FieldsShape::Union(num_fields) => {
FieldsShape::Union { .. } => {
// Compute the offset of each field
for index in 0..num_fields.get() {
variants_fields[variant_index][index].offset =
layout.fields().offset(index).bytes();
for (field_index, field) in
variants_fields[variant_index].iter_mut().enumerate()
{
field.offset = layout.fields().offset(field_index).bytes();
}
}
unexpected => panic!("Unexpected FieldsShape: {unexpected:?}"),
Expand Down
4 changes: 2 additions & 2 deletions cc_bindings_from_rs/generate_bindings/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ fn generate_using<'tcx>(
format_cc_ident(db, using_name.as_str()).context("Error formatting using name")?;

prereqs.depend_on_def(db, def_id)?;
let tokens = if using_name_ident.to_string() == main_api_fn_name.to_string() {
let tokens = if using_name_ident == main_api_fn_name {
quote! { using #formatted_fully_qualified_fn_name; }
} else {
quote! { constexpr auto #using_name_ident = #formatted_fully_qualified_fn_name; }
Expand Down Expand Up @@ -2021,7 +2021,7 @@ fn generate_crate(db: &BindingsGenerator) -> Result<BindingsTokens> {
};

fwd_decls.extend(inner_fwd_decls.difference(&already_declared).copied());
already_declared.extend(inner_fwd_decls.into_iter());
already_declared.extend(inner_fwd_decls);
// We don't need to do this for specializations.
if let Node::Def(def_id) = node {
already_declared.insert(def_id);
Expand Down
Loading