diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index d2020ac852d0..1498004e66ca 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -1453,7 +1453,7 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig { if sess.opts.crate_types.contains(&CrateType::ProcMacro) { ret.insert((Symbol::intern("proc_macro"), None)); } - return ret; + ret } pub fn build_configuration(sess: &Session, mut user_cfg: ast::CrateConfig) -> ast::CrateConfig { @@ -1469,15 +1469,12 @@ pub fn build_configuration(sess: &Session, mut user_cfg: ast::CrateConfig) -> as } pub fn build_target_config(opts: &Options, sp: &Handler) -> Config { - let target = match Target::search(&opts.target_triple) { - Ok(t) => t, - Err(e) => { - sp.struct_fatal(&format!("Error loading target specification: {}", e)) - .help("Use `--print target-list` for a list of built-in targets") - .emit(); - FatalError.raise(); - } - }; + let target = Target::search(&opts.target_triple).unwrap_or_else(|e| { + sp.struct_fatal(&format!("Error loading target specification: {}", e)) + .help("Use `--print target-list` for a list of built-in targets") + .emit(); + FatalError.raise(); + }); let (isize_ty, usize_ty) = match &target.target_pointer_width[..] { "16" => (ast::IntTy::I16, ast::UintTy::U16), @@ -1842,9 +1839,8 @@ pub fn build_session_options_and_crate_config( }; let edition = match matches.opt_str("edition") { - Some(arg) => match Edition::from_str(&arg){ - Ok(edition) => edition, - Err(_) => early_error( + Some(arg) => Edition::from_str(&arg).unwrap_or_else(|_| + early_error( ErrorOutputType::default(), &format!( "argument for --edition must be one of: \ @@ -1853,7 +1849,7 @@ pub fn build_session_options_and_crate_config( arg ), ), - } + ), None => DEFAULT_EDITION, }; @@ -1922,9 +1918,8 @@ pub fn build_session_options_and_crate_config( for output_type in list.split(',') { let mut parts = output_type.splitn(2, '='); let shorthand = parts.next().unwrap(); - let output_type = match OutputType::from_shorthand(shorthand) { - Some(output_type) => output_type, - None => early_error( + let output_type = OutputType::from_shorthand(shorthand).unwrap_or_else(|| + early_error( error_format, &format!( "unknown emission type: `{}` - expected one of: {}", @@ -1932,7 +1927,7 @@ pub fn build_session_options_and_crate_config( OutputType::shorthands_display(), ), ), - }; + ); let path = parts.next().map(PathBuf::from); output_types.insert(output_type, path); } @@ -2060,12 +2055,8 @@ pub fn build_session_options_and_crate_config( let target_triple = if let Some(target) = matches.opt_str("target") { if target.ends_with(".json") { let path = Path::new(&target); - match TargetTriple::from_path(&path) { - Ok(triple) => triple, - Err(_) => { - early_error(error_format, &format!("target file {:?} does not exist", path)) - } - } + TargetTriple::from_path(&path).unwrap_or_else(|_| + early_error(error_format, &format!("target file {:?} does not exist", path))) } else { TargetTriple::TargetTriple(target) } @@ -2220,10 +2211,8 @@ pub fn build_session_options_and_crate_config( let mut externs: BTreeMap<_, BTreeSet<_>> = BTreeMap::new(); for arg in &matches.opt_strs("extern") { let mut parts = arg.splitn(2, '='); - let name = match parts.next() { - Some(s) => s, - None => early_error(error_format, "--extern value must not be empty"), - }; + let name = parts.next().unwrap_or_else(|| + early_error(error_format, "--extern value must not be empty")); let location = parts.next().map(|s| s.to_string()); if location.is_none() && !is_unstable_enabled { early_error( diff --git a/src/librustc/session/filesearch.rs b/src/librustc/session/filesearch.rs index fb8bf8be1c24..f7a2a2d1bf14 100644 --- a/src/librustc/session/filesearch.rs +++ b/src/librustc/session/filesearch.rs @@ -160,7 +160,7 @@ pub fn get_or_default_sysroot() -> PathBuf { match env::current_exe() { Ok(exe) => { match canonicalize(Some(exe)) { - Some(mut p) => { p.pop(); p.pop(); return p; }, + Some(mut p) => { p.pop(); p.pop(); p }, None => bug!("can't determine value for sysroot") } } diff --git a/src/librustc/session/mod.rs b/src/librustc/session/mod.rs index 43c4bea9def3..e983ddc3108d 100644 --- a/src/librustc/session/mod.rs +++ b/src/librustc/session/mod.rs @@ -727,14 +727,8 @@ impl Session { pub fn set_incr_session_load_dep_graph(&self, load: bool) { let mut incr_comp_session = self.incr_comp_session.borrow_mut(); - match *incr_comp_session { - IncrCompSession::Active { - ref mut load_dep_graph, - .. - } => { - *load_dep_graph = load; - } - _ => {} + if let IncrCompSession::Active { ref mut load_dep_graph, .. } = *incr_comp_session { + *load_dep_graph = load; } } @@ -872,9 +866,9 @@ impl Session { /// This expends fuel if applicable, and records fuel if applicable. pub fn consider_optimizing String>(&self, crate_name: &str, msg: T) -> bool { let mut ret = true; - match self.optimization_fuel_crate { - Some(ref c) if c == crate_name => { - assert!(self.query_threads() == 1); + if let Some(ref c) = self.optimization_fuel_crate { + if c == crate_name { + assert_eq!(self.query_threads(), 1); let fuel = self.optimization_fuel_limit.get(); ret = fuel != 0; if fuel == 0 && !self.out_of_fuel.get() { @@ -884,14 +878,12 @@ impl Session { self.optimization_fuel_limit.set(fuel - 1); } } - _ => {} } - match self.print_fuel_crate { - Some(ref c) if c == crate_name => { - assert!(self.query_threads() == 1); + if let Some(ref c) = self.print_fuel_crate { + if c == crate_name { + assert_eq!(self.query_threads(), 1); self.print_fuel.set(self.print_fuel.get() + 1); } - _ => {} } ret } @@ -1108,14 +1100,11 @@ pub fn build_session_( source_map: Lrc, ) -> Session { let host_triple = TargetTriple::from_triple(config::host_triple()); - let host = match Target::search(&host_triple) { - Ok(t) => t, - Err(e) => { - span_diagnostic - .fatal(&format!("Error loading host specification: {}", e)) - .raise(); - } - }; + let host = Target::search(&host_triple).unwrap_or_else(|e| + span_diagnostic + .fatal(&format!("Error loading host specification: {}", e)) + .raise() + ); let target_cfg = config::build_target_config(&sopts, &span_diagnostic); let p_s = parse::ParseSess::with_span_handler(span_diagnostic, source_map); @@ -1135,12 +1124,11 @@ pub fn build_session_( let print_fuel_crate = sopts.debugging_opts.print_fuel.clone(); let print_fuel = LockCell::new(0); - let working_dir = match env::current_dir() { - Ok(dir) => dir, - Err(e) => p_s.span_diagnostic + let working_dir = env::current_dir().unwrap_or_else(|e| + p_s.span_diagnostic .fatal(&format!("Current directory is invalid: {}", e)) - .raise(), - }; + .raise() + ); let working_dir = file_path_mapping.map_prefix(working_dir); let cgu_reuse_tracker = if sopts.debugging_opts.query_dep_graph {