Skip to content

Commit 183428a

Browse files
committedFeb 22, 2024
Break complex conditional into separate statements
1 parent 16b7e12 commit 183428a

File tree

2 files changed

+21
-14
lines changed

2 files changed

+21
-14
lines changed
 

‎compiler/rustc_codegen_ssa/src/back/link.rs

+20-13
Original file line numberDiff line numberDiff line change
@@ -1187,20 +1187,27 @@ mod win {
11871187
}
11881188

11891189
fn add_sanitizer_libraries(sess: &Session, crate_type: CrateType, linker: &mut dyn Linker) {
1190-
// On macOS the runtimes are distributed as dylibs which should be linked to
1191-
// both executables and dynamic shared objects. Everywhere else the runtimes
1192-
// are currently distributed as static libraries which should be linked to
1193-
// executables only.
1194-
let needs_runtime = !sess.target.is_like_android
1195-
&& (!sess.opts.cg.link_self_contained.is_sanitizers_disabled()
1196-
|| sess.opts.cg.link_self_contained.is_sanitizers_enabled())
1197-
&& match crate_type {
1198-
CrateType::Executable => true,
1199-
CrateType::Dylib | CrateType::Cdylib | CrateType::ProcMacro => sess.target.is_like_osx,
1200-
CrateType::Rlib | CrateType::Staticlib => false,
1201-
};
1190+
if sess.target.is_like_android {
1191+
// Sanitizer runtime libraries are provided dynamically on Android
1192+
// targets.
1193+
return;
1194+
}
12021195

1203-
if !needs_runtime {
1196+
if sess.opts.cg.link_self_contained.is_sanitizers_disabled() {
1197+
// Linking against in-tree sanitizer runtimes is disabled via
1198+
// `-C link-self-contained=-sanitizers`
1199+
return;
1200+
}
1201+
1202+
// On macOS the runtimes are distributed as dylibs which should be linked to
1203+
// both executables and dynamic shared objects. On most other platforms the
1204+
// runtimes are currently distributed as static libraries which should be
1205+
// linked to executables only.
1206+
if match crate_type {
1207+
CrateType::Executable => false,
1208+
CrateType::Dylib | CrateType::Cdylib | CrateType::ProcMacro => !sess.target.is_like_osx,
1209+
CrateType::Rlib | CrateType::Staticlib => true,
1210+
} {
12041211
return;
12051212
}
12061213

‎compiler/rustc_session/src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ impl LinkSelfContained {
310310
self.enabled_components.contains(LinkSelfContainedComponents::SANITIZERS)
311311
}
312312

313-
/// Returns whether the self-contained linker component was disabled on the CLI, using the
313+
/// Returns whether the self-contained sanitizer component was disabled on the CLI, using the
314314
/// `-C link-self-contained=-sanitizers` syntax, or one of the `false` shortcuts.
315315
pub fn is_sanitizers_disabled(&self) -> bool {
316316
self.disabled_components.contains(LinkSelfContainedComponents::SANITIZERS)

0 commit comments

Comments
 (0)