diff options
| author | Camille GILLOT <gillot.camille@gmail.com> | 2019-12-28 18:31:37 +0100 |
|---|---|---|
| committer | Camille GILLOT <gillot.camille@gmail.com> | 2020-02-11 23:13:03 +0100 |
| commit | b6f875d678de6c3e19bdb87d99f9cff189a96e54 (patch) | |
| tree | 17743ea2aeeeae059f3000ae8aea5718cf15a928 | |
| parent | 98b46f77969316e0f80f60c29c4121db8b3735c4 (diff) | |
| download | rust-b6f875d678de6c3e19bdb87d99f9cff189a96e54.tar.gz rust-b6f875d678de6c3e19bdb87d99f9cff189a96e54.zip | |
Move weak_lang_items checking to librustc_passes.
| -rw-r--r-- | src/librustc/middle/weak_lang_items.rs | 32 | ||||
| -rw-r--r-- | src/librustc_passes/lang_items.rs | 3 | ||||
| -rw-r--r-- | src/librustc_passes/lib.rs | 1 | ||||
| -rw-r--r-- | src/librustc_passes/weak_lang_items.rs | 37 |
4 files changed, 40 insertions, 33 deletions
diff --git a/src/librustc/middle/weak_lang_items.rs b/src/librustc/middle/weak_lang_items.rs new file mode 100644 index 00000000000..c59c1953111 --- /dev/null +++ b/src/librustc/middle/weak_lang_items.rs @@ -0,0 +1,32 @@ +//! Validity checking for weak lang items + +use crate::ty::TyCtxt; +use rustc_hir::def_id::DefId; +use rustc_lang_items::{lang_items, LangItem}; +use rustc_target::spec::PanicStrategy; + +pub use rustc_lang_items::weak_lang_items::link_name; + +impl<'tcx> TyCtxt<'tcx> { + pub fn is_weak_lang_item(&self, item_def_id: DefId) -> bool { + self.lang_items().is_weak_lang_item(item_def_id) + } +} + +/// Returns `true` if the specified `lang_item` doesn't actually need to be +/// present for this compilation. +/// +/// Not all lang items are always required for each compilation, particularly in +/// the case of panic=abort. In these situations some lang items are injected by +/// crates and don't actually need to be defined in libstd. +pub fn whitelisted(tcx: TyCtxt<'_>, lang_item: LangItem) -> bool { + // If we're not compiling with unwinding, we won't actually need these + // symbols. Other panic runtimes ensure that the relevant symbols are + // available to link things together, but they're never exercised. + if tcx.sess.panic_strategy() != PanicStrategy::Unwind { + return lang_item == lang_items::EhPersonalityLangItem + || lang_item == lang_items::EhUnwindResumeLangItem; + } + + false +} diff --git a/src/librustc_passes/lang_items.rs b/src/librustc_passes/lang_items.rs index d964777bd7c..ea5ff000512 100644 --- a/src/librustc_passes/lang_items.rs +++ b/src/librustc_passes/lang_items.rs @@ -7,8 +7,9 @@ //! * Traits that represent operators; e.g., `Add`, `Sub`, `Index`. //! * Functions called by the compiler itself. +use crate::weak_lang_items; + use rustc::middle::cstore::ExternCrate; -use rustc::middle::weak_lang_items; use rustc::ty::TyCtxt; use rustc_errors::struct_span_err; diff --git a/src/librustc_passes/lib.rs b/src/librustc_passes/lib.rs index d0b1c70be65..afafbacb8fa 100644 --- a/src/librustc_passes/lib.rs +++ b/src/librustc_passes/lib.rs @@ -32,6 +32,7 @@ mod reachable; mod region; pub mod stability; mod upvars; +mod weak_lang_items; pub fn provide(providers: &mut Providers<'_>) { check_attr::provide(providers); diff --git a/src/librustc_passes/weak_lang_items.rs b/src/librustc_passes/weak_lang_items.rs index ab19483a62d..a579b9354d7 100644 --- a/src/librustc_passes/weak_lang_items.rs +++ b/src/librustc_passes/weak_lang_items.rs @@ -1,21 +1,18 @@ //! Validity checking for weak lang items -use crate::middle::lang_items; -use crate::session::config; +use rustc::middle::lang_items; +use rustc::middle::weak_lang_items::whitelisted; +use rustc::session::config; -use crate::hir::map::Map; -use crate::ty::TyCtxt; +use rustc::hir::map::Map; +use rustc::ty::TyCtxt; use rustc_data_structures::fx::FxHashSet; use rustc_errors::struct_span_err; use rustc_hir as hir; -use rustc_hir::def_id::DefId; use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor}; use rustc_lang_items::weak_lang_items::WEAK_ITEMS_REFS; use rustc_span::symbol::Symbol; use rustc_span::Span; -use rustc_target::spec::PanicStrategy; - -pub use rustc_lang_items::weak_lang_items::link_name; struct Context<'a, 'tcx> { tcx: TyCtxt<'tcx>, @@ -42,24 +39,6 @@ pub fn check_crate<'tcx>(tcx: TyCtxt<'tcx>, items: &mut lang_items::LanguageItem verify(tcx, items); } -/// Returns `true` if the specified `lang_item` doesn't actually need to be -/// present for this compilation. -/// -/// Not all lang items are always required for each compilation, particularly in -/// the case of panic=abort. In these situations some lang items are injected by -/// crates and don't actually need to be defined in libstd. -pub fn whitelisted(tcx: TyCtxt<'_>, lang_item: lang_items::LangItem) -> bool { - // If we're not compiling with unwinding, we won't actually need these - // symbols. Other panic runtimes ensure that the relevant symbols are - // available to link things together, but they're never exercised. - if tcx.sess.panic_strategy() != PanicStrategy::Unwind { - return lang_item == lang_items::EhPersonalityLangItem - || lang_item == lang_items::EhUnwindResumeLangItem; - } - - false -} - fn verify<'tcx>(tcx: TyCtxt<'tcx>, items: &lang_items::LanguageItems) { // We only need to check for the presence of weak lang items if we're // emitting something that's not an rlib. @@ -122,9 +101,3 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> { intravisit::walk_foreign_item(self, i) } } - -impl<'tcx> TyCtxt<'tcx> { - pub fn is_weak_lang_item(&self, item_def_id: DefId) -> bool { - self.lang_items().is_weak_lang_item(item_def_id) - } -} |
