remove some uses of try!
This commit is contained in:
parent
d48ab693d1
commit
e7e96921c2
11 changed files with 25 additions and 27 deletions
|
@ -914,13 +914,13 @@ fn symlink_dir_force(config: &Config, src: &Path, dst: &Path) -> io::Result<()>
|
||||||
}
|
}
|
||||||
if let Ok(m) = fs::symlink_metadata(dst) {
|
if let Ok(m) = fs::symlink_metadata(dst) {
|
||||||
if m.file_type().is_dir() {
|
if m.file_type().is_dir() {
|
||||||
try!(fs::remove_dir_all(dst));
|
fs::remove_dir_all(dst)?;
|
||||||
} else {
|
} else {
|
||||||
// handle directory junctions on windows by falling back to
|
// handle directory junctions on windows by falling back to
|
||||||
// `remove_dir`.
|
// `remove_dir`.
|
||||||
try!(fs::remove_file(dst).or_else(|_| {
|
fs::remove_file(dst).or_else(|_| {
|
||||||
fs::remove_dir(dst)
|
fs::remove_dir(dst)
|
||||||
}));
|
})?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
// 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
|
// picky about paths. For example, forward slashes cannot be used as a
|
||||||
// path separator, so we should try to canonicalize the path first.
|
// 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 {
|
unsafe {
|
||||||
let h = CreateFileW(path.as_ptr(),
|
let h = CreateFileW(path.as_ptr(),
|
||||||
|
|
|
@ -278,14 +278,14 @@ macro_rules! debug_assert_ne {
|
||||||
///
|
///
|
||||||
/// // The previous method of quick returning Errors
|
/// // The previous method of quick returning Errors
|
||||||
/// fn write_to_file_using_try() -> Result<(), MyError> {
|
/// fn write_to_file_using_try() -> Result<(), MyError> {
|
||||||
/// let mut file = try!(File::create("my_best_friends.txt"));
|
/// let mut file = r#try!(File::create("my_best_friends.txt"));
|
||||||
/// try!(file.write_all(b"This is a list of my best friends."));
|
/// r#try!(file.write_all(b"This is a list of my best friends."));
|
||||||
/// Ok(())
|
/// Ok(())
|
||||||
/// }
|
/// }
|
||||||
///
|
///
|
||||||
/// // This is equivalent to:
|
/// // This is equivalent to:
|
||||||
/// fn write_to_file_using_match() -> Result<(), MyError> {
|
/// 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.") {
|
/// match file.write_all(b"This is a list of my best friends.") {
|
||||||
/// Ok(v) => v,
|
/// Ok(v) => v,
|
||||||
/// Err(e) => return Err(From::from(e)),
|
/// Err(e) => return Err(From::from(e)),
|
||||||
|
@ -296,14 +296,14 @@ macro_rules! debug_assert_ne {
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
#[stable(feature = "rust1", since = "1.0.0")]
|
#[stable(feature = "rust1", since = "1.0.0")]
|
||||||
#[doc(alias = "?")]
|
#[doc(alias = "?")]
|
||||||
macro_rules! try {
|
macro_rules! r#try {
|
||||||
($expr:expr) => (match $expr {
|
($expr:expr) => (match $expr {
|
||||||
$crate::result::Result::Ok(val) => val,
|
$crate::result::Result::Ok(val) => val,
|
||||||
$crate::result::Result::Err(err) => {
|
$crate::result::Result::Err(err) => {
|
||||||
return $crate::result::Result::Err($crate::convert::From::from(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.
|
/// Write formatted data into a buffer.
|
||||||
|
|
|
@ -659,7 +659,7 @@ pub fn garbage_collect_session_directories(sess: &Session) -> io::Result<()> {
|
||||||
let mut session_directories = FxHashSet::default();
|
let mut session_directories = FxHashSet::default();
|
||||||
let mut lock_files = 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 {
|
let dir_entry = match dir_entry {
|
||||||
Ok(dir_entry) => dir_entry,
|
Ok(dir_entry) => dir_entry,
|
||||||
_ => {
|
_ => {
|
||||||
|
@ -887,7 +887,7 @@ fn all_except_most_recent(deletion_candidates: Vec<(SystemTime, PathBuf, Option<
|
||||||
/// into the '\\?\' format, which supports much longer paths.
|
/// into the '\\?\' format, which supports much longer paths.
|
||||||
fn safe_remove_dir_all(p: &Path) -> io::Result<()> {
|
fn safe_remove_dir_all(p: &Path) -> io::Result<()> {
|
||||||
if p.exists() {
|
if p.exists() {
|
||||||
let canonicalized = try!(p.canonicalize());
|
let canonicalized = p.canonicalize()?;
|
||||||
std_fs::remove_dir_all(canonicalized)
|
std_fs::remove_dir_all(canonicalized)
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
|
@ -896,7 +896,7 @@ fn safe_remove_dir_all(p: &Path) -> io::Result<()> {
|
||||||
|
|
||||||
fn safe_remove_file(p: &Path) -> io::Result<()> {
|
fn safe_remove_file(p: &Path) -> io::Result<()> {
|
||||||
if p.exists() {
|
if p.exists() {
|
||||||
let canonicalized = try!(p.canonicalize());
|
let canonicalized = p.canonicalize()?;
|
||||||
std_fs::remove_file(canonicalized)
|
std_fs::remove_file(canonicalized)
|
||||||
} else {
|
} else {
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
|
@ -128,7 +128,7 @@ impl<'b, 'a, 'gcx, 'tcx> Gatherer<'b, 'a, 'gcx, 'tcx> {
|
||||||
proj: &PlaceProjection<'tcx>)
|
proj: &PlaceProjection<'tcx>)
|
||||||
-> Result<MovePathIndex, MoveError<'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 mir = self.builder.mir;
|
||||||
let tcx = self.builder.tcx;
|
let tcx = self.builder.tcx;
|
||||||
let place_ty = proj.base.ty(mir, tcx).to_ty(tcx);
|
let place_ty = proj.base.ty(mir, tcx).to_ty(tcx);
|
||||||
|
|
|
@ -995,7 +995,7 @@ impl Target {
|
||||||
|
|
||||||
key!(is_builtin, bool);
|
key!(is_builtin, bool);
|
||||||
key!(linker, optional);
|
key!(linker, optional);
|
||||||
try!(key!(lld_flavor, LldFlavor));
|
key!(lld_flavor, LldFlavor)?;
|
||||||
key!(pre_link_args, link_args);
|
key!(pre_link_args, link_args);
|
||||||
key!(pre_link_args_crt, link_args);
|
key!(pre_link_args_crt, link_args);
|
||||||
key!(pre_link_objects_exe, list);
|
key!(pre_link_objects_exe, list);
|
||||||
|
@ -1038,7 +1038,7 @@ impl Target {
|
||||||
key!(no_default_libraries, bool);
|
key!(no_default_libraries, bool);
|
||||||
key!(position_independent_executables, bool);
|
key!(position_independent_executables, bool);
|
||||||
key!(needs_plt, bool);
|
key!(needs_plt, bool);
|
||||||
try!(key!(relro_level, RelroLevel));
|
key!(relro_level, RelroLevel)?;
|
||||||
key!(archive_format);
|
key!(archive_format);
|
||||||
key!(allow_asm, bool);
|
key!(allow_asm, bool);
|
||||||
key!(custom_unwind_resume, bool);
|
key!(custom_unwind_resume, bool);
|
||||||
|
@ -1048,7 +1048,7 @@ impl Target {
|
||||||
key!(max_atomic_width, Option<u64>);
|
key!(max_atomic_width, Option<u64>);
|
||||||
key!(min_atomic_width, Option<u64>);
|
key!(min_atomic_width, Option<u64>);
|
||||||
key!(atomic_cas, bool);
|
key!(atomic_cas, bool);
|
||||||
try!(key!(panic_strategy, PanicStrategy));
|
key!(panic_strategy, PanicStrategy)?;
|
||||||
key!(crt_static_allows_dylibs, bool);
|
key!(crt_static_allows_dylibs, bool);
|
||||||
key!(crt_static_default, bool);
|
key!(crt_static_default, bool);
|
||||||
key!(crt_static_respected, bool);
|
key!(crt_static_respected, bool);
|
||||||
|
|
|
@ -2065,7 +2065,7 @@ impl DirBuilder {
|
||||||
Err(e) => return Err(e),
|
Err(e) => return Err(e),
|
||||||
}
|
}
|
||||||
match path.parent() {
|
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")),
|
None => return Err(io::Error::new(io::ErrorKind::Other, "failed to create whole tree")),
|
||||||
}
|
}
|
||||||
match self.inner.mkdir(path) {
|
match self.inner.mkdir(path) {
|
||||||
|
|
|
@ -48,7 +48,7 @@ pub fn get(handle: c::DWORD) -> io::Result<Output> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn write(handle: c::DWORD, data: &[u8]) -> io::Result<usize> {
|
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::Console(c) => c,
|
||||||
Output::Pipe(p) => {
|
Output::Pipe(p) => {
|
||||||
let handle = Handle::new(p);
|
let handle = Handle::new(p);
|
||||||
|
@ -99,7 +99,7 @@ impl Stdin {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn read(&self, buf: &mut [u8]) -> io::Result<usize> {
|
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::Console(c) => c,
|
||||||
Output::Pipe(p) => {
|
Output::Pipe(p) => {
|
||||||
let handle = Handle::new(p);
|
let handle = Handle::new(p);
|
||||||
|
|
|
@ -3145,7 +3145,7 @@ impl<'a> Parser<'a> {
|
||||||
RangeLimits::Closed
|
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());
|
lhs = self.mk_expr(lhs_span.to(rhs_span), r, ThinVec::new());
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
@ -3353,9 +3353,7 @@ impl<'a> Parser<'a> {
|
||||||
RangeLimits::Closed
|
RangeLimits::Closed
|
||||||
};
|
};
|
||||||
|
|
||||||
let r = try!(self.mk_range(None,
|
let r = self.mk_range(None, opt_end, limits)?;
|
||||||
opt_end,
|
|
||||||
limits));
|
|
||||||
Ok(self.mk_expr(lo.to(hi), r, attrs))
|
Ok(self.mk_expr(lo.to(hi), r, attrs))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1525,7 +1525,7 @@ impl<'a> State<'a> {
|
||||||
|
|
||||||
pub fn print_defaultness(&mut self, defaultness: ast::Defaultness) -> io::Result<()> {
|
pub fn print_defaultness(&mut self, defaultness: ast::Defaultness) -> io::Result<()> {
|
||||||
if let ast::Defaultness::Default = defaultness {
|
if let ast::Defaultness::Default = defaultness {
|
||||||
try!(self.word_nbsp("default"));
|
self.word_nbsp("default")?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -264,7 +264,7 @@ pub mod printf {
|
||||||
match *self {
|
match *self {
|
||||||
Num::Num(n) => write!(s, "{}", n),
|
Num::Num(n) => write!(s, "{}", n),
|
||||||
Num::Arg(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)
|
write!(s, "{}$", n)
|
||||||
},
|
},
|
||||||
Num::Next => write!(s, "*"),
|
Num::Next => write!(s, "*"),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue