diff options
| author | bors <bors@rust-lang.org> | 2022-10-31 12:07:07 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2022-10-31 12:07:07 +0000 |
| commit | 2afca78a0b03db144c5d8b9f8868feebfe096309 (patch) | |
| tree | 50b298f204ba63b6de1acf5f7667559bc86b0d8a /compiler/rustc_passes/src | |
| parent | 4596f4f8b565bdd02d3b99d1ab12ff09146a93de (diff) | |
| parent | 4a254d557aef513c4dec1757eb1c2e7913a9f5a0 (diff) | |
| download | rust-2afca78a0b03db144c5d8b9f8868feebfe096309.tar.gz rust-2afca78a0b03db144c5d8b9f8868feebfe096309.zip | |
Auto merge of #103797 - Dylan-DPC:rollup-ps589fi, r=Dylan-DPC
Rollup of 5 pull requests Successful merges: - #103338 (Fix unreachable_pub suggestion for enum with fields) - #103603 (Lang item cleanups) - #103732 (Revert "Make the `c` feature for `compiler-builtins` opt-in instead of inferred") - #103766 (Add tracking issue to `error_in_core`) - #103789 (Update E0382.md) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'compiler/rustc_passes/src')
| -rw-r--r-- | compiler/rustc_passes/src/lang_items.rs | 32 | ||||
| -rw-r--r-- | compiler/rustc_passes/src/reachable.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_passes/src/weak_lang_items.rs | 12 |
3 files changed, 23 insertions, 29 deletions
diff --git a/compiler/rustc_passes/src/lang_items.rs b/compiler/rustc_passes/src/lang_items.rs index df811be2a7e..188efc528ef 100644 --- a/compiler/rustc_passes/src/lang_items.rs +++ b/compiler/rustc_passes/src/lang_items.rs @@ -16,7 +16,7 @@ use crate::weak_lang_items; use rustc_hir as hir; use rustc_hir::def::DefKind; use rustc_hir::def_id::DefId; -use rustc_hir::lang_items::{extract, GenericRequirement, ITEM_REFS}; +use rustc_hir::lang_items::{extract, GenericRequirement}; use rustc_hir::{HirId, LangItem, LanguageItems, Target}; use rustc_middle::ty::TyCtxt; use rustc_session::cstore::ExternCrate; @@ -43,17 +43,17 @@ impl<'tcx> LanguageItemCollector<'tcx> { fn check_for_lang(&mut self, actual_target: Target, hir_id: HirId) { let attrs = self.tcx.hir().attrs(hir_id); if let Some((name, span)) = extract(&attrs) { - match ITEM_REFS.get(&name).cloned() { + match LangItem::from_name(name) { // Known lang item with attribute on correct target. - Some((item_index, expected_target)) if actual_target == expected_target => { - self.collect_item_extended(item_index, hir_id, span); + Some(lang_item) if actual_target == lang_item.target() => { + self.collect_item_extended(lang_item, hir_id, span); } // Known lang item with attribute on incorrect target. - Some((_, expected_target)) => { + Some(lang_item) => { self.tcx.sess.emit_err(LangItemOnIncorrectTarget { span, name, - expected_target, + expected_target: lang_item.target(), actual_target, }); } @@ -65,12 +65,12 @@ impl<'tcx> LanguageItemCollector<'tcx> { } } - fn collect_item(&mut self, item_index: usize, item_def_id: DefId) { + fn collect_item(&mut self, lang_item: LangItem, item_def_id: DefId) { // Check for duplicates. - if let Some(original_def_id) = self.items.items[item_index] { + if let Some(original_def_id) = self.items.get(lang_item) { if original_def_id != item_def_id { let local_span = self.tcx.hir().span_if_local(item_def_id); - let lang_item_name = LangItem::from_u32(item_index as u32).unwrap().name(); + let lang_item_name = lang_item.name(); let crate_name = self.tcx.crate_name(item_def_id.krate); let mut dependency_of = Empty; let is_local = item_def_id.is_local(); @@ -139,17 +139,13 @@ impl<'tcx> LanguageItemCollector<'tcx> { } // Matched. - self.items.items[item_index] = Some(item_def_id); - if let Some(group) = LangItem::from_u32(item_index as u32).unwrap().group() { - self.items.groups[group as usize].push(item_def_id); - } + self.items.set(lang_item, item_def_id); } // Like collect_item() above, but also checks whether the lang item is declared // with the right number of generic arguments. - fn collect_item_extended(&mut self, item_index: usize, hir_id: HirId, span: Span) { + fn collect_item_extended(&mut self, lang_item: LangItem, hir_id: HirId, span: Span) { let item_def_id = self.tcx.hir().local_def_id(hir_id).to_def_id(); - let lang_item = LangItem::from_u32(item_index as u32).unwrap(); let name = lang_item.name(); // Now check whether the lang_item has the expected number of generic @@ -197,7 +193,7 @@ impl<'tcx> LanguageItemCollector<'tcx> { } } - self.collect_item(item_index, item_def_id); + self.collect_item(lang_item, item_def_id); } } @@ -208,8 +204,8 @@ fn get_lang_items(tcx: TyCtxt<'_>, (): ()) -> LanguageItems { // Collect lang items in other crates. for &cnum in tcx.crates(()).iter() { - for &(def_id, item_index) in tcx.defined_lang_items(cnum).iter() { - collector.collect_item(item_index, def_id); + for &(def_id, lang_item) in tcx.defined_lang_items(cnum).iter() { + collector.collect_item(lang_item, def_id); } } diff --git a/compiler/rustc_passes/src/reachable.rs b/compiler/rustc_passes/src/reachable.rs index 10d5fc5d671..73ea06a6370 100644 --- a/compiler/rustc_passes/src/reachable.rs +++ b/compiler/rustc_passes/src/reachable.rs @@ -380,11 +380,9 @@ fn reachable_set<'tcx>(tcx: TyCtxt<'tcx>, (): ()) -> FxHashSet<LocalDefId> { }) .collect::<Vec<_>>(); - for item in tcx.lang_items().items().iter() { - if let Some(def_id) = *item { - if let Some(def_id) = def_id.as_local() { - reachable_context.worklist.push(def_id); - } + for (_, def_id) in tcx.lang_items().iter() { + if let Some(def_id) = def_id.as_local() { + reachable_context.worklist.push(def_id); } } { diff --git a/compiler/rustc_passes/src/weak_lang_items.rs b/compiler/rustc_passes/src/weak_lang_items.rs index 959ee600c07..94d6a405b53 100644 --- a/compiler/rustc_passes/src/weak_lang_items.rs +++ b/compiler/rustc_passes/src/weak_lang_items.rs @@ -2,7 +2,7 @@ use rustc_data_structures::fx::FxHashSet; use rustc_hir::lang_items::{self, LangItem}; -use rustc_hir::weak_lang_items::WEAK_ITEMS_REFS; +use rustc_hir::weak_lang_items::WEAK_LANG_ITEMS; use rustc_middle::middle::lang_items::required; use rustc_middle::ty::TyCtxt; use rustc_session::config::CrateType; @@ -29,8 +29,8 @@ pub fn check_crate<'tcx>(tcx: TyCtxt<'tcx>, items: &mut lang_items::LanguageItem for id in crate_items.foreign_items() { let attrs = tcx.hir().attrs(id.hir_id()); if let Some((lang_item, _)) = lang_items::extract(attrs) { - if let Some(&item) = WEAK_ITEMS_REFS.get(&lang_item) { - if items.require(item).is_err() { + if let Some(item) = LangItem::from_name(lang_item) && item.is_weak() { + if items.get(item).is_none() { items.missing.push(item); } } else { @@ -65,8 +65,8 @@ fn verify<'tcx>(tcx: TyCtxt<'tcx>, items: &lang_items::LanguageItems) { } } - for (name, &item) in WEAK_ITEMS_REFS.iter() { - if missing.contains(&item) && required(tcx, item) && items.require(item).is_err() { + for &item in WEAK_LANG_ITEMS.iter() { + if missing.contains(&item) && required(tcx, item) && items.get(item).is_none() { if item == LangItem::PanicImpl { tcx.sess.emit_err(MissingPanicHandler); } else if item == LangItem::Oom { @@ -75,7 +75,7 @@ fn verify<'tcx>(tcx: TyCtxt<'tcx>, items: &lang_items::LanguageItems) { tcx.sess.emit_note(MissingAllocErrorHandler); } } else { - tcx.sess.emit_err(MissingLangItem { name: *name }); + tcx.sess.emit_err(MissingLangItem { name: item.name() }); } } } |
