Skip to content

Commit

Permalink
Rollup merge of rust-lang#68554 - cjgillot:lang_items, r=Zoxc
Browse files Browse the repository at this point in the history
Split lang_items to crates `rustc_hir` and `rustc_passes`.

As discussed in comment rust-lang#67688 (comment)
  • Loading branch information
JohnTitor committed Feb 12, 2020
2 parents 344f8d9 + fc73e19 commit 19b0c00
Show file tree
Hide file tree
Showing 26 changed files with 688 additions and 628 deletions.
1 change: 1 addition & 0 deletions Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -3630,6 +3630,7 @@ version = "0.0.0"
name = "rustc_hir"
version = "0.0.0"
dependencies = [
"lazy_static 1.4.0",
"rustc_ast_pretty",
"rustc_data_structures",
"rustc_errors",
Expand Down
1 change: 0 additions & 1 deletion src/librustc/hir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
//!
//! [rustc guide]: https://rust-lang.github.io/rustc-guide/hir.html

pub mod check_attr;
pub mod exports;
pub mod map;

Expand Down
6 changes: 0 additions & 6 deletions src/librustc/ich/impls_hir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -251,12 +251,6 @@ impl<'a> ToStableHashKey<StableHashingContext<'a>> for hir::def_id::DefIndex {
}
}

impl<'a> HashStable<StableHashingContext<'a>> for crate::middle::lang_items::LangItem {
fn hash_stable(&self, _: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
::std::hash::Hash::hash(self, hasher);
}
}

