Skip to content

Commit b6f875d

Browse files
committed
Move weak_lang_items checking to librustc_passes.
1 parent 98b46f7 commit b6f875d

File tree

4 files changed

+40
-33
lines changed

4 files changed

+40
-33
lines changed
+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//! Validity checking for weak lang items
2+
3+
use crate::ty::TyCtxt;
4+
use rustc_hir::def_id::DefId;
5+
use rustc_lang_items::{lang_items, LangItem};
6+
use rustc_target::spec::PanicStrategy;
7+
8+
pub use rustc_lang_items::weak_lang_items::link_name;
9+
10+
impl<'tcx> TyCtxt<'tcx> {
11+
pub fn is_weak_lang_item(&self, item_def_id: DefId) -> bool {
12+
self.lang_items().is_weak_lang_item(item_def_id)
13+
}
14+
}
15+
16+
/// Returns `true` if the specified `lang_item` doesn't actually need to be
17+
/// present for this compilation.
18+
///
19+
/// Not all lang items are always required for each compilation, particularly in
20+
/// the case of panic=abort. In these situations some lang items are injected by
21+
/// crates and don't actually need to be defined in libstd.
22+
pub fn whitelisted(tcx: TyCtxt<'_>, lang_item: LangItem) -> bool {
23+
// If we're not compiling with unwinding, we won't actually need these
24+
// symbols. Other panic runtimes ensure that the relevant symbols are
25+
// available to link things together, but they're never exercised.
26+
if tcx.sess.panic_strategy() != PanicStrategy::Unwind {
27+
return lang_item == lang_items::EhPersonalityLangItem
28+
|| lang_item == lang_items::EhUnwindResumeLangItem;
29+
}
30+
31+
false
32+
}

src/librustc_passes/lang_items.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,9 @@
77
//! * Traits that represent operators; e.g., `Add`, `Sub`, `Index`.
88
//! * Functions called by the compiler itself.
99
10+
use crate::weak_lang_items;
11+
1012
use rustc::middle::cstore::ExternCrate;
11-
use rustc::middle::weak_lang_items;
1213
use rustc::ty::TyCtxt;
1314

1415
use rustc_errors::struct_span_err;

src/librustc_passes/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ mod reachable;
3232
mod region;
3333
pub mod stability;
3434
mod upvars;
35+
mod weak_lang_items;
3536

3637
pub fn provide(providers: &mut Providers<'_>) {
3738
check_attr::provide(providers);

src/librustc_passes/weak_lang_items.rs

+5-32
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
11
//! Validity checking for weak lang items
22
3-
use crate::middle::lang_items;
4-
use crate::session::config;
3+
use rustc::middle::lang_items;
4+
use rustc::middle::weak_lang_items::whitelisted;
5+
use rustc::session::config;
56

6-
use crate::hir::map::Map;
7-
use crate::ty::TyCtxt;
7+
use rustc::hir::map::Map;
8+
use rustc::ty::TyCtxt;
89
use rustc_data_structures::fx::FxHashSet;
910
use rustc_errors::struct_span_err;
1011
use rustc_hir as hir;
11-
use rustc_hir::def_id::DefId;
1212
use rustc_hir::intravisit::{self, NestedVisitorMap, Visitor};
1313
use rustc_lang_items::weak_lang_items::WEAK_ITEMS_REFS;
1414
use rustc_span::symbol::Symbol;
1515
use rustc_span::Span;
16-
use rustc_target::spec::PanicStrategy;
17-
18-
pub use rustc_lang_items::weak_lang_items::link_name;
1916

2017
struct Context<'a, 'tcx> {
2118
tcx: TyCtxt<'tcx>,
@@ -42,24 +39,6 @@ pub fn check_crate<'tcx>(tcx: TyCtxt<'tcx>, items: &mut lang_items::LanguageItem
4239
verify(tcx, items);
4340
}
4441

45-
/// Returns `true` if the specified `lang_item` doesn't actually need to be
46-
/// present for this compilation.
47-
///
48-
/// Not all lang items are always required for each compilation, particularly in
49-
/// the case of panic=abort. In these situations some lang items are injected by
50-
/// crates and don't actually need to be defined in libstd.
51-
pub fn whitelisted(tcx: TyCtxt<'_>, lang_item: lang_items::LangItem) -> bool {
52-
// If we're not compiling with unwinding, we won't actually need these
53-
// symbols. Other panic runtimes ensure that the relevant symbols are
54-
// available to link things together, but they're never exercised.
55-
if tcx.sess.panic_strategy() != PanicStrategy::Unwind {
56-
return lang_item == lang_items::EhPersonalityLangItem
57-
|| lang_item == lang_items::EhUnwindResumeLangItem;
58-
}
59-
60-
false
61-
}
62-
6342
fn verify<'tcx>(tcx: TyCtxt<'tcx>, items: &lang_items::LanguageItems) {
6443
// We only need to check for the presence of weak lang items if we're
6544
// emitting something that's not an rlib.
@@ -122,9 +101,3 @@ impl<'a, 'tcx, 'v> Visitor<'v> for Context<'a, 'tcx> {
122101
intravisit::walk_foreign_item(self, i)
123102
}
124103
}
125-
126-
impl<'tcx> TyCtxt<'tcx> {
127-
pub fn is_weak_lang_item(&self, item_def_id: DefId) -> bool {
128-
self.lang_items().is_weak_lang_item(item_def_id)
129-
}
130-
}

0 commit comments

Comments
 (0)