Skip to content

Commit

Permalink
Auto merge of #44526 - leodasvacas:remove-deprecated-lang-items, r=ar…
Browse files Browse the repository at this point in the history
…ielb1

Remove deprecated lang items

They have been deprecated for years and there is no trace left of them in the compiler. Also removed `require_owned_box` which is dead code and other small refactorings.
  • Loading branch information
bors committed Sep 14, 2017
2 parents 84bbd14 + 9218e44 commit 2b6bc58
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 49 deletions.
55 changes: 15 additions & 40 deletions src/librustc/middle/lang_items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ enum_from_u32! {
}
}

impl LangItem {
fn name(self) -> &'static str {
match self {
$( $variant => $name, )*
}
}
}

pub struct LanguageItems {
pub items: Vec<Option<DefId>>,
pub missing: Vec<LangItem>,
Expand All @@ -65,42 +73,17 @@ impl LanguageItems {
&*self.items
}

pub fn item_name(index: usize) -> &'static str {
let item: Option<LangItem> = LangItem::from_u32(index as u32);
match item {
$( Some($variant) => $name, )*
None => "???"
}
}

pub fn require(&self, it: LangItem) -> Result<DefId, String> {
match self.items[it as usize] {
Some(id) => Ok(id),
None => {
Err(format!("requires `{}` lang_item",
LanguageItems::item_name(it as usize)))
}
}
}

pub fn require_owned_box(&self) -> Result<DefId, String> {
self.require(OwnedBoxLangItem)
self.items[it as usize].ok_or_else(|| format!("requires `{}` lang_item", it.name()))
}

pub fn fn_trait_kind(&self, id: DefId) -> Option<ty::ClosureKind> {
let def_id_kinds = [
(self.fn_trait(), ty::ClosureKind::Fn),
(self.fn_mut_trait(), ty::ClosureKind::FnMut),
(self.fn_once_trait(), ty::ClosureKind::FnOnce),
];

for &(opt_def_id, kind) in &def_id_kinds {
if Some(id) == opt_def_id {
return Some(kind);
}
match Some(id) {
x if x == self.fn_trait() => Some(ty::ClosureKind::Fn),
x if x == self.fn_mut_trait() => Some(ty::ClosureKind::FnMut),
x if x == self.fn_once_trait() => Some(ty::ClosureKind::FnOnce),
_ => None
}

None
}

$(
Expand Down Expand Up @@ -162,7 +145,7 @@ impl<'a, 'tcx> LanguageItemCollector<'a, 'tcx> {
// Check for duplicates.
match self.items.items[item_index] {
Some(original_def_id) if original_def_id != item_def_id => {
let name = LanguageItems::item_name(item_index);
let name = LangItem::from_u32(item_index as u32).unwrap().name();
let mut err = match self.tcx.hir.span_if_local(item_def_id) {
Some(span) => struct_span_err!(
self.tcx.sess,
Expand Down Expand Up @@ -327,14 +310,6 @@ language_item_table! {

PhantomDataItem, "phantom_data", phantom_data;

// Deprecated:
CovariantTypeItem, "covariant_type", covariant_type;
ContravariantTypeItem, "contravariant_type", contravariant_type;
InvariantTypeItem, "invariant_type", invariant_type;
CovariantLifetimeItem, "covariant_lifetime", covariant_lifetime;
ContravariantLifetimeItem, "contravariant_lifetime", contravariant_lifetime;
InvariantLifetimeItem, "invariant_lifetime", invariant_lifetime;

NonZeroItem, "non_zero", non_zero;

DebugTraitLangItem, "debug_trait", debug_trait;
Expand Down
9 changes: 0 additions & 9 deletions src/librustc_typeck/variance/terms.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,6 @@ fn lang_items(tcx: TyCtxt) -> Vec<(ast::NodeId, Vec<ty::Variance>)> {
let all = vec![
(lang_items.phantom_data(), vec![ty::Covariant]),
(lang_items.unsafe_cell_type(), vec![ty::Invariant]),

// Deprecated:
(lang_items.covariant_type(), vec![ty::Covariant]),
(lang_items.contravariant_type(), vec![ty::Contravariant]),
(lang_items.invariant_type(), vec![ty::Invariant]),
(lang_items.covariant_lifetime(), vec![ty::Covariant]),
(lang_items.contravariant_lifetime(), vec![ty::Contravariant]),
(lang_items.invariant_lifetime(), vec![ty::Invariant]),

];

all.into_iter() // iterating over (Option<DefId>, Variance)
Expand Down

0 comments on commit 2b6bc58

Please sign in to comment.