Two minor changes for readability and efficiency

This commit is contained in:
Fabian Wolff 2021-05-17 13:56:11 +02:00
parent 4efa4a5273
commit 7b301985fa
2 changed files with 4 additions and 8 deletions

View File

@ -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,

View File

@ -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 }
})
}