Skip to content

Commit 2b6bc58

Browse files
committed
Auto merge of #44526 - leodasvacas:remove-deprecated-lang-items, r=arielb1
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.
2 parents 84bbd14 + 9218e44 commit 2b6bc58

File tree

2 files changed

+15
-49
lines changed

2 files changed

+15
-49
lines changed

src/librustc/middle/lang_items.rs

+15-40
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,14 @@ enum_from_u32! {
4646
}
4747
}
4848

49+
impl LangItem {
50+
fn name(self) -> &'static str {
51+
match self {
52+
$( $variant => $name, )*
53+
}
54+
}
55+
}
56+
4957
pub struct LanguageItems {
5058
pub items: Vec<Option<DefId>>,
5159
pub missing: Vec<LangItem>,
@@ -65,42 +73,17 @@ impl LanguageItems {
6573
&*self.items
6674
}
6775

68-
pub fn item_name(index: usize) -> &'static str {
69-
let item: Option<LangItem> = LangItem::from_u32(index as u32);
70-
match item {
71-
$( Some($variant) => $name, )*
72-
None => "???"
73-
}
74-
}
75-
7676
pub fn require(&self, it: LangItem) -> Result<DefId, String> {
77-
match self.items[it as usize] {
78-
Some(id) => Ok(id),
79-
None => {
80-
Err(format!("requires `{}` lang_item",
81-
LanguageItems::item_name(it as usize)))
82-
}
83-
}
84-
}
85-
86-
pub fn require_owned_box(&self) -> Result<DefId, String> {
87-
self.require(OwnedBoxLangItem)
77+
self.items[it as usize].ok_or_else(|| format!("requires `{}` lang_item", it.name()))
8878
}
8979

9080
pub fn fn_trait_kind(&self, id: DefId) -> Option<ty::ClosureKind> {
91-
let def_id_kinds = [
92-
(self.fn_trait(), ty::ClosureKind::Fn),
93-
(self.fn_mut_trait(), ty::ClosureKind::FnMut),
94-
(self.fn_once_trait(), ty::ClosureKind::FnOnce),
95-
];
96-
97-
for &(opt_def_id, kind) in &def_id_kinds {
98-
if Some(id) == opt_def_id {
99-
return Some(kind);
100-
}
81+
match Some(id) {
82+
x if x == self.fn_trait() => Some(ty::ClosureKind::Fn),
83+
x if x == self.fn_mut_trait() => Some(ty::ClosureKind::FnMut),
84+
x if x == self.fn_once_trait() => Some(ty::ClosureKind::FnOnce),
85+
_ => None
10186
}
102-
103-
None
10487
}
10588

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

328311
PhantomDataItem, "phantom_data", phantom_data;
329312

330-
// Deprecated:
331-
CovariantTypeItem, "covariant_type", covariant_type;
332-
ContravariantTypeItem, "contravariant_type", contravariant_type;
333-
InvariantTypeItem, "invariant_type", invariant_type;
334-
CovariantLifetimeItem, "covariant_lifetime", covariant_lifetime;
335-
ContravariantLifetimeItem, "contravariant_lifetime", contravariant_lifetime;
336-
InvariantLifetimeItem, "invariant_lifetime", invariant_lifetime;
337-
338313
NonZeroItem, "non_zero", non_zero;
339314

340315
DebugTraitLangItem, "debug_trait", debug_trait;

src/librustc_typeck/variance/terms.rs

-9
Original file line numberDiff line numberDiff line change
@@ -98,15 +98,6 @@ fn lang_items(tcx: TyCtxt) -> Vec<(ast::NodeId, Vec<ty::Variance>)> {
9898
let all = vec![
9999
(lang_items.phantom_data(), vec![ty::Covariant]),
100100
(lang_items.unsafe_cell_type(), vec![ty::Invariant]),
101-
102-
// Deprecated:
103-
(lang_items.covariant_type(), vec![ty::Covariant]),
104-
(lang_items.contravariant_type(), vec![ty::Contravariant]),
105-
(lang_items.invariant_type(), vec![ty::Invariant]),
106-
(lang_items.covariant_lifetime(), vec![ty::Covariant]),
107-
(lang_items.contravariant_lifetime(), vec![ty::Contravariant]),
108-
(lang_items.invariant_lifetime(), vec![ty::Invariant]),
109-
110101
];
111102

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

0 commit comments

Comments
 (0)