@@ -490,10 +490,10 @@ pub enum Input {
490
490
}
491
491
492
492
impl Input {
493
- pub fn filestem ( & self ) -> String {
493
+ pub fn filestem ( & self ) -> & str {
494
494
match * self {
495
- Input :: File ( ref ifile) => ifile. file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) . to_string ( ) ,
496
- Input :: Str { .. } => "rust_out" . to_string ( ) ,
495
+ Input :: File ( ref ifile) => ifile. file_stem ( ) . unwrap ( ) . to_str ( ) . unwrap ( ) ,
496
+ Input :: Str { .. } => "rust_out" ,
497
497
}
498
498
}
499
499
@@ -765,7 +765,6 @@ macro_rules! options {
765
765
}
766
766
767
767
impl <' a> dep_tracking:: DepTrackingHash for $struct_name {
768
-
769
768
fn hash( & self , hasher: & mut DefaultHasher , error_format: ErrorOutputType ) {
770
769
let mut sub_hashes = BTreeMap :: new( ) ;
771
770
$( {
@@ -1313,13 +1312,11 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
1313
1312
profile: bool = ( false , parse_bool, [ TRACKED ] ,
1314
1313
"insert profiling code" ) ,
1315
1314
pgo_gen: Option <String > = ( None , parse_opt_string, [ TRACKED ] ,
1316
- "Generate PGO profile data, to a given file, or to the default \
1317
- location if it's empty.") ,
1315
+ "Generate PGO profile data, to a given file, or to the default location if it's empty." ) ,
1318
1316
pgo_use: String = ( String :: new( ) , parse_string, [ TRACKED ] ,
1319
1317
"Use PGO profile data from the given profile file." ) ,
1320
- disable_instrumentation_preinliner: bool =
1321
- ( false , parse_bool, [ TRACKED ] , "Disable the instrumentation pre-inliner, \
1322
- useful for profiling / PGO.") ,
1318
+ disable_instrumentation_preinliner: bool = ( false , parse_bool, [ TRACKED ] ,
1319
+ "Disable the instrumentation pre-inliner, useful for profiling / PGO." ) ,
1323
1320
relro_level: Option <RelroLevel > = ( None , parse_relro_level, [ TRACKED ] ,
1324
1321
"choose which RELRO level to use" ) ,
1325
1322
nll_subminimal_causes: bool = ( false , parse_bool, [ UNTRACKED ] ,
@@ -1409,6 +1406,7 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
1409
1406
let atomic_cas = sess. target . target . options . atomic_cas ;
1410
1407
1411
1408
let mut ret = FxHashSet :: default ( ) ;
1409
+ ret. reserve ( 6 ) ; // the minimum number of insertions
1412
1410
// Target bindings.
1413
1411
ret. insert ( ( Symbol :: intern ( "target_os" ) , Some ( Symbol :: intern ( os) ) ) ) ;
1414
1412
if let Some ( ref fam) = sess. target . target . options . target_family {
@@ -1455,7 +1453,7 @@ pub fn default_configuration(sess: &Session) -> ast::CrateConfig {
1455
1453
if sess. opts . crate_types . contains ( & CrateType :: ProcMacro ) {
1456
1454
ret. insert ( ( Symbol :: intern ( "proc_macro" ) , None ) ) ;
1457
1455
}
1458
- return ret;
1456
+ ret
1459
1457
}
1460
1458
1461
1459
pub fn build_configuration ( sess : & Session , mut user_cfg : ast:: CrateConfig ) -> ast:: CrateConfig {
@@ -1471,15 +1469,12 @@ pub fn build_configuration(sess: &Session, mut user_cfg: ast::CrateConfig) -> as
1471
1469
}
1472
1470
1473
1471
pub fn build_target_config ( opts : & Options , sp : & Handler ) -> Config {
1474
- let target = match Target :: search ( & opts. target_triple ) {
1475
- Ok ( t) => t,
1476
- Err ( e) => {
1472
+ let target = Target :: search ( & opts. target_triple ) . unwrap_or_else ( |e| {
1477
1473
sp. struct_fatal ( & format ! ( "Error loading target specification: {}" , e) )
1478
1474
. help ( "Use `--print target-list` for a list of built-in targets" )
1479
1475
. emit ( ) ;
1480
1476
FatalError . raise ( ) ;
1481
- }
1482
- } ;
1477
+ } ) ;
1483
1478
1484
1479
let ( isize_ty, usize_ty) = match & target. target_pointer_width [ ..] {
1485
1480
"16" => ( ast:: IntTy :: I16 , ast:: UintTy :: U16 ) ,
@@ -1502,7 +1497,6 @@ pub fn build_target_config(opts: &Options, sp: &Handler) -> Config {
1502
1497
#[ derive( Copy , Clone , PartialEq , Eq , Debug ) ]
1503
1498
pub enum OptionStability {
1504
1499
Stable ,
1505
-
1506
1500
Unstable ,
1507
1501
}
1508
1502
@@ -1845,9 +1839,8 @@ pub fn build_session_options_and_crate_config(
1845
1839
} ;
1846
1840
1847
1841
let edition = match matches. opt_str ( "edition" ) {
1848
- Some ( arg) => match Edition :: from_str ( & arg) {
1849
- Ok ( edition) => edition,
1850
- Err ( _) => early_error (
1842
+ Some ( arg) => Edition :: from_str ( & arg) . unwrap_or_else ( |_|
1843
+ early_error (
1851
1844
ErrorOutputType :: default ( ) ,
1852
1845
& format ! (
1853
1846
"argument for --edition must be one of: \
@@ -1856,7 +1849,7 @@ pub fn build_session_options_and_crate_config(
1856
1849
arg
1857
1850
) ,
1858
1851
) ,
1859
- }
1852
+ ) ,
1860
1853
None => DEFAULT_EDITION ,
1861
1854
} ;
1862
1855
@@ -1925,17 +1918,16 @@ pub fn build_session_options_and_crate_config(
1925
1918
for output_type in list. split ( ',' ) {
1926
1919
let mut parts = output_type. splitn ( 2 , '=' ) ;
1927
1920
let shorthand = parts. next ( ) . unwrap ( ) ;
1928
- let output_type = match OutputType :: from_shorthand ( shorthand) {
1929
- Some ( output_type) => output_type,
1930
- None => early_error (
1921
+ let output_type = OutputType :: from_shorthand ( shorthand) . unwrap_or_else ( ||
1922
+ early_error (
1931
1923
error_format,
1932
1924
& format ! (
1933
1925
"unknown emission type: `{}` - expected one of: {}" ,
1934
1926
shorthand,
1935
1927
OutputType :: shorthands_display( ) ,
1936
1928
) ,
1937
1929
) ,
1938
- } ;
1930
+ ) ;
1939
1931
let path = parts. next ( ) . map ( PathBuf :: from) ;
1940
1932
output_types. insert ( output_type, path) ;
1941
1933
}
@@ -2063,12 +2055,8 @@ pub fn build_session_options_and_crate_config(
2063
2055
let target_triple = if let Some ( target) = matches. opt_str ( "target" ) {
2064
2056
if target. ends_with ( ".json" ) {
2065
2057
let path = Path :: new ( & target) ;
2066
- match TargetTriple :: from_path ( & path) {
2067
- Ok ( triple) => triple,
2068
- Err ( _) => {
2069
- early_error ( error_format, & format ! ( "target file {:?} does not exist" , path) )
2070
- }
2071
- }
2058
+ TargetTriple :: from_path ( & path) . unwrap_or_else ( |_|
2059
+ early_error ( error_format, & format ! ( "target file {:?} does not exist" , path) ) )
2072
2060
} else {
2073
2061
TargetTriple :: TargetTriple ( target)
2074
2062
}
@@ -2169,7 +2157,7 @@ pub fn build_session_options_and_crate_config(
2169
2157
let mut name_parts = name. splitn ( 2 , ':' ) ;
2170
2158
let name = name_parts. next ( ) . unwrap ( ) ;
2171
2159
let new_name = name_parts. next ( ) ;
2172
- ( name. to_string ( ) , new_name. map ( |n| n. to_string ( ) ) , kind)
2160
+ ( name. to_owned ( ) , new_name. map ( |n| n. to_owned ( ) ) , kind)
2173
2161
} )
2174
2162
. collect ( ) ;
2175
2163
@@ -2223,10 +2211,8 @@ pub fn build_session_options_and_crate_config(
2223
2211
let mut externs: BTreeMap < _ , BTreeSet < _ > > = BTreeMap :: new ( ) ;
2224
2212
for arg in & matches. opt_strs ( "extern" ) {
2225
2213
let mut parts = arg. splitn ( 2 , '=' ) ;
2226
- let name = match parts. next ( ) {
2227
- Some ( s) => s,
2228
- None => early_error ( error_format, "--extern value must not be empty" ) ,
2229
- } ;
2214
+ let name = parts. next ( ) . unwrap_or_else ( ||
2215
+ early_error ( error_format, "--extern value must not be empty" ) ) ;
2230
2216
let location = parts. next ( ) . map ( |s| s. to_string ( ) ) ;
2231
2217
if location. is_none ( ) && !is_unstable_enabled {
2232
2218
early_error (
@@ -2237,7 +2223,7 @@ pub fn build_session_options_and_crate_config(
2237
2223
} ;
2238
2224
2239
2225
externs
2240
- . entry ( name. to_string ( ) )
2226
+ . entry ( name. to_owned ( ) )
2241
2227
. or_default ( )
2242
2228
. insert ( location) ;
2243
2229
}
@@ -2308,9 +2294,7 @@ pub fn parse_crate_types_from_list(list_list: Vec<String>) -> Result<Vec<CrateTy
2308
2294
"cdylib" => CrateType :: Cdylib ,
2309
2295
"bin" => CrateType :: Executable ,
2310
2296
"proc-macro" => CrateType :: ProcMacro ,
2311
- _ => {
2312
- return Err ( format ! ( "unknown crate type: `{}`" , part) ) ;
2313
- }
2297
+ _ => return Err ( format ! ( "unknown crate type: `{}`" , part) )
2314
2298
} ;
2315
2299
if !crate_types. contains ( & new_part) {
2316
2300
crate_types. push ( new_part)
0 commit comments