Skip to content

Commit 9e5e6a9

Browse files
committed
rustc_codegen_ssa: cleanup nested ifs and a needless match
1 parent c930bb2 commit 9e5e6a9

File tree

4 files changed

+24
-28
lines changed

4 files changed

+24
-28
lines changed

compiler/rustc_codegen_ssa/src/back/link.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -626,10 +626,9 @@ fn link_staticlib(
626626

627627
let mut all_rust_dylibs = vec![];
628628
for &cnum in crates {
629-
match fmts.get(cnum) {
630-
Some(&Linkage::Dynamic) => {}
631-
_ => continue,
632-
}
629+
let Some(Linkage::Dynamic) = fmts.get(cnum) else {
630+
continue;
631+
};
633632
let crate_name = codegen_results.crate_info.crate_name[&cnum];
634633
let used_crate_source = &codegen_results.crate_info.used_crate_source[&cnum];
635634
if let Some((path, _)) = &used_crate_source.dylib {

compiler/rustc_codegen_ssa/src/back/write.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -1537,8 +1537,9 @@ fn start_executing_work<B: ExtraBackendMethods>(
15371537
// Spin up what work we can, only doing this while we've got available
15381538
// parallelism slots and work left to spawn.
15391539
if codegen_state != Aborted {
1540-
while !work_items.is_empty() && running_with_own_token < tokens.len() {
1541-
let (item, _) = work_items.pop().unwrap();
1540+
while running_with_own_token < tokens.len()
1541+
&& let Some((item, _)) = work_items.pop()
1542+
{
15421543
spawn_work(
15431544
&cgcx,
15441545
&mut llvm_start_time,

compiler/rustc_codegen_ssa/src/codegen_attrs.rs

+15-20
Original file line numberDiff line numberDiff line change
@@ -655,25 +655,20 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
655655
// llvm/llvm-project#70563).
656656
if !codegen_fn_attrs.target_features.is_empty()
657657
&& matches!(codegen_fn_attrs.inline, InlineAttr::Always)
658+
&& let Some(span) = inline_span
658659
{
659-
if let Some(span) = inline_span {
660-
tcx.dcx().span_err(span, "cannot use `#[inline(always)]` with `#[target_feature]`");
661-
}
660+
tcx.dcx().span_err(span, "cannot use `#[inline(always)]` with `#[target_feature]`");
662661
}
663662

664-
if !codegen_fn_attrs.no_sanitize.is_empty() && codegen_fn_attrs.inline.always() {
665-
if let (Some(no_sanitize_span), Some(inline_span)) = (no_sanitize_span, inline_span) {
666-
let hir_id = tcx.local_def_id_to_hir_id(did);
667-
tcx.node_span_lint(
668-
lint::builtin::INLINE_NO_SANITIZE,
669-
hir_id,
670-
no_sanitize_span,
671-
|lint| {
672-
lint.primary_message("`no_sanitize` will have no effect after inlining");
673-
lint.span_note(inline_span, "inlining requested here");
674-
},
675-
)
676-
}
663+
if !codegen_fn_attrs.no_sanitize.is_empty()
664+
&& codegen_fn_attrs.inline.always()
665+
&& let (Some(no_sanitize_span), Some(inline_span)) = (no_sanitize_span, inline_span)
666+
{
667+
let hir_id = tcx.local_def_id_to_hir_id(did);
668+
tcx.node_span_lint(lint::builtin::INLINE_NO_SANITIZE, hir_id, no_sanitize_span, |lint| {
669+
lint.primary_message("`no_sanitize` will have no effect after inlining");
670+
lint.span_note(inline_span, "inlining requested here");
671+
})
677672
}
678673

679674
// Weak lang items have the same semantics as "std internal" symbols in the
@@ -703,10 +698,10 @@ fn codegen_fn_attrs(tcx: TyCtxt<'_>, did: LocalDefId) -> CodegenFnAttrs {
703698
// Any linkage to LLVM intrinsics for now forcibly marks them all as never
704699
// unwinds since LLVM sometimes can't handle codegen which `invoke`s
705700
// intrinsic functions.
706-
if let Some(name) = &codegen_fn_attrs.link_name {
707-
if name.as_str().starts_with("llvm.") {
708-
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NEVER_UNWIND;
709-
}
701+
if let Some(name) = &codegen_fn_attrs.link_name
702+
&& name.as_str().starts_with("llvm.")
703+
{
704+
codegen_fn_attrs.flags |= CodegenFnAttrFlags::NEVER_UNWIND;
710705
}
711706

712707
if let Some(features) = check_tied_features(

compiler/rustc_codegen_ssa/src/mir/block.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -990,8 +990,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
990990
});
991991

992992
// Split the rust-call tupled arguments off.
993-
let (first_args, untuple) = if abi == ExternAbi::RustCall && !args.is_empty() {
994-
let (tup, args) = args.split_last().unwrap();
993+
let (first_args, untuple) = if abi == ExternAbi::RustCall
994+
&& let Some((tup, args)) = args.split_last()
995+
{
995996
(args, Some(tup))
996997
} else {
997998
(args, None)

0 commit comments

Comments
 (0)