Skip to content

Commit

Permalink
Eliminate some Option<NativeLibKind>s
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed May 20, 2020
1 parent 529d488 commit 8dbe4d9
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 34 deletions.
42 changes: 21 additions & 21 deletions src/librustc_interface/tests.rs
Expand Up @@ -300,30 +300,30 @@ fn test_native_libs_tracking_hash_different_values() {

// Reference
v1.libs = vec![
(String::from("a"), None, Some(NativeLibKind::StaticBundle)),
(String::from("b"), None, Some(NativeLibKind::Framework)),
(String::from("c"), None, Some(NativeLibKind::Unspecified)),
(String::from("a"), None, NativeLibKind::StaticBundle),
(String::from("b"), None, NativeLibKind::Framework),
(String::from("c"), None, NativeLibKind::Unspecified),
];

// Change label
v2.libs = vec![
(String::from("a"), None, Some(NativeLibKind::StaticBundle)),
(String::from("X"), None, Some(NativeLibKind::Framework)),
(String::from("c"), None, Some(NativeLibKind::Unspecified)),
(String::from("a"), None, NativeLibKind::StaticBundle),
(String::from("X"), None, NativeLibKind::Framework),
(String::from("c"), None, NativeLibKind::Unspecified),
];

// Change kind
v3.libs = vec![
(String::from("a"), None, Some(NativeLibKind::StaticBundle)),
(String::from("b"), None, Some(NativeLibKind::StaticBundle)),
(String::from("c"), None, Some(NativeLibKind::Unspecified)),
(String::from("a"), None, NativeLibKind::StaticBundle),
(String::from("b"), None, NativeLibKind::StaticBundle),
(String::from("c"), None, NativeLibKind::Unspecified),
];

// Change new-name
v4.libs = vec![
(String::from("a"), None, Some(NativeLibKind::StaticBundle)),
(String::from("b"), Some(String::from("X")), Some(NativeLibKind::Framework)),
(String::from("c"), None, Some(NativeLibKind::Unspecified)),
(String::from("a"), None, NativeLibKind::StaticBundle),
(String::from("b"), Some(String::from("X")), NativeLibKind::Framework),
(String::from("c"), None, NativeLibKind::Unspecified),
];

assert!(v1.dep_tracking_hash() != v2.dep_tracking_hash());
Expand All @@ -345,21 +345,21 @@ fn test_native_libs_tracking_hash_different_order() {

// Reference
v1.libs = vec![
(String::from("a"), None, Some(NativeLibKind::StaticBundle)),
(String::from("b"), None, Some(NativeLibKind::Framework)),
(String::from("c"), None, Some(NativeLibKind::Unspecified)),
(String::from("a"), None, NativeLibKind::StaticBundle),
(String::from("b"), None, NativeLibKind::Framework),
(String::from("c"), None, NativeLibKind::Unspecified),
];

v2.libs = vec![
(String::from("b"), None, Some(NativeLibKind::Framework)),
(String::from("a"), None, Some(NativeLibKind::StaticBundle)),
(String::from("c"), None, Some(NativeLibKind::Unspecified)),
(String::from("b"), None, NativeLibKind::Framework),
(String::from("a"), None, NativeLibKind::StaticBundle),
(String::from("c"), None, NativeLibKind::Unspecified),
];

v3.libs = vec![
(String::from("c"), None, Some(NativeLibKind::Unspecified)),
(String::from("a"), None, Some(NativeLibKind::StaticBundle)),
(String::from("b"), None, Some(NativeLibKind::Framework)),
(String::from("c"), None, NativeLibKind::Unspecified),
(String::from("a"), None, NativeLibKind::StaticBundle),
(String::from("b"), None, NativeLibKind::Framework),
];

assert!(v1.dep_tracking_hash() == v2.dep_tracking_hash());
Expand Down
6 changes: 3 additions & 3 deletions src/librustc_metadata/native_libs.rs
Expand Up @@ -241,8 +241,8 @@ impl Collector<'tcx> {
.drain_filter(|lib| {
if let Some(lib_name) = lib.name {
if lib_name.as_str() == *name {
if let Some(k) = kind {
lib.kind = k;
if kind != NativeLibKind::Unspecified {
lib.kind = kind;
}
if let &Some(ref new_name) = new_name {
lib.name = Some(Symbol::intern(new_name));
Expand All @@ -258,7 +258,7 @@ impl Collector<'tcx> {
let new_name = new_name.as_ref().map(|s| &**s); // &Option<String> -> Option<&str>
let lib = NativeLib {
name: Some(Symbol::intern(new_name.unwrap_or(name))),
kind: if let Some(k) = kind { k } else { NativeLibKind::Unspecified },
kind,
cfg: None,
foreign_module: None,
wasm_import_module: None,
Expand Down
17 changes: 8 additions & 9 deletions src/librustc_session/config.rs
Expand Up @@ -1452,7 +1452,7 @@ fn select_debuginfo(
fn parse_libs(
matches: &getopts::Matches,
error_format: ErrorOutputType,
) -> Vec<(String, Option<String>, Option<NativeLibKind>)> {
) -> Vec<(String, Option<String>, NativeLibKind)> {
matches
.opt_strs("l")
.into_iter()
Expand All @@ -1462,11 +1462,11 @@ fn parse_libs(
let mut parts = s.splitn(2, '=');
let kind = parts.next().unwrap();
let (name, kind) = match (parts.next(), kind) {
(None, name) => (name, None),
(Some(name), "dylib") => (name, Some(NativeLibKind::Dylib)),
(Some(name), "framework") => (name, Some(NativeLibKind::Framework)),
(Some(name), "static") => (name, Some(NativeLibKind::StaticBundle)),
(Some(name), "static-nobundle") => (name, Some(NativeLibKind::StaticNoBundle)),
(None, name) => (name, NativeLibKind::Unspecified),
(Some(name), "dylib") => (name, NativeLibKind::Dylib),
(Some(name), "framework") => (name, NativeLibKind::Framework),
(Some(name), "static") => (name, NativeLibKind::StaticBundle),
(Some(name), "static-nobundle") => (name, NativeLibKind::StaticNoBundle),
(_, s) => {
early_error(
error_format,
Expand All @@ -1478,7 +1478,7 @@ fn parse_libs(
);
}
};
if kind == Some(NativeLibKind::StaticNoBundle) && !nightly_options::is_nightly_build() {
if kind == NativeLibKind::StaticNoBundle && !nightly_options::is_nightly_build() {
early_error(
error_format,
"the library kind 'static-nobundle' is only \
Expand Down Expand Up @@ -2058,7 +2058,6 @@ crate mod dep_tracking {
impl_dep_tracking_hash_via_hash!(Option<RelroLevel>);
impl_dep_tracking_hash_via_hash!(Option<lint::Level>);
impl_dep_tracking_hash_via_hash!(Option<PathBuf>);
impl_dep_tracking_hash_via_hash!(Option<NativeLibKind>);
impl_dep_tracking_hash_via_hash!(CrateType);
impl_dep_tracking_hash_via_hash!(MergeFunctions);
impl_dep_tracking_hash_via_hash!(PanicStrategy);
Expand All @@ -2084,7 +2083,7 @@ crate mod dep_tracking {
impl_dep_tracking_hash_for_sortable_vec_of!(PathBuf);
impl_dep_tracking_hash_for_sortable_vec_of!(CrateType);
impl_dep_tracking_hash_for_sortable_vec_of!((String, lint::Level));
impl_dep_tracking_hash_for_sortable_vec_of!((String, Option<String>, Option<NativeLibKind>));
impl_dep_tracking_hash_for_sortable_vec_of!((String, Option<String>, NativeLibKind));
impl_dep_tracking_hash_for_sortable_vec_of!((String, u64));
impl_dep_tracking_hash_for_sortable_vec_of!(Sanitizer);

Expand Down
2 changes: 1 addition & 1 deletion src/librustc_session/options.rs
Expand Up @@ -93,7 +93,7 @@ top_level_options!(
describe_lints: bool [UNTRACKED],
output_types: OutputTypes [TRACKED],
search_paths: Vec<SearchPath> [UNTRACKED],
libs: Vec<(String, Option<String>, Option<NativeLibKind>)> [TRACKED],
libs: Vec<(String, Option<String>, NativeLibKind)> [TRACKED],
maybe_sysroot: Option<PathBuf> [UNTRACKED],

target_triple: TargetTriple [TRACKED],
Expand Down

0 comments on commit 8dbe4d9

Please sign in to comment.