about summary refs log tree commit diff
path: root/compiler/rustc_passes/src
diff options
context:
space:
mode:
authorFabian Wolff <fabi.wolff@arcor.de>2021-05-16 18:16:00 +0200
committerFabian Wolff <fabi.wolff@arcor.de>2021-05-16 18:22:34 +0200
commit4efa4a5273293354526801d8e3a3d05d005b2479 (patch)
tree9c4d8525129dd64da403dc3604cdcc9ba3e33902 /compiler/rustc_passes/src
parent7217d767b2054ac98da4f1840934f35f8285890c (diff)
downloadrust-4efa4a5273293354526801d8e3a3d05d005b2479.tar.gz
rust-4efa4a5273293354526801d8e3a3d05d005b2479.zip
Implement changes suggested by varkor
Diffstat (limited to 'compiler/rustc_passes/src')
-rw-r--r--compiler/rustc_passes/src/lang_items.rs54
1 files changed, 49 insertions, 5 deletions
diff --git a/compiler/rustc_passes/src/lang_items.rs b/compiler/rustc_passes/src/lang_items.rs
index 111bdd1a117..9086e21579e 100644
--- a/compiler/rustc_passes/src/lang_items.rs
+++ b/compiler/rustc_passes/src/lang_items.rs
@@ -182,6 +182,8 @@ impl LanguageItemCollector<'tcx> {
         }
     }
 
+    // Like collect_item() above, but also checks whether the lang item is declared
+    // with the right number of generic arguments if it is a trait.
     fn collect_item_extended(&mut self, item_index: usize, 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();
@@ -190,10 +192,15 @@ impl LanguageItemCollector<'tcx> {
         self.collect_item(item_index, item_def_id);
 
         // Now check whether the lang_item has the expected number of generic
-        // arguments. Binary and indexing operations have one (for the RHS/index),
-        // unary operations have no generic arguments.
+        // arguments if it is a trait. Generally speaking, binary and indexing
+        // operations have one (for the RHS/index), unary operations have none,
+        // and the rest also have none except for the closure traits (one for
+        // the argument list), generators (one for the resume argument),
+        // ordering/equality relations (one for the RHS), and various conversion
+        // traits.
 
         let expected_num = match lang_item {
+            // Binary operations
             LangItem::Add
             | LangItem::Sub
             | LangItem::Mul
@@ -215,11 +222,48 @@ impl LanguageItemCollector<'tcx> {
             | LangItem::ShlAssign
             | LangItem::ShrAssign
             | LangItem::Index
-            | LangItem::IndexMut => Some(1),
+            | LangItem::IndexMut
 
-            LangItem::Neg | LangItem::Not | LangItem::Deref | LangItem::DerefMut => Some(0),
+            // Miscellaneous
+            | LangItem::Unsize
+            | LangItem::CoerceUnsized
+            | LangItem::DispatchFromDyn
+            | LangItem::Fn
+            | LangItem::FnMut
+            | LangItem::FnOnce
+            | LangItem::Generator
+            | LangItem::PartialEq
+            | LangItem::PartialOrd
+                => Some(1),
 
-            // FIXME: add more cases?
+            // Unary operations
+            LangItem::Neg
+            | LangItem::Not
+
+            // Miscellaneous
+            | LangItem::Deref
+            | LangItem::DerefMut
+            | LangItem::Sized
+            | LangItem::StructuralPeq
+            | LangItem::StructuralTeq
+            | LangItem::Copy
+            | LangItem::Clone
+            | LangItem::Sync
+            | LangItem::DiscriminantKind
+            | LangItem::PointeeTrait
+            | LangItem::Freeze
+            | LangItem::Drop
+            | LangItem::Receiver
+            | LangItem::Future
+            | LangItem::Unpin
+            | LangItem::Termination
+            | LangItem::Try
+            | LangItem::Send
+            | LangItem::UnwindSafe
+            | LangItem::RefUnwindSafe
+                => Some(0),
+
+            // Not a trait
             _ => None,
         };