Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move weak_lang_items checking to librustc_passes.
- Loading branch information
Showing
4 changed files
with
40 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters