Skip to content

Commit 58217bc

Browse files
committed
Replace uses of parse_opt_* with parse_* where possible.
This lets us specify the default at the options declaration point, instead of using `.unwrap(default)` or `None | Some(default)` at some use point far away. It also makes the code more concise.
1 parent b9bcddc commit 58217bc

File tree

10 files changed

+50
-67
lines changed

10 files changed

+50
-67
lines changed

src/librustc_codegen_llvm/back/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ pub(crate) fn should_use_new_llvm_pass_manager(config: &ModuleConfig) -> bool {
347347
}
348348

349349
// The new pass manager is disabled by default.
350-
config.new_llvm_pass_manager.unwrap_or(false)
350+
config.new_llvm_pass_manager
351351
}
352352

353353
pub(crate) unsafe fn optimize_with_new_llvm_pass_manager(

src/librustc_codegen_ssa/back/link.rs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -858,18 +858,7 @@ fn preserve_objects_for_their_debuginfo(sess: &Session) -> bool {
858858
// *not* running dsymutil then the object files are the only source of truth
859859
// for debug information, so we must preserve them.
860860
if sess.target.target.options.is_like_osx {
861-
match sess.opts.debugging_opts.run_dsymutil {
862-
// dsymutil is not being run, preserve objects
863-
Some(false) => return true,
864-
865-
// dsymutil is being run, no need to preserve the objects
866-
Some(true) => return false,
867-
868-
// The default historical behavior was to always run dsymutil, so
869-
// we're preserving that temporarily, but we're likely to switch the
870-
// default soon.
871-
None => return false,
872-
}
861+
return !sess.opts.debugging_opts.run_dsymutil;
873862
}
874863

875864
false
@@ -1324,11 +1313,11 @@ fn link_local_crate_native_libs_and_dependent_crate_libs<'a, B: ArchiveBuilder<'
13241313
// If -Zlink-native-libraries=false is set, then the assumption is that an
13251314
// external build system already has the native dependencies defined, and it
13261315
// will provide them to the linker itself.
1327-
if sess.opts.debugging_opts.link_native_libraries.unwrap_or(true) {
1316+
if sess.opts.debugging_opts.link_native_libraries {
13281317
add_local_native_libraries(cmd, sess, codegen_results);
13291318
}
13301319
add_upstream_rust_crates::<B>(cmd, sess, codegen_results, crate_type, tmpdir);
1331-
if sess.opts.debugging_opts.link_native_libraries.unwrap_or(true) {
1320+
if sess.opts.debugging_opts.link_native_libraries {
13321321
add_upstream_native_libraries(cmd, sess, codegen_results, crate_type);
13331322
}
13341323
}
@@ -1534,9 +1523,7 @@ fn linker_with_args<'a, B: ArchiveBuilder<'a>>(
15341523
// OBJECT-FILES-NO, AUDIT-ORDER
15351524
// We want to prevent the compiler from accidentally leaking in any system libraries,
15361525
// so by default we tell linkers not to link to any default libraries.
1537-
if !sess.opts.cg.default_linker_libraries.unwrap_or(false)
1538-
&& sess.target.target.options.no_default_libraries
1539-
{
1526+
if !sess.opts.cg.default_linker_libraries && sess.target.target.options.no_default_libraries {
15401527
cmd.no_default_libraries();
15411528
}
15421529

src/librustc_codegen_ssa/back/linker.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ impl<'a> Linker for GccLinker<'a> {
384384
// If we are building without debuginfo enabled and we were called with
385385
// `-Zstrip-debuginfo-if-disabled=yes`, tell the linker to strip any debuginfo
386386
// found when linking to get rid of symbols from libstd.
387-
if let Some(true) = self.sess.opts.debugging_opts.strip_debuginfo_if_disabled {
387+
if self.sess.opts.debugging_opts.strip_debuginfo_if_disabled {
388388
self.linker_arg("-S");
389389
}
390390
};

src/librustc_codegen_ssa/back/write.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ pub struct ModuleConfig {
115115
pub vectorize_slp: bool,
116116
pub merge_functions: bool,
117117
pub inline_threshold: Option<usize>,
118-
pub new_llvm_pass_manager: Option<bool>,
118+
pub new_llvm_pass_manager: bool,
119119
}
120120

121121
impl ModuleConfig {

src/librustc_interface/tests.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -375,7 +375,7 @@ fn test_codegen_options_tracking_hash() {
375375
let mut opts = Options::default();
376376

377377
// Make sure the changing an [UNTRACKED] option leaves the hash unchanged
378-
opts.cg.ar = Some(String::from("abc"));
378+
opts.cg.ar = String::from("abc");
379379
assert_eq!(reference.dep_tracking_hash(), opts.dep_tracking_hash());
380380

381381
opts.cg.linker = Some(PathBuf::from("linker"));
@@ -479,11 +479,11 @@ fn test_codegen_options_tracking_hash() {
479479
assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
480480

481481
opts = reference.clone();
482-
opts.cg.debuginfo = Some(0xdeadbeef);
482+
opts.cg.debuginfo = 0xdeadbeef;
483483
assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
484484

485485
opts = reference.clone();
486-
opts.cg.debuginfo = Some(0xba5eba11);
486+
opts.cg.debuginfo = 0xba5eba11;
487487
assert!(reference.dep_tracking_hash() != opts.dep_tracking_hash());
488488

489489
opts = reference.clone();

src/librustc_middle/ty/layout.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2182,9 +2182,7 @@ where
21822182
//
21832183
// For now, do not enable mutable_noalias by default at all, while the
21842184
// issue is being figured out.
2185-
let mutable_noalias =
2186-
tcx.sess.opts.debugging_opts.mutable_noalias.unwrap_or(false);
2187-
if mutable_noalias {
2185+
if tcx.sess.opts.debugging_opts.mutable_noalias {
21882186
PointerKind::UniqueBorrowed
21892187
} else {
21902188
PointerKind::Shared

src/librustc_session/config.rs

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -617,18 +617,14 @@ impl Options {
617617
}
618618

619619
impl DebuggingOptions {
620-
pub fn ui_testing(&self) -> bool {
621-
self.ui_testing.unwrap_or(false)
622-
}
623-
624620
pub fn diagnostic_handler_flags(&self, can_emit_warnings: bool) -> HandlerFlags {
625621
HandlerFlags {
626622
can_emit_warnings,
627623
treat_err_as_bug: self.treat_err_as_bug,
628624
dont_buffer_diagnostics: self.dont_buffer_diagnostics,
629625
report_delayed_bugs: self.report_delayed_bugs,
630626
macro_backtrace: self.macro_backtrace,
631-
deduplicate_diagnostics: self.deduplicate_diagnostics.unwrap_or(true),
627+
deduplicate_diagnostics: self.deduplicate_diagnostics,
632628
}
633629
}
634630
}
@@ -1395,15 +1391,14 @@ fn parse_opt_level(
13951391
if max_o > max_c {
13961392
OptLevel::Default
13971393
} else {
1398-
match cg.opt_level.as_ref().map(String::as_ref) {
1399-
None => OptLevel::No,
1400-
Some("0") => OptLevel::No,
1401-
Some("1") => OptLevel::Less,
1402-
Some("2") => OptLevel::Default,
1403-
Some("3") => OptLevel::Aggressive,
1404-
Some("s") => OptLevel::Size,
1405-
Some("z") => OptLevel::SizeMin,
1406-
Some(arg) => {
1394+
match cg.opt_level.as_ref() {
1395+
"0" => OptLevel::No,
1396+
"1" => OptLevel::Less,
1397+
"2" => OptLevel::Default,
1398+
"3" => OptLevel::Aggressive,
1399+
"s" => OptLevel::Size,
1400+
"z" => OptLevel::SizeMin,
1401+
arg => {
14071402
early_error(
14081403
error_format,
14091404
&format!(
@@ -1436,10 +1431,10 @@ fn select_debuginfo(
14361431
DebugInfo::Full
14371432
} else {
14381433
match cg.debuginfo {
1439-
None | Some(0) => DebugInfo::None,
1440-
Some(1) => DebugInfo::Limited,
1441-
Some(2) => DebugInfo::Full,
1442-
Some(arg) => {
1434+
0 => DebugInfo::None,
1435+
1 => DebugInfo::Limited,
1436+
2 => DebugInfo::Full,
1437+
arg => {
14431438
early_error(
14441439
error_format,
14451440
&format!(
@@ -1502,10 +1497,10 @@ fn parse_libs(
15021497
}
15031498

15041499
fn parse_borrowck_mode(dopts: &DebuggingOptions, error_format: ErrorOutputType) -> BorrowckMode {
1505-
match dopts.borrowck.as_ref().map(|s| &s[..]) {
1506-
None | Some("migrate") => BorrowckMode::Migrate,
1507-
Some("mir") => BorrowckMode::Mir,
1508-
Some(m) => early_error(error_format, &format!("unknown borrowck mode `{}`", m)),
1500+
match dopts.borrowck.as_ref() {
1501+
"migrate" => BorrowckMode::Migrate,
1502+
"mir" => BorrowckMode::Mir,
1503+
m => early_error(error_format, &format!("unknown borrowck mode `{}`", m)),
15091504
}
15101505
}
15111506

src/librustc_session/options.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,7 @@ macro_rules! options {
613613
options! {CodegenOptions, CodegenSetter, basic_codegen_options,
614614
build_codegen_options, "C", "codegen",
615615
CG_OPTIONS, cg_type_desc, cgsetters,
616-
ar: Option<String> = (None, parse_opt_string, [UNTRACKED],
616+
ar: String = (String::new(), parse_string, [UNTRACKED],
617617
"this option is deprecated and does nothing"),
618618
linker: Option<PathBuf> = (None, parse_opt_pathbuf, [UNTRACKED],
619619
"system linker to link outputs with"),
@@ -666,10 +666,10 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options,
666666
"print remarks for these optimization passes (space separated, or \"all\")"),
667667
no_stack_check: bool = (false, parse_bool, [UNTRACKED],
668668
"the `--no-stack-check` flag is deprecated and does nothing"),
669-
debuginfo: Option<usize> = (None, parse_opt_uint, [TRACKED],
669+
debuginfo: usize = (0, parse_uint, [TRACKED],
670670
"debug info emission level, 0 = no debug info, 1 = line tables only, \
671671
2 = full debug info with variable and type information"),
672-
opt_level: Option<String> = (None, parse_opt_string, [TRACKED],
672+
opt_level: String = ("0".to_string(), parse_string, [TRACKED],
673673
"optimize with possible levels 0-3, s, or z"),
674674
force_frame_pointers: Option<bool> = (None, parse_opt_bool, [TRACKED],
675675
"force use of the frame pointers"),
@@ -681,7 +681,7 @@ options! {CodegenOptions, CodegenSetter, basic_codegen_options,
681681
[TRACKED], "panic strategy to compile crate with"),
682682
incremental: Option<String> = (None, parse_opt_string, [UNTRACKED],
683683
"enable incremental compilation"),
684-
default_linker_libraries: Option<bool> = (None, parse_opt_bool, [UNTRACKED],
684+
default_linker_libraries: bool = (false, parse_bool, [UNTRACKED],
685685
"allow the linker to link its default libraries"),
686686
linker_flavor: Option<LinkerFlavor> = (None, parse_linker_flavor, [UNTRACKED],
687687
"linker flavor"),
@@ -706,7 +706,7 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
706706
"when debug-printing compiler state, do not include spans"), // o/w tests have closure@path
707707
identify_regions: bool = (false, parse_bool, [UNTRACKED],
708708
"make unnamed regions display as '# (where # is some non-ident unique id)"),
709-
borrowck: Option<String> = (None, parse_opt_string, [UNTRACKED],
709+
borrowck: String = ("migrate".to_string(), parse_string, [UNTRACKED],
710710
"select which borrowck is used (`mir` or `migrate`)"),
711711
time_passes: bool = (false, parse_bool, [UNTRACKED],
712712
"measure time of each rustc pass"),
@@ -806,7 +806,7 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
806806
"print the result of the monomorphization collection pass"),
807807
mir_opt_level: usize = (1, parse_uint, [TRACKED],
808808
"set the MIR optimization level (0-3, default: 1)"),
809-
mutable_noalias: Option<bool> = (None, parse_opt_bool, [TRACKED],
809+
mutable_noalias: bool = (false, parse_bool, [TRACKED],
810810
"emit noalias metadata for mutable references (default: no)"),
811811
dump_mir: Option<String> = (None, parse_opt_string, [UNTRACKED],
812812
"dump MIR state to file.
@@ -816,7 +816,7 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
816816
`foo & ConstProp` only the 'ConstProp' pass for function names containing 'foo',
817817
`foo | bar` all passes for function names containing 'foo' or 'bar'."),
818818

819-
dump_mir_dir: String = (String::from("mir_dump"), parse_string, [UNTRACKED],
819+
dump_mir_dir: String = ("mir_dump".to_string(), parse_string, [UNTRACKED],
820820
"the directory the MIR is dumped into"),
821821
dump_mir_graphviz: bool = (false, parse_bool, [UNTRACKED],
822822
"in addition to `.mir` files, create graphviz `.dot` files"),
@@ -890,13 +890,16 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
890890
`hir,typed` (HIR with types for each node),
891891
`hir-tree` (dump the raw HIR),
892892
`mir` (the MIR), or `mir-cfg` (graphviz formatted MIR)"),
893-
run_dsymutil: Option<bool> = (None, parse_opt_bool, [TRACKED],
893+
// The default historical behavior was to always run dsymutil, so we're
894+
// preserving that temporarily, but we're likely to switch the default
895+
// soon.
896+
run_dsymutil: bool = (true, parse_bool, [TRACKED],
894897
"run `dsymutil` and delete intermediate object files"),
895-
ui_testing: Option<bool> = (None, parse_opt_bool, [UNTRACKED],
898+
ui_testing: bool = (false, parse_bool, [UNTRACKED],
896899
"format compiler diagnostics in a way that's better suitable for UI testing"),
897900
embed_bitcode: bool = (false, parse_bool, [TRACKED],
898901
"embed LLVM bitcode in object files"),
899-
strip_debuginfo_if_disabled: Option<bool> = (None, parse_opt_bool, [TRACKED],
902+
strip_debuginfo_if_disabled: bool = (false, parse_bool, [TRACKED],
900903
"tell the linker to strip debuginfo when building without debuginfo enabled"),
901904
share_generics: Option<bool> = (None, parse_opt_bool, [TRACKED],
902905
"make the current crate share its generic instantiations"),
@@ -936,17 +939,17 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
936939
insert_sideeffect: bool = (false, parse_bool, [TRACKED],
937940
"fix undefined behavior when a thread doesn't eventually make progress \
938941
(such as entering an empty infinite loop) by inserting llvm.sideeffect"),
939-
deduplicate_diagnostics: Option<bool> = (None, parse_opt_bool, [UNTRACKED],
942+
deduplicate_diagnostics: bool = (true, parse_bool, [UNTRACKED],
940943
"deduplicate identical diagnostics"),
941944
control_flow_guard: CFGuard = (CFGuard::Disabled, parse_cfguard, [UNTRACKED],
942945
"use Windows Control Flow Guard (`disabled`, `nochecks` or `checks`)"),
943946
no_link: bool = (false, parse_bool, [TRACKED],
944947
"compile without linking"),
945948
link_only: bool = (false, parse_bool, [TRACKED],
946949
"link the `.rlink` file generated by `-Z no-link`"),
947-
new_llvm_pass_manager: Option<bool> = (None, parse_opt_bool, [TRACKED],
950+
new_llvm_pass_manager: bool = (false, parse_bool, [TRACKED],
948951
"use new LLVM pass manager"),
949-
link_native_libraries: Option<bool> = (None, parse_opt_bool, [UNTRACKED],
952+
link_native_libraries: bool = (true, parse_bool, [UNTRACKED],
950953
"link native libraries in the linker invocation"),
951954
src_hash_algorithm: Option<SourceFileHashAlgorithm> = (None, parse_src_file_hash, [TRACKED],
952955
"hash algorithm of source files in debug info (`md5`, or `sha1`)"),

src/librustc_session/session.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -899,7 +899,7 @@ fn default_emitter(
899899
short,
900900
macro_backtrace,
901901
);
902-
Box::new(emitter.ui_testing(sopts.debugging_opts.ui_testing()))
902+
Box::new(emitter.ui_testing(sopts.debugging_opts.ui_testing))
903903
} else {
904904
let emitter = match dst {
905905
None => EmitterWriter::stderr(
@@ -920,7 +920,7 @@ fn default_emitter(
920920
macro_backtrace,
921921
),
922922
};
923-
Box::new(emitter.ui_testing(sopts.debugging_opts.ui_testing()))
923+
Box::new(emitter.ui_testing(sopts.debugging_opts.ui_testing))
924924
}
925925
}
926926
(config::ErrorOutputType::Json { pretty, json_rendered }, None) => Box::new(
@@ -931,7 +931,7 @@ fn default_emitter(
931931
json_rendered,
932932
macro_backtrace,
933933
)
934-
.ui_testing(sopts.debugging_opts.ui_testing()),
934+
.ui_testing(sopts.debugging_opts.ui_testing),
935935
),
936936
(config::ErrorOutputType::Json { pretty, json_rendered }, Some(dst)) => Box::new(
937937
JsonEmitter::new(
@@ -942,7 +942,7 @@ fn default_emitter(
942942
json_rendered,
943943
macro_backtrace,
944944
)
945-
.ui_testing(sopts.debugging_opts.ui_testing()),
945+
.ui_testing(sopts.debugging_opts.ui_testing),
946946
),
947947
}
948948
}

src/librustdoc/core.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ pub fn new_handler(
185185
debugging_opts.terminal_width,
186186
false,
187187
)
188-
.ui_testing(debugging_opts.ui_testing()),
188+
.ui_testing(debugging_opts.ui_testing),
189189
)
190190
}
191191
ErrorOutputType::Json { pretty, json_rendered } => {
@@ -194,7 +194,7 @@ pub fn new_handler(
194194
});
195195
Box::new(
196196
JsonEmitter::stderr(None, source_map, pretty, json_rendered, false)
197-
.ui_testing(debugging_opts.ui_testing()),
197+
.ui_testing(debugging_opts.ui_testing),
198198
)
199199
}
200200
};

0 commit comments

Comments
 (0)