-
Notifications
You must be signed in to change notification settings - Fork 13.5k
Remove deprecated lang items #44526
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Remove deprecated lang items #44526
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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>, | ||
|
@@ -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(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), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: Extra space after the |
||
_ => None | ||
} | ||
|
||
None | ||
} | ||
|
||
$( | ||
|
@@ -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, | ||
|
@@ -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; | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make this an
ok_or_else
since otherwise we allocate aString
each name, and also go through a lookup table to get the name of the lang item, both of which are somewhat expensive operations to do for lang item lookup.