about summary refs log tree commit diff
diff options
context:
space:
mode:
authorFabian Wolff <fabi.wolff@arcor.de>2021-05-17 13:56:11 +0200
committerFabian Wolff <fabi.wolff@arcor.de>2021-05-17 13:58:14 +0200
commit7b301985faa73b1404cbc21ffe7c7f859a293448 (patch)
treec84249466f8e71a9325f6759acd330c17e8cbc80
parent4efa4a5273293354526801d8e3a3d05d005b2479 (diff)
downloadrust-7b301985faa73b1404cbc21ffe7c7f859a293448.tar.gz
rust-7b301985faa73b1404cbc21ffe7c7f859a293448.zip
Two minor changes for readability and efficiency
-rw-r--r--compiler/rustc_passes/src/lang_items.rs5
-rw-r--r--compiler/rustc_typeck/src/check/mod.rs7
2 files changed, 4 insertions, 8 deletions
diff --git a/compiler/rustc_passes/src/lang_items.rs b/compiler/rustc_passes/src/lang_items.rs
index 9086e21579e..a6306ad923d 100644
--- a/compiler/rustc_passes/src/lang_items.rs
+++ b/compiler/rustc_passes/src/lang_items.rs
@@ -100,12 +100,11 @@ impl LanguageItemCollector<'tcx> {
     }
 
     fn collect_item(&mut self, item_index: usize, item_def_id: DefId) {
-        let lang_item = LangItem::from_u32(item_index as u32).unwrap();
-        let name = lang_item.name();
-
         // Check for duplicates.
         if let Some(original_def_id) = self.items.items[item_index] {
             if original_def_id != item_def_id {
+                let lang_item = LangItem::from_u32(item_index as u32).unwrap();
+                let name = lang_item.name();
                 let mut err = match self.tcx.hir().span_if_local(item_def_id) {
                     Some(span) => struct_span_err!(
                         self.tcx.sess,
diff --git a/compiler/rustc_typeck/src/check/mod.rs b/compiler/rustc_typeck/src/check/mod.rs
index 6f96bd544c0..0b5387993c9 100644
--- a/compiler/rustc_typeck/src/check/mod.rs
+++ b/compiler/rustc_typeck/src/check/mod.rs
@@ -1194,13 +1194,10 @@ fn potentially_plural_count(count: usize, word: &str) -> String {
 fn has_expected_num_generic_args<'tcx>(
     tcx: TyCtxt<'tcx>,
     trait_did: Option<DefId>,
-    mut expected: usize,
+    expected: usize,
 ) -> bool {
     trait_did.map_or(true, |trait_did| {
         let generics = tcx.generics_of(trait_did);
-        if generics.has_self {
-            expected += 1;
-        }
-        generics.count() == expected
+        generics.count() == expected + if generics.has_self { 1 } else { 0 }
     })
 }