Unnamed repository; edit this file 'description' to name the repository.
Diffstat (limited to 'crates/hir-def/src/generics.rs')
-rw-r--r--crates/hir-def/src/generics.rs27
1 files changed, 19 insertions, 8 deletions
diff --git a/crates/hir-def/src/generics.rs b/crates/hir-def/src/generics.rs
index 11e9bb0d88..7b3f1d06d2 100644
--- a/crates/hir-def/src/generics.rs
+++ b/crates/hir-def/src/generics.rs
@@ -26,8 +26,8 @@ use crate::{
nameres::{DefMap, MacroSubNs},
path::{AssociatedTypeBinding, GenericArg, GenericArgs, NormalPath, Path},
type_ref::{
- ArrayType, ConstRef, FnType, LifetimeRef, RefType, TypeBound, TypeRef, TypeRefId, TypesMap,
- TypesSourceMap,
+ ArrayType, ConstRef, FnType, LifetimeRef, PathId, RefType, TypeBound, TypeRef, TypeRefId,
+ TypesMap, TypesSourceMap,
},
AdtId, ConstParamId, GenericDefId, HasModule, ItemTreeLoc, LifetimeParamId,
LocalLifetimeParamId, LocalTypeOrConstParamId, Lookup, TypeOrConstParamId, TypeParamId,
@@ -225,6 +225,11 @@ impl GenericParams {
}
#[inline]
+ pub fn no_predicates(&self) -> bool {
+ self.where_predicates.is_empty()
+ }
+
+ #[inline]
pub fn where_predicates(&self) -> std::slice::Iter<'_, WherePredicate> {
self.where_predicates.iter()
}
@@ -874,14 +879,20 @@ fn copy_type_bound(
to: &mut TypesMap,
to_source_map: &mut TypesSourceMap,
) -> TypeBound {
+ let mut copy_path_id = |path: PathId| {
+ let new_path = copy_path(&from[path], from, from_source_map, to, to_source_map);
+ let new_path_id = to.types.alloc(TypeRef::Path(new_path));
+ if let Some(&ptr) = from_source_map.types_map_back.get(path.type_ref()) {
+ to_source_map.types_map_back.insert(new_path_id, ptr);
+ }
+ PathId::from_type_ref_unchecked(new_path_id)
+ };
+
match bound {
- TypeBound::Path(path, modifier) => {
- TypeBound::Path(copy_path(path, from, from_source_map, to, to_source_map), *modifier)
+ &TypeBound::Path(path, modifier) => TypeBound::Path(copy_path_id(path), modifier),
+ TypeBound::ForLifetime(lifetimes, path) => {
+ TypeBound::ForLifetime(lifetimes.clone(), copy_path_id(*path))
}
- TypeBound::ForLifetime(lifetimes, path) => TypeBound::ForLifetime(
- lifetimes.clone(),
- copy_path(path, from, from_source_map, to, to_source_map),
- ),
TypeBound::Lifetime(lifetime) => TypeBound::Lifetime(lifetime.clone()),
TypeBound::Use(use_args) => TypeBound::Use(use_args.clone()),
TypeBound::Error => TypeBound::Error,