Skip to content

Commit

Permalink
Rollup merge of rust-lang#59180 - taiki-e:try_blocks, r=scottmcm
Browse files Browse the repository at this point in the history
Use try blocks in rustc_codegen_ssa

r? @scottmcm
  • Loading branch information
Centril authored Mar 16, 2019
2 parents ff17858 + ab19e58 commit d7aa140
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
15 changes: 6 additions & 9 deletions src/librustc_codegen_ssa/back/linker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,29 +382,27 @@ impl<'a> Linker for GccLinker<'a> {

if self.sess.target.target.options.is_like_osx {
// Write a plain, newline-separated list of symbols
let res = (|| -> io::Result<()> {
let res: io::Result<()> = try {
let mut f = BufWriter::new(File::create(&path)?);
for sym in self.info.exports[&crate_type].iter() {
debug!(" _{}", sym);
writeln!(f, "_{}", sym)?;
}
Ok(())
})();
};
if let Err(e) = res {
self.sess.fatal(&format!("failed to write lib.def file: {}", e));
}
} else {
// Write an LD version script
let res = (|| -> io::Result<()> {
let res: io::Result<()> = try {
let mut f = BufWriter::new(File::create(&path)?);
writeln!(f, "{{\n global:")?;
for sym in self.info.exports[&crate_type].iter() {
debug!(" {};", sym);
writeln!(f, " {};", sym)?;
}
writeln!(f, "\n local:\n *;\n}};")?;
Ok(())
})();
};
if let Err(e) = res {
self.sess.fatal(&format!("failed to write version script: {}", e));
}
Expand Down Expand Up @@ -644,7 +642,7 @@ impl<'a> Linker for MsvcLinker<'a> {
tmpdir: &Path,
crate_type: CrateType) {
let path = tmpdir.join("lib.def");
let res = (|| -> io::Result<()> {
let res: io::Result<()> = try {
let mut f = BufWriter::new(File::create(&path)?);

// Start off with the standard module name header and then go
Expand All @@ -655,8 +653,7 @@ impl<'a> Linker for MsvcLinker<'a> {
debug!(" _{}", symbol);
writeln!(f, " {}", symbol)?;
}
Ok(())
})();
};
if let Err(e) = res {
self.sess.fatal(&format!("failed to write lib.def file: {}", e));
}
Expand Down
1 change: 1 addition & 0 deletions src/librustc_codegen_ssa/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#![feature(libc)]
#![feature(rustc_diagnostic_macros)]
#![feature(stmt_expr_attributes)]
#![feature(try_blocks)]
#![feature(in_band_lifetimes)]
#![feature(nll)]
#![allow(unused_attributes)]
Expand Down

0 comments on commit d7aa140

Please sign in to comment.