Skip to content

Commit bf92f3b

Browse files
committed
Streamline collect_crate_types.
- The early return can be right at the top. - The control flow is simplified with `if let`. - The `collect` isn't necessary.
1 parent 95b0088 commit bf92f3b

File tree

1 file changed

+9
-15
lines changed
  • compiler/rustc_interface/src

1 file changed

+9
-15
lines changed

compiler/rustc_interface/src/util.rs

+9-15
Original file line numberDiff line numberDiff line change
@@ -482,27 +482,21 @@ fn categorize_crate_type(s: Symbol) -> Option<CrateType> {
482482
}
483483

484484
pub fn collect_crate_types(session: &Session, attrs: &[ast::Attribute]) -> Vec<CrateType> {
485-
// Unconditionally collect crate types from attributes to make them used
486-
let attr_types: Vec<CrateType> = attrs
487-
.iter()
488-
.filter_map(|a| {
489-
if a.has_name(sym::crate_type) {
490-
match a.value_str() {
491-
Some(s) => categorize_crate_type(s),
492-
_ => None,
493-
}
494-
} else {
495-
None
496-
}
497-
})
498-
.collect();
499-
500485
// If we're generating a test executable, then ignore all other output
501486
// styles at all other locations
502487
if session.opts.test {
503488
return vec![CrateType::Executable];
504489
}
505490

491+
// Unconditionally collect crate types from attributes to make them used
492+
let attr_types = attrs.iter().filter_map(|a| {
493+
if a.has_name(sym::crate_type) && let Some(s) = a.value_str() {
494+
categorize_crate_type(s)
495+
} else {
496+
None
497+
}
498+
});
499+
506500
// Only check command line flags if present. If no types are specified by
507501
// command line, then reuse the empty `base` Vec to hold the types that
508502
// will be found in crate attributes.

0 commit comments

Comments
 (0)