impl<'a> HashStable<StableHashingContext<'a>> for hir::TraitCandidate {
fn hash_stable(&self, hcx: &mut StableHashingContext<'a>, hasher: &mut StableHasher) {
hcx.with_node_id_hashing_mode(NodeIdHashingMode::HashDefPath, |hcx| {
Expand Down
37 changes: 0 additions & 37 deletions src/librustc/macros.rs
Original file line number Diff line number Diff line change
@@ -1,40 +1,3 @@
macro_rules! enum_from_u32 {
($(#[$attr:meta])* pub enum $name:ident {
$($variant:ident = $e:expr,)*
}) => {
$(#[$attr])*
pub enum $name {
$($variant = $e),*
}

impl $name {
pub fn from_u32(u: u32) -> Option<$name> {
$(if u == $name::$variant as u32 {
return Some($name::$variant)
})*
None
}
}
};
($(#[$attr:meta])* pub enum $name:ident {
$($variant:ident,)*
}) => {
$(#[$attr])*
pub enum $name {
$($variant,)*
}

impl $name {
pub fn from_u32(u: u32) -> Option<$name> {
$(if u == $name::$variant as u32 {
return Some($name::$variant)
})*
None
}
}
}
}

#[macro_export]
macro_rules! bug {
() => ( bug!("impossible case reached") );
Expand Down
425 changes: 35 additions & 390 deletions src/librustc/middle/lang_items.rs

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion src/librustc/middle/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,3 @@ pub mod recursion_limit;
pub mod region;
pub mod resolve_lifetime;
pub mod stability;
pub mod weak_lang_items;
167 changes: 0 additions & 167 deletions src/librustc/middle/weak_lang_items.rs

This file was deleted.

7 changes: 3 additions & 4 deletions src/librustc/traits/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1634,7 +1634,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
obligation: &TraitObligation<'tcx>,
candidates: &mut SelectionCandidateSet<'tcx>,
) -> Result<(), SelectionError<'tcx>> {
let kind = match self.tcx().lang_items().fn_trait_kind(obligation.predicate.def_id()) {
let kind = match self.tcx().fn_trait_kind_from_lang_item(obligation.predicate.def_id()) {
Some(k) => k,
None => {
return Ok(());
Expand Down Expand Up @@ -1677,7 +1677,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
candidates: &mut SelectionCandidateSet<'tcx>,
) -> Result<(), SelectionError<'tcx>> {
// We provide impl of all fn traits for fn pointers.
if self.tcx().lang_items().fn_trait_kind(obligation.predicate.def_id()).is_none() {
if self.tcx().fn_trait_kind_from_lang_item(obligation.predicate.def_id()).is_none() {
return Ok(());
}

Expand Down Expand Up @@ -2889,8 +2889,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {

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

// Okay to skip binder because the substs on closure types never
Expand Down
4 changes: 0 additions & 4 deletions src/librustc/ty/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2716,10 +2716,6 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) {
assert_eq!(id, LOCAL_CRATE);
tcx.crate_name
};
providers.get_lang_items = |tcx, id| {
assert_eq!(id, LOCAL_CRATE);
tcx.arena.alloc(middle::lang_items::collect(tcx))
};
providers.maybe_unused_trait_import = |tcx, id| tcx.maybe_unused_trait_imports.contains(&id);
providers.maybe_unused_extern_crates = |tcx, cnum| {
assert_eq!(cnum, LOCAL_CRATE);
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ fn resolve_associated_item<'tcx>(
substs: generator_data.substs,
}),
traits::VtableClosure(closure_data) => {
let trait_closure_kind = tcx.lang_items().fn_trait_kind(trait_id).unwrap();
let trait_closure_kind = tcx.fn_trait_kind_from_lang_item(trait_id).unwrap();
Some(Instance::resolve_closure(
tcx,
closure_data.closure_def_id,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ pub trait PrettyPrinter<'tcx>:
let mut resugared = false;

// Special-case `Fn(...) -> ...` and resugar it.
let fn_trait_kind = self.tcx().lang_items().fn_trait_kind(principal.def_id);
let fn_trait_kind = self.tcx().fn_trait_kind_from_lang_item(principal.def_id);
if !self.tcx().sess.verbose() && fn_trait_kind.is_some() {
if let ty::Tuple(ref args) = principal.substs.type_at(0).kind {
let mut projections = predicates.projection_bounds();
Expand Down
9 changes: 3 additions & 6 deletions src/librustc_codegen_ssa/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ use crate::{CachedModuleCodegen, CrateInfo, MemFlags, ModuleCodegen, ModuleKind}
use rustc::middle::codegen_fn_attrs::CodegenFnAttrs;
use rustc::middle::cstore::EncodedMetadata;
use rustc::middle::cstore::{self, LinkagePreference};
use rustc::middle::lang_items;
use rustc::middle::lang_items::StartFnLangItem;
use rustc::middle::weak_lang_items;
use rustc::mir::mono::{CodegenUnit, CodegenUnitNameBuilder, MonoItem};
use rustc::session::config::{self, EntryFnType, Lto};
use rustc::session::Session;
Expand Down Expand Up @@ -847,11 +847,8 @@ impl CrateInfo {

// No need to look for lang items that are whitelisted and don't
// actually need to exist.
let missing = missing
.iter()
.cloned()
.filter(|&l| !weak_lang_items::whitelisted(tcx, l))
.collect();
let missing =
missing.iter().cloned().filter(|&l| !lang_items::whitelisted(tcx, l)).collect();
info.missing_lang_items.insert(cnum, missing);
}

Expand Down
38 changes: 38 additions & 0 deletions src/librustc_data_structures/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,41 @@ macro_rules! static_assert_size {
const _: [(); $size] = [(); ::std::mem::size_of::<$ty>()];
};
}

#[macro_export]
macro_rules! enum_from_u32 {
($(#[$attr:meta])* pub enum $name:ident {
$($variant:ident = $e:expr,)*
}) => {
$(#[$attr])*
pub enum $name {
$($variant = $e),*
}

impl $name {
pub fn from_u32(u: u32) -> Option<$name> {
$(if u == $name::$variant as u32 {
return Some($name::$variant)
})*
None
}
}
};
($(#[$attr:meta])* pub enum $name:ident {
$($variant:ident,)*
}) => {
$(#[$attr])*
pub enum $name {
$($variant,)*
}

impl $name {
pub fn from_u32(u: u32) -> Option<$name> {
$(if u == $name::$variant as u32 {
return Some($name::$variant)
})*
None
}
}
}
}
1 change: 1 addition & 0 deletions src/librustc_hir/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ rustc_span = { path = "../librustc_span" }
rustc_errors = { path = "../librustc_errors" }
rustc_serialize = { path = "../libserialize", package = "serialize" }
syntax = { path = "../libsyntax" }
lazy_static = "1"
smallvec = { version = "1.0", features = ["union", "may_dangle"] }
Loading

0 comments on commit 19b0c00

Please sign in to comment.