Skip to content

Commit d9e6377

Browse files
committed
adjust hir_def::TypeBound::as_path
1 parent b217e9c commit d9e6377

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

crates/hir_def/src/item_tree/tests.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ struct S<'a, 'b: 'a, T: Copy + 'a + 'b, const K: u8 = 0> {
304304
field: &'a &'b T,
305305
}
306306
307-
struct Tuple<T: Copy>(T);
307+
struct Tuple<T: Copy, U: ?Sized>(T, U);
308308
309309
impl<'a, 'b: 'a, T: Copy + 'a + 'b, const K: u8 = 0> S<'a, 'b, T, K> {
310310
fn f<G: 'a>(arg: impl Copy) -> impl Copy {}
@@ -325,11 +325,13 @@ trait Tr<'a, T: 'a>: Super where Self: for<'a> Tr<'a, T> {}
325325
pub(self) field: &'a &'b T,
326326
}
327327
328-
pub(self) struct Tuple<T>(
328+
pub(self) struct Tuple<T, U>(
329329
pub(self) 0: T,
330+
pub(self) 1: U,
330331
)
331332
where
332-
T: Copy;
333+
T: Copy,
334+
U: ?Sized;
333335
334336
impl<'a, 'b, T, const K: u8> S<'a, 'b, T, K>
335337
where

crates/hir_def/src/type_ref.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -332,9 +332,10 @@ impl TypeBound {
332332
}
333333
}
334334

335-
pub fn as_path(&self) -> Option<&Path> {
335+
pub fn as_path(&self) -> Option<(&Path, &TraitBoundModifier)> {
336336
match self {
337-
TypeBound::Path(p, _) | TypeBound::ForLifetime(_, p) => Some(p),
337+
TypeBound::Path(p, m) => Some((p, m)),
338+
TypeBound::ForLifetime(_, p) => Some((p, &TraitBoundModifier::None)),
338339
TypeBound::Lifetime(_) | TypeBound::Error => None,
339340
}
340341
}

crates/hir_ty/src/utils.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use hir_def::{
1313
intern::Interned,
1414
path::Path,
1515
resolver::{HasResolver, TypeNs},
16-
type_ref::TypeRef,
16+
type_ref::{TraitBoundModifier, TypeRef},
1717
AssocContainerId, GenericDefId, Lookup, TraitId, TypeAliasId, TypeParamId,
1818
};
1919
use hir_expand::name::{name, Name};
@@ -58,6 +58,10 @@ fn direct_super_traits(db: &dyn DefDatabase, trait_: TraitId) -> Vec<TraitId> {
5858
},
5959
WherePredicate::Lifetime { .. } => None,
6060
})
61+
.filter_map(|(path, bound_modifier)| match bound_modifier {
62+
TraitBoundModifier::None => Some(path),
63+
TraitBoundModifier::Maybe => None,
64+
})
6165
.filter_map(|path| match resolver.resolve_path_in_type_ns_fully(db, path.mod_path()) {
6266
Some(TypeNs::TraitId(t)) => Some(t),
6367
_ => None,

0 commit comments

Comments
 (0)