Skip to content

Commit

Permalink
Rollup merge of #56419 - mark-i-m:remove-try, r=Centril
Browse files Browse the repository at this point in the history
Remove some uses of try!
  • Loading branch information
Centril authored Dec 1, 2018
2 parents 9b574ce + e7e9692 commit 874af23
Show file tree
Hide file tree
Showing 11 changed files with 25 additions and 27 deletions.
6 changes: 3 additions & 3 deletions src/bootstrap/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -915,13 +915,13 @@ fn symlink_dir_force(config: &Config, src: &Path, dst: &Path) -> io::Result<()>
}
if let Ok(m) = fs::symlink_metadata(dst) {
if m.file_type().is_dir() {
try!(fs::remove_dir_all(dst));
fs::remove_dir_all(dst)?;
} else {
// handle directory junctions on windows by falling back to
// `remove_dir`.
try!(fs::remove_file(dst).or_else(|_| {
fs::remove_file(dst).or_else(|_| {
fs::remove_dir(dst)
}));
})?;
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/bootstrap/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -203,11 +203,11 @@ pub fn symlink_dir(config: &Config, src: &Path, dest: &Path) -> io::Result<()> {
// We're using low-level APIs to create the junction, and these are more
// picky about paths. For example, forward slashes cannot be used as a
// path separator, so we should try to canonicalize the path first.
let target = try!(fs::canonicalize(target));
let target = fs::canonicalize(target)?;

try!(fs::create_dir(junction));
fs::create_dir(junction)?;

let path = try!(to_u16s(junction));
let path = to_u16s(junction)?;

unsafe {
let h = CreateFileW(path.as_ptr(),
Expand Down
10 changes: 5 additions & 5 deletions src/libcore/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -278,14 +278,14 @@ macro_rules! debug_assert_ne {
///
/// // The previous method of quick returning Errors
/// fn write_to_file_using_try() -> Result<(), MyError> {
/// let mut file = try!(File::create("my_best_friends.txt"));
/// try!(file.write_all(b"This is a list of my best friends."));
/// let mut file = r#try!(File::create("my_best_friends.txt"));
/// r#try!(file.write_all(b"This is a list of my best friends."));
/// Ok(())
/// }
///
/// // This is equivalent to:
/// fn write_to_file_using_match() -> Result<(), MyError> {
/// let mut file = try!(File::create("my_best_friends.txt"));
/// let mut file = r#try!(File::create("my_best_friends.txt"));
/// match file.write_all(b"This is a list of my best friends.") {
/// Ok(v) => v,
/// Err(e) => return Err(From::from(e)),
Expand All @@ -296,14 +296,14 @@ macro_rules! debug_assert_ne {
#[macro_export]
#[stable(feature = "rust1", since = "1.0.0")]
#[doc(alias = "?")]
macro_rules! try {
macro_rules! r#try {
($expr:expr) => (match $expr {
$crate::result::Result::Ok(val) => val,
$crate::result::Result::Err(err) => {
return $crate::result::Result::Err($crate::convert::From::from(err))
}
});
($expr:expr,) => (try!($expr));
($expr:expr,) => (r#try!($expr));
}

/// Write formatted data into a buffer.
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_incremental/persist/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -659,7 +659,7 @@ pub fn garbage_collect_session_directories(sess: &Session) -> io::Result<()> {
let mut session_directories = FxHashSet::default();
let mut lock_files = FxHashSet::default();

for dir_entry in try!(crate_directory.read_dir()) {
for dir_entry in crate_directory.read_dir()? {
let dir_entry = match dir_entry {
Ok(dir_entry) => dir_entry,
_ => {
Expand Down Expand Up @@ -887,7 +887,7 @@ fn all_except_most_recent(deletion_candidates: Vec<(SystemTime, PathBuf, Option<
/// into the '\\?\' format, which supports much longer paths.
fn safe_remove_dir_all(p: &Path) -> io::Result<()> {
if p.exists() {
let canonicalized = try!(p.canonicalize());
let canonicalized = p.canonicalize()?;
std_fs::remove_dir_all(canonicalized)
} else {
Ok(())
Expand All @@ -896,7 +896,7 @@ fn safe_remove_dir_all(p: &Path) -> io::Result<()> {

fn safe_remove_file(p: &Path) -> io::Result<()> {
if p.exists() {
let canonicalized = try!(p.canonicalize());
let canonicalized = p.canonicalize()?;
std_fs::remove_file(canonicalized)
} else {
Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/dataflow/move_paths/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ impl<'b, 'a, 'gcx, 'tcx> Gatherer<'b, 'a, 'gcx, 'tcx> {
proj: &PlaceProjection<'tcx>)
-> Result<MovePathIndex, MoveError<'tcx>>
{
let base = try!(self.move_path_for(&proj.base));
let base = self.move_path_for(&proj.base)?;
let mir = self.builder.mir;
let tcx = self.builder.tcx;
let place_ty = proj.base.ty(mir, tcx).to_ty(tcx);
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_target/spec/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -995,7 +995,7 @@ impl Target {

key!(is_builtin, bool);
key!(linker, optional);
try!(key!(lld_flavor, LldFlavor));
key!(lld_flavor, LldFlavor)?;
key!(pre_link_args, link_args);
key!(pre_link_args_crt, link_args);
key!(pre_link_objects_exe, list);
Expand Down Expand Up @@ -1038,7 +1038,7 @@ impl Target {
key!(no_default_libraries, bool);
key!(position_independent_executables, bool);
key!(needs_plt, bool);
try!(key!(relro_level, RelroLevel));
key!(relro_level, RelroLevel)?;
key!(archive_format);
key!(allow_asm, bool);
key!(custom_unwind_resume, bool);
Expand All @@ -1048,7 +1048,7 @@ impl Target {
key!(max_atomic_width, Option<u64>);
key!(min_atomic_width, Option<u64>);
key!(atomic_cas, bool);
try!(key!(panic_strategy, PanicStrategy));
key!(panic_strategy, PanicStrategy)?;
key!(crt_static_allows_dylibs, bool);
key!(crt_static_default, bool);
key!(crt_static_respected, bool);
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2065,7 +2065,7 @@ impl DirBuilder {
Err(e) => return Err(e),
}
match path.parent() {
Some(p) => try!(self.create_dir_all(p)),
Some(p) => self.create_dir_all(p)?,
None => return Err(io::Error::new(io::ErrorKind::Other, "failed to create whole tree")),
}
match self.inner.mkdir(path) {
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/sys/windows/stdio.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ pub fn get(handle: c::DWORD) -> io::Result<Output> {
}

fn write(handle: c::DWORD, data: &[u8]) -> io::Result<usize> {
let handle = match try!(get(handle)) {
let handle = match get(handle)? {
Output::Console(c) => c,
Output::Pipe(p) => {
let handle = Handle::new(p);
Expand Down Expand Up @@ -99,7 +99,7 @@ impl Stdin {
}

pub fn read(&self, buf: &mut [u8]) -> io::Result<usize> {
let handle = match try!(get(c::STD_INPUT_HANDLE)) {
let handle = match get(c::STD_INPUT_HANDLE)? {
Output::Console(c) => c,
Output::Pipe(p) => {
let handle = Handle::new(p);
Expand Down
6 changes: 2 additions & 4 deletions src/libsyntax/parse/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3145,7 +3145,7 @@ impl<'a> Parser<'a> {
RangeLimits::Closed
};

let r = try!(self.mk_range(Some(lhs), rhs, limits));
let r = self.mk_range(Some(lhs), rhs, limits)?;
lhs = self.mk_expr(lhs_span.to(rhs_span), r, ThinVec::new());
break
}
Expand Down Expand Up @@ -3353,9 +3353,7 @@ impl<'a> Parser<'a> {
RangeLimits::Closed
};

let r = try!(self.mk_range(None,
opt_end,
limits));
let r = self.mk_range(None, opt_end, limits)?;
Ok(self.mk_expr(lo.to(hi), r, attrs))
}

Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax/print/pprust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1527,7 +1527,7 @@ impl<'a> State<'a> {

pub fn print_defaultness(&mut self, defaultness: ast::Defaultness) -> io::Result<()> {
if let ast::Defaultness::Default = defaultness {
try!(self.word_nbsp("default"));
self.word_nbsp("default")?;
}
Ok(())
}
Expand Down
2 changes: 1 addition & 1 deletion src/libsyntax_ext/format_foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,7 @@ pub mod printf {
match *self {
Num::Num(n) => write!(s, "{}", n),
Num::Arg(n) => {
let n = try!(n.checked_sub(1).ok_or(::std::fmt::Error));
let n = n.checked_sub(1).ok_or(::std::fmt::Error)?;
write!(s, "{}$", n)
},
Num::Next => write!(s, "*"),
Expand Down

0 comments on commit 874af23

Please sign in to comment.