Skip to content

Commit 71e39ed

Browse files
committed
transpile: refactor and document TypedAstContext::tys_of_params
1 parent fecafdb commit 71e39ed

File tree

1 file changed

+10
-8
lines changed
  • c2rust-transpile/src/c_ast

1 file changed

+10
-8
lines changed

c2rust-transpile/src/c_ast/mod.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -508,15 +508,17 @@ impl TypedAstContext {
508508
}
509509

510510
/// Return the list of types for a list of declared function parameters.
511+
///
512+
/// Returns `None` if one of the parameters is not a `CDeclKind::Variable`, e.g. if it was not a
513+
/// function parameter but actually some other kind of declaration.
511514
pub fn tys_of_params(&self, parameters: &[CDeclId]) -> Option<Vec<CQualTypeId>> {
512-
let mut param_tys = vec![];
513-
for p in parameters {
514-
match self.index(*p).kind {
515-
CDeclKind::Variable { typ, .. } => param_tys.push(CQualTypeId::new(typ.ctype)),
516-
_ => return None,
517-
}
518-
}
519-
return Some(param_tys);
515+
parameters
516+
.iter()
517+
.map(|p| match self.index(*p).kind {
518+
CDeclKind::Variable { typ, .. } => Some(CQualTypeId::new(typ.ctype)),
519+
_ => None,
520+
})
521+
.collect()
520522
}
521523

522524
/// Return the most precise possible CTypeKind for the given function declaration.

0 commit comments

Comments
 (0)