mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 07:04:49 +00:00
Implement TypeRef::ForLifetime
This commit is contained in:
parent
1b9b2d1f40
commit
af739731db
6 changed files with 64 additions and 19 deletions
|
@ -21,6 +21,7 @@ use hir_def::{
|
|||
AssocContainerId, Lookup, ModuleId, TraitId,
|
||||
};
|
||||
use hir_expand::{hygiene::Hygiene, name::Name};
|
||||
use itertools::Itertools;
|
||||
|
||||
use crate::{
|
||||
const_from_placeholder_idx, db::HirDatabase, from_assoc_type_id, from_foreign_def_id,
|
||||
|
@ -1029,6 +1030,10 @@ impl HirDisplay for TypeBound {
|
|||
match self {
|
||||
TypeBound::Path(path) => path.hir_fmt(f),
|
||||
TypeBound::Lifetime(lifetime) => write!(f, "{}", lifetime.name),
|
||||
TypeBound::ForLifetime(lifetimes, path) => {
|
||||
write!(f, "for<{}> ", lifetimes.iter().format(", "))?;
|
||||
path.hir_fmt(f)
|
||||
}
|
||||
TypeBound::Error => write!(f, "{{error}}"),
|
||||
}
|
||||
}
|
||||
|
|
|
@ -786,6 +786,11 @@ impl<'a> TyLoweringContext<'a> {
|
|||
bindings = self.lower_trait_ref_from_path(path, Some(self_ty));
|
||||
bindings.clone().map(WhereClause::Implemented).map(crate::wrap_empty_binders)
|
||||
}
|
||||
TypeBound::ForLifetime(_, path) => {
|
||||
// FIXME Don't silently drop the hrtb lifetimes here
|
||||
bindings = self.lower_trait_ref_from_path(path, Some(self_ty));
|
||||
bindings.clone().map(WhereClause::Implemented).map(crate::wrap_empty_binders)
|
||||
}
|
||||
TypeBound::Lifetime(_) => None,
|
||||
TypeBound::Error => None,
|
||||
};
|
||||
|
@ -803,7 +808,7 @@ impl<'a> TyLoweringContext<'a> {
|
|||
trait_ref: TraitRef,
|
||||
) -> impl Iterator<Item = QuantifiedWhereClause> + 'a {
|
||||
let last_segment = match bound {
|
||||
TypeBound::Path(path) => path.segments().last(),
|
||||
TypeBound::Path(path) | TypeBound::ForLifetime(_, path) => path.segments().last(),
|
||||
TypeBound::Error | TypeBound::Lifetime(_) => None,
|
||||
};
|
||||
last_segment
|
||||
|
|
|
@ -54,3 +54,16 @@ fn main() {
|
|||
"#,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn render_dyn_for_ty() {
|
||||
// FIXME
|
||||
check_types_source_code(
|
||||
r#"
|
||||
trait Foo<'a> {}
|
||||
|
||||
fn foo(foo: &dyn for<'a> Foo<'a>) {}
|
||||
// ^^^ &dyn Foo
|
||||
"#,
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue