Clean up with_generic_param_rib, avoid double hashing

This commit is contained in:
Dániel Buga 2020-12-20 21:08:55 +01:00
parent bd2f1cb278
commit 93d5a8025d

View File

@ -29,7 +29,7 @@
use smallvec::{smallvec, SmallVec};
use rustc_span::source_map::{respan, Spanned};
use std::collections::BTreeSet;
use std::collections::{hash_map::Entry, BTreeSet};
use std::mem::{replace, take};
use tracing::debug;
@ -1060,36 +1060,29 @@ fn with_generic_param_rib<'c, F>(&'c mut self, generics: &'c Generics, kind: Rib
continue;
}
let def_kind = match param.kind {
GenericParamKind::Type { .. } => DefKind::TyParam,
GenericParamKind::Const { .. } => DefKind::ConstParam,
_ => unreachable!(),
};
let ident = param.ident.normalize_to_macros_2_0();
debug!("with_generic_param_rib: {}", param.id);
if seen_bindings.contains_key(&ident) {
let span = seen_bindings.get(&ident).unwrap();
let err = ResolutionError::NameAlreadyUsedInParameterList(ident.name, *span);
match seen_bindings.entry(ident) {
Entry::Occupied(entry) => {
let span = *entry.get();
let err = ResolutionError::NameAlreadyUsedInParameterList(ident.name, span);
self.report_error(param.ident.span, err);
}
seen_bindings.entry(ident).or_insert(param.ident.span);
Entry::Vacant(entry) => {
entry.insert(param.ident.span);
}
}
// Plain insert (no renaming).
let res = Res::Def(def_kind, self.r.local_def_id(param.id).to_def_id());
match param.kind {
GenericParamKind::Type { .. } => {
function_type_rib.bindings.insert(ident, res);
self.r.record_partial_res(param.id, PartialRes::new(res));
}
GenericParamKind::Const { .. } => {
function_value_rib.bindings.insert(ident, res);
self.r.record_partial_res(param.id, PartialRes::new(res));
}
let (rib, def_kind) = match param.kind {
GenericParamKind::Type { .. } => (&mut function_type_rib, DefKind::TyParam),
GenericParamKind::Const { .. } => (&mut function_value_rib, DefKind::ConstParam),
_ => unreachable!(),
}
};
let res = Res::Def(def_kind, self.r.local_def_id(param.id).to_def_id());
self.r.record_partial_res(param.id, PartialRes::new(res));
rib.bindings.insert(ident, res);
}
self.ribs[ValueNS].push(function_value_rib);