Skip to content

Commit 3968ada

Browse files
committed
codegen_llvm_back: use mem::replace instead of swap where more concise
1 parent ed5802c commit 3968ada

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed

src/librustc_codegen_utils/linker.rs

+5-12
Original file line numberDiff line numberDiff line change
@@ -456,9 +456,8 @@ impl<'a> Linker for GccLinker<'a> {
456456

457457
fn finalize(&mut self) -> Command {
458458
self.hint_dynamic(); // Reset to default before returning the composed command line.
459-
let mut cmd = Command::new("");
460-
::std::mem::swap(&mut cmd, &mut self.cmd);
461-
cmd
459+
460+
::std::mem::replace(&mut self.cmd, Command::new(""))
462461
}
463462

464463
fn group_start(&mut self) {
@@ -710,9 +709,7 @@ impl<'a> Linker for MsvcLinker<'a> {
710709
}
711710

712711
fn finalize(&mut self) -> Command {
713-
let mut cmd = Command::new("");
714-
::std::mem::swap(&mut cmd, &mut self.cmd);
715-
cmd
712+
::std::mem::replace(&mut self.cmd, Command::new(""))
716713
}
717714

718715
// MSVC doesn't need group indicators
@@ -880,9 +877,7 @@ impl<'a> Linker for EmLinker<'a> {
880877
}
881878

882879
fn finalize(&mut self) -> Command {
883-
let mut cmd = Command::new("");
884-
::std::mem::swap(&mut cmd, &mut self.cmd);
885-
cmd
880+
::std::mem::replace(&mut self.cmd, Command::new(""))
886881
}
887882

888883
// Appears not necessary on Emscripten
@@ -1080,9 +1075,7 @@ impl<'a> Linker for WasmLd<'a> {
10801075
// indicative of bugs, let's prevent them.
10811076
self.cmd.arg("--fatal-warnings");
10821077

1083-
let mut cmd = Command::new("");
1084-
::std::mem::swap(&mut cmd, &mut self.cmd);
1085-
cmd
1078+
::std::mem::replace(&mut self.cmd, Command::new(""))
10861079
}
10871080

10881081
// Not needed for now with LLD

0 commit comments

Comments
 (0)