Skip to content

Commit bf6e173

Browse files
anforowiczcopybara-github
authored andcommitted
Fix most Clippy warnings underneath cc_bindings_from_rs/....
PiperOrigin-RevId: 886219205
1 parent 67087d1 commit bf6e173

4 files changed

Lines changed: 14 additions & 13 deletions

File tree

cc_bindings_from_rs/generate_bindings/format_type.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ pub fn format_ty_for_cc<'tcx>(
158158
bail!("The never type `!` is only supported as a return type (b/254507801)");
159159
}
160160
},
161-
ty::TyKind::Tuple(ref types) => {
161+
ty::TyKind::Tuple(types) => {
162162
if types.is_empty() && matches!(location, TypeLocation::FnReturn { .. }) {
163163
keyword(quote! { void })
164164
} else if !location.is_bridgeable() {
@@ -168,7 +168,7 @@ pub fn format_ty_for_cc<'tcx>(
168168
prereqs.includes.insert(CcInclude::tuple());
169169

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

276-
ty::TyKind::Adt(adt, ref substs) => {
276+
ty::TyKind::Adt(adt, substs) => {
277277
let def_id = adt.did();
278278
let mut prereqs = CcPrerequisites::default();
279279

@@ -305,7 +305,7 @@ pub fn format_ty_for_cc<'tcx>(
305305
let mut tokens = composable.cpp_type.to_token_stream();
306306
if !substs.is_empty() {
307307
let mut generic_types_tokens = Vec::with_capacity(substs.len());
308-
for subst in *substs {
308+
for subst in substs {
309309
let snippet = format_ty_for_cc(
310310
db,
311311
subst.expect_ty(),

cc_bindings_from_rs/generate_bindings/generate_function_thunk.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ pub fn generate_thunk_decl<'tcx>(
100100
sig_mid
101101
.inputs()
102102
.iter()
103-
.zip(cpp_types.into_iter())
103+
.zip(cpp_types)
104104
.map(|(&ty, cpp_type)| -> Result<TokenStream> {
105105
let cpp_type = cpp_type.snippet.into_tokens(&mut prereqs);
106106
let bridged_type_opt = is_bridged_type(db, ty)?;

cc_bindings_from_rs/generate_bindings/generate_struct_and_union.rs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,8 @@ pub(crate) fn generate_associated_item<'tcx>(
292292
}
293293
crate::error_scope!(db, def_id);
294294
let result = match assoc_item.kind {
295-
ty::AssocKind::Fn { .. } => db.generate_function(def_id).and_then(|binding| {
295+
ty::AssocKind::Fn { .. } => db.generate_function(def_id).inspect(|_binding| {
296+
// If `generate_function` succeeds, record the method in `member_function_names`.
296297
let unqualified_name = db
297298
.symbol_unqualified_name(def_id)
298299
.expect("Associated item should have an unqualified name: {def_id:?}");
@@ -302,7 +303,6 @@ pub(crate) fn generate_associated_item<'tcx>(
302303
was_inserted, // Bindings for Rust/user-named items are given priority.
303304
"Unexpected (user-named 'members' are handled first) naming conflict: {cpp_name}",
304305
);
305-
Ok(binding)
306306
}),
307307
ty::AssocKind::Const { .. } => generate_const(db, def_id),
308308
// TODO: b/405132277 - Rust does not support inherent associated types, but should support
@@ -1365,11 +1365,12 @@ pub(crate) fn generate_fields<'tcx>(
13651365
(field.offset, field_size, field.index)
13661366
});
13671367
}
1368-
FieldsShape::Union(num_fields) => {
1368+
FieldsShape::Union { .. } => {
13691369
// Compute the offset of each field
1370-
for index in 0..num_fields.get() {
1371-
variants_fields[variant_index][index].offset =
1372-
layout.fields().offset(index).bytes();
1370+
for (field_index, field) in
1371+
variants_fields[variant_index].iter_mut().enumerate()
1372+
{
1373+
field.offset = layout.fields().offset(field_index).bytes();
13731374
}
13741375
}
13751376
unexpected => panic!("Unexpected FieldsShape: {unexpected:?}"),

cc_bindings_from_rs/generate_bindings/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -781,7 +781,7 @@ fn generate_using<'tcx>(
781781
format_cc_ident(db, using_name.as_str()).context("Error formatting using name")?;
782782

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

20232023
fwd_decls.extend(inner_fwd_decls.difference(&already_declared).copied());
2024-
already_declared.extend(inner_fwd_decls.into_iter());
2024+
already_declared.extend(inner_fwd_decls);
20252025
// We don't need to do this for specializations.
20262026
if let Node::Def(def_id) = node {
20272027
already_declared.insert(def_id);

0 commit comments

Comments
 (0)