Skip to content

Commit be8fd8b

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. - The "Unconditionally" comment is erroneously duplicated from `check_attr_crate_type`, and can be removed.
1 parent 95b0088 commit be8fd8b

File tree

1 file changed

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

1 file changed

+7
-15
lines changed

compiler/rustc_interface/src/util.rs

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -482,21 +482,6 @@ 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 {
@@ -510,6 +495,13 @@ pub fn collect_crate_types(session: &Session, attrs: &[ast::Attribute]) -> Vec<C
510495
#[allow(rustc::bad_opt_access)]
511496
let mut base = session.opts.crate_types.clone();
512497
if base.is_empty() {
498+
let attr_types = attrs.iter().filter_map(|a| {
499+
if a.has_name(sym::crate_type) && let Some(s) = a.value_str() {
500+
categorize_crate_type(s)
501+
} else {
502+
None
503+
}
504+
});
513505
base.extend(attr_types);
514506
if base.is_empty() {
515507
base.push(output::default_output_for_target(session));

0 commit comments

Comments
 (0)