From ee7a35ab95e00b5015bff8af5959ce28af528ca5 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Mon, 18 May 2020 00:18:50 +0300 Subject: [PATCH 1/3] Rename some types describing native libraries NativeLibrary(Kind) -> NativeLib(Kind) NativeStatic -> StaticBundle NativeStaticNobundle -> StaticNoBundle NativeFramework -> Framework NativeRawDylib -> RawDylib NativeUnknown -> Unspecified --- src/librustc_codegen_llvm/attributes.rs | 4 +- src/librustc_codegen_ssa/back/link.rs | 47 ++++++++++--------- src/librustc_codegen_ssa/base.rs | 3 +- src/librustc_codegen_ssa/lib.rs | 6 +-- src/librustc_interface/tests.rs | 44 ++++++++--------- src/librustc_metadata/native_libs.rs | 37 ++++++++------- src/librustc_metadata/rmeta/decoder.rs | 4 +- .../rmeta/decoder/cstore_impl.rs | 7 +-- src/librustc_metadata/rmeta/encoder.rs | 6 +-- src/librustc_metadata/rmeta/mod.rs | 4 +- src/librustc_middle/middle/cstore.rs | 8 ++-- src/librustc_middle/query/mod.rs | 4 +- src/librustc_middle/ty/query/mod.rs | 5 +- src/librustc_session/config.rs | 30 +++++------- src/librustc_session/options.rs | 4 +- src/librustc_session/utils.rs | 26 +++++----- 16 files changed, 117 insertions(+), 122 deletions(-) diff --git a/src/librustc_codegen_llvm/attributes.rs b/src/librustc_codegen_llvm/attributes.rs index 64412843f6def..b67119db2b4f2 100644 --- a/src/librustc_codegen_llvm/attributes.rs +++ b/src/librustc_codegen_llvm/attributes.rs @@ -361,8 +361,8 @@ pub fn provide(providers: &mut Providers<'_>) { pub fn provide_extern(providers: &mut Providers<'_>) { providers.wasm_import_module_map = |tcx, cnum| { - // Build up a map from DefId to a `NativeLibrary` structure, where - // `NativeLibrary` internally contains information about + // Build up a map from DefId to a `NativeLib` structure, where + // `NativeLib` internally contains information about // `#[link(wasm_import_module = "...")]` for example. let native_libs = tcx.native_libraries(cnum); diff --git a/src/librustc_codegen_ssa/back/link.rs b/src/librustc_codegen_ssa/back/link.rs index d87b84f880a35..1e9559f59f1de 100644 --- a/src/librustc_codegen_ssa/back/link.rs +++ b/src/librustc_codegen_ssa/back/link.rs @@ -1,12 +1,13 @@ use rustc_data_structures::fx::FxHashSet; use rustc_fs_util::fix_windows_verbatim_for_gcc; use rustc_hir::def_id::CrateNum; -use rustc_middle::middle::cstore::{EncodedMetadata, LibSource, NativeLibrary, NativeLibraryKind}; +use rustc_middle::middle::cstore::{EncodedMetadata, LibSource, NativeLib}; use rustc_middle::middle::dependency_format::Linkage; use rustc_session::config::{self, CFGuard, CrateType, DebugInfo}; use rustc_session::config::{OutputFilenames, OutputType, PrintRequest, Sanitizer}; use rustc_session::output::{check_file_is_writeable, invalid_output_for_target, out_filename}; use rustc_session::search_paths::PathKind; +use rustc_session::utils::NativeLibKind; /// For all the linkers we support, and information they might /// need out of the shared crate context before we get rid of it. use rustc_session::{filesearch, Session}; @@ -327,11 +328,11 @@ fn link_rlib<'a, B: ArchiveBuilder<'a>>( // metadata of the rlib we're generating somehow. for lib in codegen_results.crate_info.used_libraries.iter() { match lib.kind { - NativeLibraryKind::NativeStatic => {} - NativeLibraryKind::NativeStaticNobundle - | NativeLibraryKind::NativeFramework - | NativeLibraryKind::NativeRawDylib - | NativeLibraryKind::NativeUnknown => continue, + NativeLibKind::StaticBundle => {} + NativeLibKind::StaticNoBundle + | NativeLibKind::Framework + | NativeLibKind::RawDylib + | NativeLibKind::Unspecified => continue, } if let Some(name) = lib.name { ab.add_native_library(name); @@ -430,7 +431,7 @@ fn link_staticlib<'a, B: ArchiveBuilder<'a>>( // object files come from where and selectively skip them. let skip_object_files = native_libs .iter() - .any(|lib| lib.kind == NativeLibraryKind::NativeStatic && !relevant_lib(sess, lib)); + .any(|lib| lib.kind == NativeLibKind::StaticBundle && !relevant_lib(sess, lib)); ab.add_rlib( path, &name.as_str(), @@ -858,26 +859,26 @@ enum RlibFlavor { StaticlibBase, } -fn print_native_static_libs(sess: &Session, all_native_libs: &[NativeLibrary]) { +fn print_native_static_libs(sess: &Session, all_native_libs: &[NativeLib]) { let lib_args: Vec<_> = all_native_libs .iter() .filter(|l| relevant_lib(sess, l)) .filter_map(|lib| { let name = lib.name?; match lib.kind { - NativeLibraryKind::NativeStaticNobundle | NativeLibraryKind::NativeUnknown => { + NativeLibKind::StaticNoBundle | NativeLibKind::Unspecified => { if sess.target.target.options.is_like_msvc { Some(format!("{}.lib", name)) } else { Some(format!("-l{}", name)) } } - NativeLibraryKind::NativeFramework => { + NativeLibKind::Framework => { // ld-only syntax, since there are no frameworks in MSVC Some(format!("-framework {}", name)) } // These are included, no need to print them - NativeLibraryKind::NativeStatic | NativeLibraryKind::NativeRawDylib => None, + NativeLibKind::StaticBundle | NativeLibKind::RawDylib => None, } }) .collect(); @@ -1647,11 +1648,11 @@ fn add_local_native_libraries( None => continue, }; match lib.kind { - NativeLibraryKind::NativeUnknown => cmd.link_dylib(name), - NativeLibraryKind::NativeFramework => cmd.link_framework(name), - NativeLibraryKind::NativeStaticNobundle => cmd.link_staticlib(name), - NativeLibraryKind::NativeStatic => cmd.link_whole_staticlib(name, &search_path), - NativeLibraryKind::NativeRawDylib => { + NativeLibKind::Unspecified => cmd.link_dylib(name), + NativeLibKind::Framework => cmd.link_framework(name), + NativeLibKind::StaticNoBundle => cmd.link_staticlib(name), + NativeLibKind::StaticBundle => cmd.link_whole_staticlib(name, &search_path), + NativeLibKind::RawDylib => { // FIXME(#58713): Proper handling for raw dylibs. bug!("raw_dylib feature not yet implemented"); } @@ -1841,7 +1842,7 @@ fn add_upstream_rust_crates<'a, B: ArchiveBuilder<'a>>( let native_libs = &codegen_results.crate_info.native_libraries[&cnum]; let skip_native = native_libs .iter() - .any(|lib| lib.kind == NativeLibraryKind::NativeStatic && !relevant_lib(sess, lib)); + .any(|lib| lib.kind == NativeLibKind::StaticBundle && !relevant_lib(sess, lib)); if (!are_upstream_rust_objects_already_included(sess) || ignored_for_lto(sess, &codegen_results.crate_info, cnum)) @@ -1983,9 +1984,9 @@ fn add_upstream_native_libraries( continue; } match lib.kind { - NativeLibraryKind::NativeUnknown => cmd.link_dylib(name), - NativeLibraryKind::NativeFramework => cmd.link_framework(name), - NativeLibraryKind::NativeStaticNobundle => { + NativeLibKind::Unspecified => cmd.link_dylib(name), + NativeLibKind::Framework => cmd.link_framework(name), + NativeLibKind::StaticNoBundle => { // Link "static-nobundle" native libs only if the crate they originate from // is being linked statically to the current crate. If it's linked dynamically // or is an rlib already included via some other dylib crate, the symbols from @@ -1997,8 +1998,8 @@ fn add_upstream_native_libraries( // ignore statically included native libraries here as we've // already included them when we included the rust library // previously - NativeLibraryKind::NativeStatic => {} - NativeLibraryKind::NativeRawDylib => { + NativeLibKind::StaticBundle => {} + NativeLibKind::RawDylib => { // FIXME(#58713): Proper handling for raw dylibs. bug!("raw_dylib feature not yet implemented"); } @@ -2007,7 +2008,7 @@ fn add_upstream_native_libraries( } } -fn relevant_lib(sess: &Session, lib: &NativeLibrary) -> bool { +fn relevant_lib(sess: &Session, lib: &NativeLib) -> bool { match lib.cfg { Some(ref cfg) => rustc_attr::cfg_matches(cfg, &sess.parse_sess, None), None => true, diff --git a/src/librustc_codegen_ssa/base.rs b/src/librustc_codegen_ssa/base.rs index 29398db6ff8a9..c6ee43a94c398 100644 --- a/src/librustc_codegen_ssa/base.rs +++ b/src/librustc_codegen_ssa/base.rs @@ -44,6 +44,7 @@ use rustc_middle::ty::query::Providers; use rustc_middle::ty::{self, Instance, Ty, TyCtxt}; use rustc_session::cgu_reuse_tracker::CguReuse; use rustc_session::config::{self, EntryFnType}; +use rustc_session::utils::NativeLibKind; use rustc_session::Session; use rustc_span::Span; use rustc_symbol_mangling::test as symbol_names_test; @@ -895,7 +896,7 @@ pub fn provide_both(providers: &mut Providers<'_>) { .native_libraries(krate) .iter() .filter(|lib| { - if lib.kind != cstore::NativeLibraryKind::NativeUnknown { + if lib.kind != NativeLibKind::Unspecified { return false; } let cfg = match lib.cfg { diff --git a/src/librustc_codegen_ssa/lib.rs b/src/librustc_codegen_ssa/lib.rs index 7dc09b595c36e..bd3721850f35f 100644 --- a/src/librustc_codegen_ssa/lib.rs +++ b/src/librustc_codegen_ssa/lib.rs @@ -24,7 +24,7 @@ use rustc_data_structures::sync::Lrc; use rustc_hir::def_id::CrateNum; use rustc_hir::LangItem; use rustc_middle::dep_graph::WorkProduct; -use rustc_middle::middle::cstore::{CrateSource, LibSource, NativeLibrary}; +use rustc_middle::middle::cstore::{CrateSource, LibSource, NativeLib}; use rustc_middle::middle::dependency_format::Dependencies; use rustc_middle::ty::query::Providers; use rustc_session::config::{OutputFilenames, OutputType, RUST_CGU_EXT}; @@ -112,9 +112,9 @@ pub struct CrateInfo { pub compiler_builtins: Option, pub profiler_runtime: Option, pub is_no_builtins: FxHashSet, - pub native_libraries: FxHashMap>>, + pub native_libraries: FxHashMap>>, pub crate_name: FxHashMap, - pub used_libraries: Lrc>, + pub used_libraries: Lrc>, pub link_args: Lrc>, pub used_crate_source: FxHashMap>, pub used_crates_static: Vec<(CrateNum, LibSource)>, diff --git a/src/librustc_interface/tests.rs b/src/librustc_interface/tests.rs index 5e17660f4c60e..3b89ceff447fe 100644 --- a/src/librustc_interface/tests.rs +++ b/src/librustc_interface/tests.rs @@ -2,7 +2,6 @@ use crate::interface::parse_cfgspecs; use rustc_data_structures::fx::FxHashSet; use rustc_errors::{emitter::HumanReadableErrorType, registry, ColorConfig}; -use rustc_middle::middle::cstore; use rustc_session::config::Strip; use rustc_session::config::{build_configuration, build_session_options, to_crate_config}; use rustc_session::config::{rustc_optgroups, ErrorOutputType, ExternLocation, Options, Passes}; @@ -11,6 +10,7 @@ use rustc_session::config::{Externs, OutputType, OutputTypes, Sanitizer, SymbolM use rustc_session::getopts; use rustc_session::lint::Level; use rustc_session::search_paths::SearchPath; +use rustc_session::utils::NativeLibKind; use rustc_session::{build_session, Session}; use rustc_span::edition::{Edition, DEFAULT_EDITION}; use rustc_span::symbol::sym; @@ -300,30 +300,30 @@ fn test_native_libs_tracking_hash_different_values() { // Reference v1.libs = vec![ - (String::from("a"), None, Some(cstore::NativeStatic)), - (String::from("b"), None, Some(cstore::NativeFramework)), - (String::from("c"), None, Some(cstore::NativeUnknown)), + (String::from("a"), None, Some(NativeLibKind::StaticBundle)), + (String::from("b"), None, Some(NativeLibKind::Framework)), + (String::from("c"), None, Some(NativeLibKind::Unspecified)), ]; // Change label v2.libs = vec![ - (String::from("a"), None, Some(cstore::NativeStatic)), - (String::from("X"), None, Some(cstore::NativeFramework)), - (String::from("c"), None, Some(cstore::NativeUnknown)), + (String::from("a"), None, Some(NativeLibKind::StaticBundle)), + (String::from("X"), None, Some(NativeLibKind::Framework)), + (String::from("c"), None, Some(NativeLibKind::Unspecified)), ]; // Change kind v3.libs = vec![ - (String::from("a"), None, Some(cstore::NativeStatic)), - (String::from("b"), None, Some(cstore::NativeStatic)), - (String::from("c"), None, Some(cstore::NativeUnknown)), + (String::from("a"), None, Some(NativeLibKind::StaticBundle)), + (String::from("b"), None, Some(NativeLibKind::StaticBundle)), + (String::from("c"), None, Some(NativeLibKind::Unspecified)), ]; // Change new-name v4.libs = vec![ - (String::from("a"), None, Some(cstore::NativeStatic)), - (String::from("b"), Some(String::from("X")), Some(cstore::NativeFramework)), - (String::from("c"), None, Some(cstore::NativeUnknown)), + (String::from("a"), None, Some(NativeLibKind::StaticBundle)), + (String::from("b"), Some(String::from("X")), Some(NativeLibKind::Framework)), + (String::from("c"), None, Some(NativeLibKind::Unspecified)), ]; assert!(v1.dep_tracking_hash() != v2.dep_tracking_hash()); @@ -345,21 +345,21 @@ fn test_native_libs_tracking_hash_different_order() { // Reference v1.libs = vec![ - (String::from("a"), None, Some(cstore::NativeStatic)), - (String::from("b"), None, Some(cstore::NativeFramework)), - (String::from("c"), None, Some(cstore::NativeUnknown)), + (String::from("a"), None, Some(NativeLibKind::StaticBundle)), + (String::from("b"), None, Some(NativeLibKind::Framework)), + (String::from("c"), None, Some(NativeLibKind::Unspecified)), ]; v2.libs = vec![ - (String::from("b"), None, Some(cstore::NativeFramework)), - (String::from("a"), None, Some(cstore::NativeStatic)), - (String::from("c"), None, Some(cstore::NativeUnknown)), + (String::from("b"), None, Some(NativeLibKind::Framework)), + (String::from("a"), None, Some(NativeLibKind::StaticBundle)), + (String::from("c"), None, Some(NativeLibKind::Unspecified)), ]; v3.libs = vec![ - (String::from("c"), None, Some(cstore::NativeUnknown)), - (String::from("a"), None, Some(cstore::NativeStatic)), - (String::from("b"), None, Some(cstore::NativeFramework)), + (String::from("c"), None, Some(NativeLibKind::Unspecified)), + (String::from("a"), None, Some(NativeLibKind::StaticBundle)), + (String::from("b"), None, Some(NativeLibKind::Framework)), ]; assert!(v1.dep_tracking_hash() == v2.dep_tracking_hash()); diff --git a/src/librustc_metadata/native_libs.rs b/src/librustc_metadata/native_libs.rs index 51c9950a5dfed..a822aec817f00 100644 --- a/src/librustc_metadata/native_libs.rs +++ b/src/librustc_metadata/native_libs.rs @@ -3,22 +3,23 @@ use rustc_data_structures::fx::FxHashSet; use rustc_errors::struct_span_err; use rustc_hir as hir; use rustc_hir::itemlikevisit::ItemLikeVisitor; -use rustc_middle::middle::cstore::{self, NativeLibrary}; +use rustc_middle::middle::cstore::NativeLib; use rustc_middle::ty::TyCtxt; use rustc_session::parse::feature_err; +use rustc_session::utils::NativeLibKind; use rustc_session::Session; use rustc_span::source_map::Span; use rustc_span::symbol::{kw, sym, Symbol}; use rustc_target::spec::abi::Abi; -crate fn collect(tcx: TyCtxt<'_>) -> Vec { +crate fn collect(tcx: TyCtxt<'_>) -> Vec { let mut collector = Collector { tcx, libs: Vec::new() }; tcx.hir().krate().visit_all_item_likes(&mut collector); collector.process_command_line(); collector.libs } -crate fn relevant_lib(sess: &Session, lib: &NativeLibrary) -> bool { +crate fn relevant_lib(sess: &Session, lib: &NativeLib) -> bool { match lib.cfg { Some(ref cfg) => attr::cfg_matches(cfg, &sess.parse_sess, None), None => true, @@ -27,7 +28,7 @@ crate fn relevant_lib(sess: &Session, lib: &NativeLibrary) -> bool { struct Collector<'tcx> { tcx: TyCtxt<'tcx>, - libs: Vec, + libs: Vec, } impl ItemLikeVisitor<'tcx> for Collector<'tcx> { @@ -47,9 +48,9 @@ impl ItemLikeVisitor<'tcx> for Collector<'tcx> { Some(item) => item, None => continue, }; - let mut lib = NativeLibrary { + let mut lib = NativeLib { name: None, - kind: cstore::NativeUnknown, + kind: NativeLibKind::Unspecified, cfg: None, foreign_module: Some(self.tcx.hir().local_def_id(it.hir_id).to_def_id()), wasm_import_module: None, @@ -64,11 +65,11 @@ impl ItemLikeVisitor<'tcx> for Collector<'tcx> { None => continue, // skip like historical compilers }; lib.kind = match &*kind.as_str() { - "static" => cstore::NativeStatic, - "static-nobundle" => cstore::NativeStaticNobundle, - "dylib" => cstore::NativeUnknown, - "framework" => cstore::NativeFramework, - "raw-dylib" => cstore::NativeRawDylib, + "static" => NativeLibKind::StaticBundle, + "static-nobundle" => NativeLibKind::StaticNoBundle, + "dylib" => NativeLibKind::Unspecified, + "framework" => NativeLibKind::Framework, + "raw-dylib" => NativeLibKind::RawDylib, k => { struct_span_err!( self.tcx.sess, @@ -80,7 +81,7 @@ impl ItemLikeVisitor<'tcx> for Collector<'tcx> { .span_label(item.span(), "unknown kind") .span_label(m.span, "") .emit(); - cstore::NativeUnknown + NativeLibKind::Unspecified } }; } else if item.check_name(sym::name) { @@ -134,7 +135,7 @@ impl ItemLikeVisitor<'tcx> for Collector<'tcx> { } impl Collector<'tcx> { - fn register_native_lib(&mut self, span: Option, lib: NativeLibrary) { + fn register_native_lib(&mut self, span: Option, lib: NativeLib) { if lib.name.as_ref().map(|&s| s == kw::Invalid).unwrap_or(false) { match span { Some(span) => { @@ -154,7 +155,7 @@ impl Collector<'tcx> { return; } let is_osx = self.tcx.sess.target.target.options.is_like_osx; - if lib.kind == cstore::NativeFramework && !is_osx { + if lib.kind == NativeLibKind::Framework && !is_osx { let msg = "native frameworks are only available on macOS targets"; match span { Some(span) => struct_span_err!(self.tcx.sess, span, E0455, "{}", msg).emit(), @@ -170,7 +171,7 @@ impl Collector<'tcx> { ) .emit(); } - if lib.kind == cstore::NativeStaticNobundle && !self.tcx.features().static_nobundle { + if lib.kind == NativeLibKind::StaticNoBundle && !self.tcx.features().static_nobundle { feature_err( &self.tcx.sess.parse_sess, sym::static_nobundle, @@ -179,7 +180,7 @@ impl Collector<'tcx> { ) .emit(); } - if lib.kind == cstore::NativeRawDylib && !self.tcx.features().raw_dylib { + if lib.kind == NativeLibKind::RawDylib && !self.tcx.features().raw_dylib { feature_err( &self.tcx.sess.parse_sess, sym::raw_dylib, @@ -255,9 +256,9 @@ impl Collector<'tcx> { if existing.is_empty() { // Add if not found let new_name = new_name.as_ref().map(|s| &**s); // &Option -> Option<&str> - let lib = NativeLibrary { + let lib = NativeLib { name: Some(Symbol::intern(new_name.unwrap_or(name))), - kind: if let Some(k) = kind { k } else { cstore::NativeUnknown }, + kind: if let Some(k) = kind { k } else { NativeLibKind::Unspecified }, cfg: None, foreign_module: None, wasm_import_module: None, diff --git a/src/librustc_metadata/rmeta/decoder.rs b/src/librustc_metadata/rmeta/decoder.rs index 32149c0afd597..220d74960755f 100644 --- a/src/librustc_metadata/rmeta/decoder.rs +++ b/src/librustc_metadata/rmeta/decoder.rs @@ -23,7 +23,7 @@ use rustc_index::vec::{Idx, IndexVec}; use rustc_middle::dep_graph::{self, DepNode, DepNodeExt, DepNodeIndex}; use rustc_middle::hir::exports::Export; use rustc_middle::middle::cstore::{CrateSource, ExternCrate}; -use rustc_middle::middle::cstore::{ForeignModule, LinkagePreference, NativeLibrary}; +use rustc_middle::middle::cstore::{ForeignModule, LinkagePreference, NativeLib}; use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel}; use rustc_middle::mir::interpret::{AllocDecodingSession, AllocDecodingState}; use rustc_middle::mir::{self, interpret, Body, Promoted}; @@ -1278,7 +1278,7 @@ impl<'a, 'tcx> CrateMetadataRef<'a> { }) } - fn get_native_libraries(&self, sess: &Session) -> Vec { + fn get_native_libraries(&self, sess: &Session) -> Vec { if self.root.is_proc_macro_crate() { // Proc macro crates do not have any *target* native libraries. vec![] diff --git a/src/librustc_metadata/rmeta/decoder/cstore_impl.rs b/src/librustc_metadata/rmeta/decoder/cstore_impl.rs index b18272675c0b2..6b8072ec49ab5 100644 --- a/src/librustc_metadata/rmeta/decoder/cstore_impl.rs +++ b/src/librustc_metadata/rmeta/decoder/cstore_impl.rs @@ -13,12 +13,13 @@ use rustc_hir::def_id::{CrateNum, DefId, DefIdMap, CRATE_DEF_INDEX, LOCAL_CRATE} use rustc_hir::definitions::DefPathTable; use rustc_hir::definitions::{DefKey, DefPath, DefPathHash}; use rustc_middle::hir::exports::Export; -use rustc_middle::middle::cstore::{CrateSource, CrateStore, EncodedMetadata, NativeLibraryKind}; +use rustc_middle::middle::cstore::{CrateSource, CrateStore, EncodedMetadata}; use rustc_middle::middle::exported_symbols::ExportedSymbol; use rustc_middle::middle::stability::DeprecationEntry; use rustc_middle::ty::query::Providers; use rustc_middle::ty::query::QueryConfig; use rustc_middle::ty::{self, TyCtxt}; +use rustc_session::utils::NativeLibKind; use rustc_session::{CrateDisambiguator, Session}; use rustc_span::source_map::{self, Span, Spanned}; use rustc_span::symbol::{Ident, Symbol}; @@ -246,11 +247,11 @@ pub fn provide(providers: &mut Providers<'_>) { // resolve! Does this work? Unsure! That's what the issue is about *providers = Providers { is_dllimport_foreign_item: |tcx, id| match tcx.native_library_kind(id) { - Some(NativeLibraryKind::NativeUnknown | NativeLibraryKind::NativeRawDylib) => true, + Some(NativeLibKind::Unspecified | NativeLibKind::RawDylib) => true, _ => false, }, is_statically_included_foreign_item: |tcx, id| match tcx.native_library_kind(id) { - Some(NativeLibraryKind::NativeStatic | NativeLibraryKind::NativeStaticNobundle) => true, + Some(NativeLibKind::StaticBundle | NativeLibKind::StaticNoBundle) => true, _ => false, }, native_library_kind: |tcx, id| { diff --git a/src/librustc_metadata/rmeta/encoder.rs b/src/librustc_metadata/rmeta/encoder.rs index 2589e162dffe2..ebe91d3cee2aa 100644 --- a/src/librustc_metadata/rmeta/encoder.rs +++ b/src/librustc_metadata/rmeta/encoder.rs @@ -18,9 +18,7 @@ use rustc_hir::lang_items; use rustc_hir::{AnonConst, GenericParamKind}; use rustc_index::vec::Idx; use rustc_middle::hir::map::Map; -use rustc_middle::middle::cstore::{ - EncodedMetadata, ForeignModule, LinkagePreference, NativeLibrary, -}; +use rustc_middle::middle::cstore::{EncodedMetadata, ForeignModule, LinkagePreference, NativeLib}; use rustc_middle::middle::dependency_format::Linkage; use rustc_middle::middle::exported_symbols::{ metadata_symbol_name, ExportedSymbol, SymbolExportLevel, @@ -1355,7 +1353,7 @@ impl EncodeContext<'tcx> { self.encode_promoted_mir(def_id); } - fn encode_native_libraries(&mut self) -> Lazy<[NativeLibrary]> { + fn encode_native_libraries(&mut self) -> Lazy<[NativeLib]> { let used_libraries = self.tcx.native_libraries(LOCAL_CRATE); self.lazy(used_libraries.iter().cloned()) } diff --git a/src/librustc_metadata/rmeta/mod.rs b/src/librustc_metadata/rmeta/mod.rs index 669307612055a..89d525eb80b8c 100644 --- a/src/librustc_metadata/rmeta/mod.rs +++ b/src/librustc_metadata/rmeta/mod.rs @@ -11,7 +11,7 @@ use rustc_hir::def_id::{DefId, DefIndex}; use rustc_hir::lang_items; use rustc_index::vec::IndexVec; use rustc_middle::hir::exports::Export; -use rustc_middle::middle::cstore::{DepKind, ForeignModule, LinkagePreference, NativeLibrary}; +use rustc_middle::middle::cstore::{DepKind, ForeignModule, LinkagePreference, NativeLib}; use rustc_middle::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel}; use rustc_middle::mir; use rustc_middle::ty::{self, ReprOptions, Ty}; @@ -190,7 +190,7 @@ crate struct CrateRoot<'tcx> { lang_items: Lazy<[(DefIndex, usize)]>, lang_items_missing: Lazy<[lang_items::LangItem]>, diagnostic_items: Lazy<[(Symbol, DefIndex)]>, - native_libraries: Lazy<[NativeLibrary]>, + native_libraries: Lazy<[NativeLib]>, foreign_modules: Lazy<[ForeignModule]>, source_map: Lazy<[rustc_span::SourceFile]>, def_path_table: Lazy, diff --git a/src/librustc_middle/middle/cstore.rs b/src/librustc_middle/middle/cstore.rs index 012390e8f74b8..97e877df96663 100644 --- a/src/librustc_middle/middle/cstore.rs +++ b/src/librustc_middle/middle/cstore.rs @@ -2,8 +2,6 @@ //! are *mostly* used as a part of that interface, but these should //! probably get a better home if someone can find one. -pub use self::NativeLibraryKind::*; - use crate::ty::TyCtxt; use rustc_ast::ast; @@ -14,7 +12,7 @@ use rustc_hir::def_id::{CrateNum, DefId, LOCAL_CRATE}; use rustc_hir::definitions::{DefKey, DefPath, DefPathHash, DefPathTable}; use rustc_macros::HashStable; use rustc_session::search_paths::PathKind; -pub use rustc_session::utils::NativeLibraryKind; +use rustc_session::utils::NativeLibKind; use rustc_session::CrateDisambiguator; use rustc_span::symbol::Symbol; use rustc_span::Span; @@ -89,8 +87,8 @@ pub enum LinkagePreference { } #[derive(Clone, Debug, RustcEncodable, RustcDecodable, HashStable)] -pub struct NativeLibrary { - pub kind: NativeLibraryKind, +pub struct NativeLib { + pub kind: NativeLibKind, pub name: Option, pub cfg: Option, pub foreign_module: Option, diff --git a/src/librustc_middle/query/mod.rs b/src/librustc_middle/query/mod.rs index 13cf9a934b72c..f7f5c5df8d67b 100644 --- a/src/librustc_middle/query/mod.rs +++ b/src/librustc_middle/query/mod.rs @@ -131,7 +131,7 @@ rustc_queries! { cache_on_disk_if { key.is_local() } } - query native_libraries(_: CrateNum) -> Lrc> { + query native_libraries(_: CrateNum) -> Lrc> { desc { "looking up the native libraries of a linked crate" } } @@ -937,7 +937,7 @@ rustc_queries! { query is_dllimport_foreign_item(_: DefId) -> bool {} query is_statically_included_foreign_item(_: DefId) -> bool {} query native_library_kind(_: DefId) - -> Option {} + -> Option {} } Linking { diff --git a/src/librustc_middle/ty/query/mod.rs b/src/librustc_middle/ty/query/mod.rs index e1a5a766ca15a..f61fc65ce394c 100644 --- a/src/librustc_middle/ty/query/mod.rs +++ b/src/librustc_middle/ty/query/mod.rs @@ -4,8 +4,8 @@ use crate::hir::map; use crate::infer::canonical::{self, Canonical}; use crate::lint::LintLevelMap; use crate::middle::codegen_fn_attrs::CodegenFnAttrs; -use crate::middle::cstore::{CrateSource, DepKind, NativeLibraryKind}; -use crate::middle::cstore::{ExternCrate, ForeignModule, LinkagePreference, NativeLibrary}; +use crate::middle::cstore::{CrateSource, DepKind}; +use crate::middle::cstore::{ExternCrate, ForeignModule, LinkagePreference, NativeLib}; use crate::middle::exported_symbols::{ExportedSymbol, SymbolExportLevel}; use crate::middle::lib_features::LibFeatures; use crate::middle::privacy::AccessLevels; @@ -46,6 +46,7 @@ use rustc_hir::lang_items::{LangItem, LanguageItems}; use rustc_hir::{Crate, HirIdSet, ItemLocalId, TraitCandidate}; use rustc_index::vec::IndexVec; use rustc_session::config::{EntryFnType, OptLevel, OutputFilenames, SymbolManglingVersion}; +use rustc_session::utils::NativeLibKind; use rustc_session::CrateDisambiguator; use rustc_target::spec::PanicStrategy; diff --git a/src/librustc_session/config.rs b/src/librustc_session/config.rs index 5f34a39db05ce..405a058ffab60 100644 --- a/src/librustc_session/config.rs +++ b/src/librustc_session/config.rs @@ -5,7 +5,7 @@ pub use crate::options::*; use crate::lint; use crate::search_paths::SearchPath; -use crate::utils::NativeLibraryKind; +use crate::utils::NativeLibKind; use crate::{early_error, early_warn, Session}; use rustc_data_structures::fx::FxHashSet; @@ -1452,7 +1452,7 @@ fn select_debuginfo( fn parse_libs( matches: &getopts::Matches, error_format: ErrorOutputType, -) -> Vec<(String, Option, Option)> { +) -> Vec<(String, Option, Option)> { matches .opt_strs("l") .into_iter() @@ -1463,12 +1463,10 @@ fn parse_libs( let kind = parts.next().unwrap(); let (name, kind) = match (parts.next(), kind) { (None, name) => (name, None), - (Some(name), "dylib") => (name, Some(NativeLibraryKind::NativeUnknown)), - (Some(name), "framework") => (name, Some(NativeLibraryKind::NativeFramework)), - (Some(name), "static") => (name, Some(NativeLibraryKind::NativeStatic)), - (Some(name), "static-nobundle") => { - (name, Some(NativeLibraryKind::NativeStaticNobundle)) - } + (Some(name), "dylib") => (name, Some(NativeLibKind::Unspecified)), + (Some(name), "framework") => (name, Some(NativeLibKind::Framework)), + (Some(name), "static") => (name, Some(NativeLibKind::StaticBundle)), + (Some(name), "static-nobundle") => (name, Some(NativeLibKind::StaticNoBundle)), (_, s) => { early_error( error_format, @@ -1480,9 +1478,7 @@ fn parse_libs( ); } }; - if kind == Some(NativeLibraryKind::NativeStaticNobundle) - && !nightly_options::is_nightly_build() - { + if kind == Some(NativeLibKind::StaticNoBundle) && !nightly_options::is_nightly_build() { early_error( error_format, "the library kind 'static-nobundle' is only \ @@ -2003,7 +1999,7 @@ crate mod dep_tracking { SymbolManglingVersion, }; use crate::lint; - use crate::utils::NativeLibraryKind; + use crate::utils::NativeLibKind; use rustc_feature::UnstableFeatures; use rustc_span::edition::Edition; use rustc_target::spec::{CodeModel, MergeFunctions, PanicStrategy, RelocModel}; @@ -2062,7 +2058,7 @@ crate mod dep_tracking { impl_dep_tracking_hash_via_hash!(Option); impl_dep_tracking_hash_via_hash!(Option); impl_dep_tracking_hash_via_hash!(Option); - impl_dep_tracking_hash_via_hash!(Option); + impl_dep_tracking_hash_via_hash!(Option); impl_dep_tracking_hash_via_hash!(CrateType); impl_dep_tracking_hash_via_hash!(MergeFunctions); impl_dep_tracking_hash_via_hash!(PanicStrategy); @@ -2073,7 +2069,7 @@ crate mod dep_tracking { impl_dep_tracking_hash_via_hash!(DebugInfo); impl_dep_tracking_hash_via_hash!(UnstableFeatures); impl_dep_tracking_hash_via_hash!(OutputTypes); - impl_dep_tracking_hash_via_hash!(NativeLibraryKind); + impl_dep_tracking_hash_via_hash!(NativeLibKind); impl_dep_tracking_hash_via_hash!(Sanitizer); impl_dep_tracking_hash_via_hash!(Option); impl_dep_tracking_hash_via_hash!(CFGuard); @@ -2088,11 +2084,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, - Option - )); + impl_dep_tracking_hash_for_sortable_vec_of!((String, Option, Option)); impl_dep_tracking_hash_for_sortable_vec_of!((String, u64)); impl_dep_tracking_hash_for_sortable_vec_of!(Sanitizer); diff --git a/src/librustc_session/options.rs b/src/librustc_session/options.rs index a8d213a8663c1..5ac5cf9f6bc6f 100644 --- a/src/librustc_session/options.rs +++ b/src/librustc_session/options.rs @@ -3,7 +3,7 @@ use crate::config::*; use crate::early_error; use crate::lint; use crate::search_paths::SearchPath; -use crate::utils::NativeLibraryKind; +use crate::utils::NativeLibKind; use rustc_target::spec::{CodeModel, LinkerFlavor, MergeFunctions, PanicStrategy}; use rustc_target::spec::{RelocModel, RelroLevel, TargetTriple, TlsModel}; @@ -93,7 +93,7 @@ top_level_options!( describe_lints: bool [UNTRACKED], output_types: OutputTypes [TRACKED], search_paths: Vec [UNTRACKED], - libs: Vec<(String, Option, Option)> [TRACKED], + libs: Vec<(String, Option, Option)> [TRACKED], maybe_sysroot: Option [UNTRACKED], target_triple: TargetTriple [TRACKED], diff --git a/src/librustc_session/utils.rs b/src/librustc_session/utils.rs index fda11b647490f..758a00ecdf612 100644 --- a/src/librustc_session/utils.rs +++ b/src/librustc_session/utils.rs @@ -11,17 +11,19 @@ impl Session { } #[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord, Hash, RustcEncodable, RustcDecodable)] -pub enum NativeLibraryKind { - /// native static library (.a archive) - NativeStatic, - /// native static library, which doesn't get bundled into .rlibs - NativeStaticNobundle, - /// macOS-specific - NativeFramework, - /// Windows dynamic library without import library. - NativeRawDylib, - /// default way to specify a dynamic library - NativeUnknown, +pub enum NativeLibKind { + /// Static library (e.g. `libfoo.a` on Linux or `foo.lib` on Windows/MSVC) included + /// when linking a final binary, but not when archiving an rlib. + StaticNoBundle, + /// Static library (e.g. `libfoo.a` on Linux or `foo.lib` on Windows/MSVC) included + /// when linking a final binary, but also included when archiving an rlib. + StaticBundle, + /// Windows dynamic library (`foo.dll`) without a corresponding import library. + RawDylib, + /// A macOS-specific kind of dynamic libraries. + Framework, + /// The library kind wasn't specified, dynamic linking is currently preferred. + Unspecified, } -rustc_data_structures::impl_stable_hash_via_hash!(NativeLibraryKind); +rustc_data_structures::impl_stable_hash_via_hash!(NativeLibKind); From 529d488f1a8a009fc2dca911b25c82269fadc1d6 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Mon, 18 May 2020 01:37:24 +0300 Subject: [PATCH 2/3] Factor out `NativeLibKind::Dylib` from `NativeLibKind::Unspecified` --- src/librustc_codegen_ssa/back/link.rs | 9 ++++++--- src/librustc_codegen_ssa/base.rs | 2 +- src/librustc_metadata/native_libs.rs | 2 +- src/librustc_metadata/rmeta/decoder/cstore_impl.rs | 4 +++- src/librustc_session/config.rs | 2 +- src/librustc_session/utils.rs | 7 +++++-- 6 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/librustc_codegen_ssa/back/link.rs b/src/librustc_codegen_ssa/back/link.rs index 1e9559f59f1de..afff061468bc3 100644 --- a/src/librustc_codegen_ssa/back/link.rs +++ b/src/librustc_codegen_ssa/back/link.rs @@ -330,6 +330,7 @@ fn link_rlib<'a, B: ArchiveBuilder<'a>>( match lib.kind { NativeLibKind::StaticBundle => {} NativeLibKind::StaticNoBundle + | NativeLibKind::Dylib | NativeLibKind::Framework | NativeLibKind::RawDylib | NativeLibKind::Unspecified => continue, @@ -866,7 +867,9 @@ fn print_native_static_libs(sess: &Session, all_native_libs: &[NativeLib]) { .filter_map(|lib| { let name = lib.name?; match lib.kind { - NativeLibKind::StaticNoBundle | NativeLibKind::Unspecified => { + NativeLibKind::StaticNoBundle + | NativeLibKind::Dylib + | NativeLibKind::Unspecified => { if sess.target.target.options.is_like_msvc { Some(format!("{}.lib", name)) } else { @@ -1648,7 +1651,7 @@ fn add_local_native_libraries( None => continue, }; match lib.kind { - NativeLibKind::Unspecified => cmd.link_dylib(name), + NativeLibKind::Dylib | NativeLibKind::Unspecified => cmd.link_dylib(name), NativeLibKind::Framework => cmd.link_framework(name), NativeLibKind::StaticNoBundle => cmd.link_staticlib(name), NativeLibKind::StaticBundle => cmd.link_whole_staticlib(name, &search_path), @@ -1984,7 +1987,7 @@ fn add_upstream_native_libraries( continue; } match lib.kind { - NativeLibKind::Unspecified => cmd.link_dylib(name), + NativeLibKind::Dylib | NativeLibKind::Unspecified => cmd.link_dylib(name), NativeLibKind::Framework => cmd.link_framework(name), NativeLibKind::StaticNoBundle => { // Link "static-nobundle" native libs only if the crate they originate from diff --git a/src/librustc_codegen_ssa/base.rs b/src/librustc_codegen_ssa/base.rs index c6ee43a94c398..ed5448ca8bac4 100644 --- a/src/librustc_codegen_ssa/base.rs +++ b/src/librustc_codegen_ssa/base.rs @@ -896,7 +896,7 @@ pub fn provide_both(providers: &mut Providers<'_>) { .native_libraries(krate) .iter() .filter(|lib| { - if lib.kind != NativeLibKind::Unspecified { + if !matches!(lib.kind, NativeLibKind::Dylib | NativeLibKind::Unspecified) { return false; } let cfg = match lib.cfg { diff --git a/src/librustc_metadata/native_libs.rs b/src/librustc_metadata/native_libs.rs index a822aec817f00..68ad987065710 100644 --- a/src/librustc_metadata/native_libs.rs +++ b/src/librustc_metadata/native_libs.rs @@ -67,7 +67,7 @@ impl ItemLikeVisitor<'tcx> for Collector<'tcx> { lib.kind = match &*kind.as_str() { "static" => NativeLibKind::StaticBundle, "static-nobundle" => NativeLibKind::StaticNoBundle, - "dylib" => NativeLibKind::Unspecified, + "dylib" => NativeLibKind::Dylib, "framework" => NativeLibKind::Framework, "raw-dylib" => NativeLibKind::RawDylib, k => { diff --git a/src/librustc_metadata/rmeta/decoder/cstore_impl.rs b/src/librustc_metadata/rmeta/decoder/cstore_impl.rs index 6b8072ec49ab5..1b168bf01178c 100644 --- a/src/librustc_metadata/rmeta/decoder/cstore_impl.rs +++ b/src/librustc_metadata/rmeta/decoder/cstore_impl.rs @@ -247,7 +247,9 @@ pub fn provide(providers: &mut Providers<'_>) { // resolve! Does this work? Unsure! That's what the issue is about *providers = Providers { is_dllimport_foreign_item: |tcx, id| match tcx.native_library_kind(id) { - Some(NativeLibKind::Unspecified | NativeLibKind::RawDylib) => true, + Some(NativeLibKind::Dylib | NativeLibKind::RawDylib | NativeLibKind::Unspecified) => { + true + } _ => false, }, is_statically_included_foreign_item: |tcx, id| match tcx.native_library_kind(id) { diff --git a/src/librustc_session/config.rs b/src/librustc_session/config.rs index 405a058ffab60..1aac639f9236e 100644 --- a/src/librustc_session/config.rs +++ b/src/librustc_session/config.rs @@ -1463,7 +1463,7 @@ fn parse_libs( let kind = parts.next().unwrap(); let (name, kind) = match (parts.next(), kind) { (None, name) => (name, None), - (Some(name), "dylib") => (name, Some(NativeLibKind::Unspecified)), + (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)), diff --git a/src/librustc_session/utils.rs b/src/librustc_session/utils.rs index 758a00ecdf612..b97308c22cb7d 100644 --- a/src/librustc_session/utils.rs +++ b/src/librustc_session/utils.rs @@ -18,11 +18,14 @@ pub enum NativeLibKind { /// Static library (e.g. `libfoo.a` on Linux or `foo.lib` on Windows/MSVC) included /// when linking a final binary, but also included when archiving an rlib. StaticBundle, - /// Windows dynamic library (`foo.dll`) without a corresponding import library. + /// Dynamic library (e.g. `libfoo.so` on Linux) + /// or an import library corresponding to a dynamic library (e.g. `foo.lib` on Windows/MSVC). + Dylib, + /// Dynamic library (e.g. `foo.dll` on Windows) without a corresponding import library. RawDylib, /// A macOS-specific kind of dynamic libraries. Framework, - /// The library kind wasn't specified, dynamic linking is currently preferred. + /// The library kind wasn't specified, `Dylib` is currently used as a default. Unspecified, } From 8dbe4d9ba4c5cd30e12179bc51c03fafd551914a Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Mon, 18 May 2020 01:52:34 +0300 Subject: [PATCH 3/3] Eliminate some `Option`s --- src/librustc_interface/tests.rs | 42 ++++++++++++++-------------- src/librustc_metadata/native_libs.rs | 6 ++-- src/librustc_session/config.rs | 17 ++++++----- src/librustc_session/options.rs | 2 +- 4 files changed, 33 insertions(+), 34 deletions(-) diff --git a/src/librustc_interface/tests.rs b/src/librustc_interface/tests.rs index 3b89ceff447fe..0394821d09569 100644 --- a/src/librustc_interface/tests.rs +++ b/src/librustc_interface/tests.rs @@ -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()); @@ -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()); diff --git a/src/librustc_metadata/native_libs.rs b/src/librustc_metadata/native_libs.rs index 68ad987065710..fc4235a3eda09 100644 --- a/src/librustc_metadata/native_libs.rs +++ b/src/librustc_metadata/native_libs.rs @@ -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)); @@ -258,7 +258,7 @@ impl Collector<'tcx> { let new_name = new_name.as_ref().map(|s| &**s); // &Option -> 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, diff --git a/src/librustc_session/config.rs b/src/librustc_session/config.rs index 1aac639f9236e..5bdd7b67723b8 100644 --- a/src/librustc_session/config.rs +++ b/src/librustc_session/config.rs @@ -1452,7 +1452,7 @@ fn select_debuginfo( fn parse_libs( matches: &getopts::Matches, error_format: ErrorOutputType, -) -> Vec<(String, Option, Option)> { +) -> Vec<(String, Option, NativeLibKind)> { matches .opt_strs("l") .into_iter() @@ -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, @@ -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 \ @@ -2058,7 +2058,6 @@ crate mod dep_tracking { impl_dep_tracking_hash_via_hash!(Option); impl_dep_tracking_hash_via_hash!(Option); impl_dep_tracking_hash_via_hash!(Option); - impl_dep_tracking_hash_via_hash!(Option); impl_dep_tracking_hash_via_hash!(CrateType); impl_dep_tracking_hash_via_hash!(MergeFunctions); impl_dep_tracking_hash_via_hash!(PanicStrategy); @@ -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, Option)); + impl_dep_tracking_hash_for_sortable_vec_of!((String, Option, NativeLibKind)); impl_dep_tracking_hash_for_sortable_vec_of!((String, u64)); impl_dep_tracking_hash_for_sortable_vec_of!(Sanitizer); diff --git a/src/librustc_session/options.rs b/src/librustc_session/options.rs index 5ac5cf9f6bc6f..3b6c21e7de008 100644 --- a/src/librustc_session/options.rs +++ b/src/librustc_session/options.rs @@ -93,7 +93,7 @@ top_level_options!( describe_lints: bool [UNTRACKED], output_types: OutputTypes [TRACKED], search_paths: Vec [UNTRACKED], - libs: Vec<(String, Option, Option)> [TRACKED], + libs: Vec<(String, Option, NativeLibKind)> [TRACKED], maybe_sysroot: Option [UNTRACKED], target_triple: TargetTriple [TRACKED],