Skip to content

Commit 19b0c00

Browse files
authored
Rollup merge of rust-lang#68554 - cjgillot:lang_items, r=Zoxc
Split lang_items to crates `rustc_hir` and `rustc_passes`. As discussed in comment rust-lang#67688 (comment)
2 parents 344f8d9 + fc73e19 commit 19b0c00

File tree

26 files changed

+688
-628
lines changed

26 files changed

+688
-628
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -3630,6 +3630,7 @@ version = "0.0.0"
36303630
name = "rustc_hir"
36313631
version = "0.0.0"
36323632
dependencies = [
3633+
"lazy_static 1.4.0",
36333634
"rustc_ast_pretty",
36343635
"rustc_data_structures",
36353636
"rustc_errors",

src/librustc/hir/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
//!
33
//! [rustc guide]: https://rust-lang.github.io/rustc-guide/hir.html
44
5-
pub mod check_attr;
65
pub mod exports;
76
pub mod map;
87

src/librustc/ich/impls_hir.rs

-6
Original file line numberDiff line numberDiff line change
@@ -251,12 +251,6 @@ impl<'a> ToStableHashKey<StableHashingContext<'a>> for hir::def_id::DefIndex {
251251
}
252252
}
253253

254-
impl<'a> HashStable<StableHashingContext<'a>> for crate::middle::lang_items::LangItem {
255-
fn hash_stable(&self, _: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
256-
::std::hash::Hash::hash(self, hasher);
257-
}
258-
}
259-
260254
impl<'a> HashStable<StableHashingContext<'a>> for hir::TraitCandidate {
261255
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
262256
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {

src/librustc/macros.rs

-37
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,3 @@
1-
macro_rules! enum_from_u32 {
2-
($(#[$attr:meta])* pub enum $name:ident {
3-
$($variant:ident = $e:expr,)*
4-
}) => {
5-
$(#[$attr])*
6-
pub enum $name {
7-
$($variant = $e),*
8-
}
9-
10-
impl $name {
11-
pub fn from_u32(u: u32) -> Option<$name> {
12-
$(if u == $name::$variant as u32 {
13-
return Some($name::$variant)
14-
})*
15-
None
16-
}
17-
}
18-
};
19-
($(#[$attr:meta])* pub enum $name:ident {
20-
$($variant:ident,)*
21-
}) => {
22-
$(#[$attr])*
23-
pub enum $name {
24-
$($variant,)*
25-
}
26-
27-
impl $name {
28-
pub fn from_u32(u: u32) -> Option<$name> {
29-
$(if u == $name::$variant as u32 {
30-
return Some($name::$variant)
31-
})*
32-
None
33-
}
34-
}
35-
}
36-
}
37-
381
#[macro_export]
392
macro_rules! bug {
403
() => ( bug!("impossible case reached") );

src/librustc/middle/lang_items.rs

+35-390
Large diffs are not rendered by default.

src/librustc/middle/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,3 @@ pub mod recursion_limit;
3333
pub mod region;
3434
pub mod resolve_lifetime;
3535
pub mod stability;
36-
pub mod weak_lang_items;

src/librustc/middle/weak_lang_items.rs

-167
This file was deleted.

src/librustc/traits/select.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -1634,7 +1634,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16341634
obligation: &TraitObligation<'tcx>,
16351635
candidates: &mut SelectionCandidateSet<'tcx>,
16361636
) -> Result<(), SelectionError<'tcx>> {
1637-
let kind = match self.tcx().lang_items().fn_trait_kind(obligation.predicate.def_id()) {
1637+
let kind = match self.tcx().fn_trait_kind_from_lang_item(obligation.predicate.def_id()) {
16381638
Some(k) => k,
16391639
None => {
16401640
return Ok(());
@@ -1677,7 +1677,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16771677
candidates: &mut SelectionCandidateSet<'tcx>,
16781678
) -> Result<(), SelectionError<'tcx>> {
16791679
// We provide impl of all fn traits for fn pointers.
1680-
if self.tcx().lang_items().fn_trait_kind(obligation.predicate.def_id()).is_none() {
1680+
if self.tcx().fn_trait_kind_from_lang_item(obligation.predicate.def_id()).is_none() {
16811681
return Ok(());
16821682
}
16831683

@@ -2889,8 +2889,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
28892889

28902890
let kind = self
28912891
.tcx()
2892-
.lang_items()
2893-
.fn_trait_kind(obligation.predicate.def_id())
2892+
.fn_trait_kind_from_lang_item(obligation.predicate.def_id())
28942893
.unwrap_or_else(|| bug!("closure candidate for non-fn trait {:?}", obligation));
28952894

28962895
// Okay to skip binder because the substs on closure types never

src/librustc/ty/context.rs

-4
Original file line numberDiff line numberDiff line change
@@ -2716,10 +2716,6 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
27162716
assert_eq!(id, LOCAL_CRATE);
27172717
tcx.crate_name
27182718
};
2719-
providers.get_lang_items = |tcx, id| {
2720-
assert_eq!(id, LOCAL_CRATE);
2721-
tcx.arena.alloc(middle::lang_items::collect(tcx))
2722-
};
27232719
providers.maybe_unused_trait_import = |tcx, id| tcx.maybe_unused_trait_imports.contains(&id);
27242720
providers.maybe_unused_extern_crates = |tcx, cnum| {
27252721
assert_eq!(cnum, LOCAL_CRATE);

src/librustc/ty/instance.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -450,7 +450,7 @@ fn resolve_associated_item<'tcx>(
450450
substs: generator_data.substs,
451451
}),
452452
traits::VtableClosure(closure_data) => {
453-
let trait_closure_kind = tcx.lang_items().fn_trait_kind(trait_id).unwrap();
453+
let trait_closure_kind = tcx.fn_trait_kind_from_lang_item(trait_id).unwrap();
454454
Some(Instance::resolve_closure(
455455
tcx,
456456
closure_data.closure_def_id,

src/librustc/ty/print/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ pub trait PrettyPrinter<'tcx>:
724724
let mut resugared = false;
725725

726726
// Special-case `Fn(...) -> ...` and resugar it.
727-
let fn_trait_kind = self.tcx().lang_items().fn_trait_kind(principal.def_id);
727+
let fn_trait_kind = self.tcx().fn_trait_kind_from_lang_item(principal.def_id);
728728
if !self.tcx().sess.verbose() && fn_trait_kind.is_some() {
729729
if let ty::Tuple(ref args) = principal.substs.type_at(0).kind {
730730
let mut projections = predicates.projection_bounds();

src/librustc_codegen_ssa/base.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ use crate::{CachedModuleCodegen, CrateInfo, MemFlags, ModuleCodegen, ModuleKind}
2828
use rustc::middle::codegen_fn_attrs::CodegenFnAttrs;
2929
use rustc::middle::cstore::EncodedMetadata;
3030
use rustc::middle::cstore::{self, LinkagePreference};
31+
use rustc::middle::lang_items;
3132
use rustc::middle::lang_items::StartFnLangItem;
32-
use rustc::middle::weak_lang_items;
3333
use rustc::mir::mono::{CodegenUnit, CodegenUnitNameBuilder, MonoItem};
3434
use rustc::session::config::{self, EntryFnType, Lto};
3535
use rustc::session::Session;
@@ -847,11 +847,8 @@ impl CrateInfo {
847847

848848
// No need to look for lang items that are whitelisted and don't
849849
// actually need to exist.
850-
let missing = missing
851-
.iter()
852-
.cloned()
853-
.filter(|&l| !weak_lang_items::whitelisted(tcx, l))
854-
.collect();
850+
let missing =
851+
missing.iter().cloned().filter(|&l| !lang_items::whitelisted(tcx, l)).collect();
855852
info.missing_lang_items.insert(cnum, missing);
856853
}
857854

src/librustc_data_structures/macros.rs

+38
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,41 @@ macro_rules! static_assert_size {
1717
const _: [(); $size] = [(); ::std::mem::size_of::<$ty>()];
1818
};
1919
}
20+
21+
#[macro_export]
22+
macro_rules! enum_from_u32 {
23+
($(#[$attr:meta])* pub enum $name:ident {
24+
$($variant:ident = $e:expr,)*
25+
}) => {
26+
$(#[$attr])*
27+
pub enum $name {
28+
$($variant = $e),*
29+
}
30+
31+
impl $name {
32+
pub fn from_u32(u: u32) -> Option<$name> {
33+
$(if u == $name::$variant as u32 {
34+
return Some($name::$variant)
35+
})*
36+
None
37+
}
38+
}
39+
};
40+
($(#[$attr:meta])* pub enum $name:ident {
41+
$($variant:ident,)*
42+
}) => {
43+
$(#[$attr])*
44+
pub enum $name {
45+
$($variant,)*
46+
}
47+
48+
impl $name {
49+
pub fn from_u32(u: u32) -> Option<$name> {
50+
$(if u == $name::$variant as u32 {
51+
return Some($name::$variant)
52+
})*
53+
None
54+
}
55+
}
56+
}
57+
}

src/librustc_hir/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ rustc_span = { path = "../librustc_span" }
1919
rustc_errors = { path = "../librustc_errors" }
2020
rustc_serialize = { path = "../libserialize", package = "serialize" }
2121
syntax = { path = "../libsyntax" }
22+
lazy_static = "1"
2223
smallvec = { version = "1.0", features = ["union", "may_dangle"] }

0 commit comments

Comments
 (0)