mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 20:42:04 +00:00
Impl hovering for TypeParams
This commit is contained in:
parent
5b86ff3e91
commit
47900dd3bc
3 changed files with 67 additions and 7 deletions
|
@ -5,9 +5,7 @@ use arrayvec::ArrayVec;
|
|||
use base_db::{CrateDisplayName, CrateId, Edition, FileId};
|
||||
use either::Either;
|
||||
use hir_def::{
|
||||
adt::ReprKind,
|
||||
adt::StructKind,
|
||||
adt::VariantData,
|
||||
adt::{ReprKind, StructKind, VariantData},
|
||||
builtin_type::BuiltinType,
|
||||
expr::{BindingAnnotation, LabelId, Pat, PatId},
|
||||
import_map,
|
||||
|
@ -31,7 +29,7 @@ use hir_expand::{
|
|||
};
|
||||
use hir_ty::{
|
||||
autoderef,
|
||||
display::{HirDisplayError, HirFormatter},
|
||||
display::{write_bounds_like_dyn_trait, HirDisplayError, HirFormatter},
|
||||
method_resolution,
|
||||
traits::{FnTrait, Solution, SolutionVariables},
|
||||
ApplicationTy, BoundVar, CallableDefId, Canonical, DebruijnIndex, FnSig, GenericPredicate,
|
||||
|
@ -1293,6 +1291,20 @@ impl TypeParam {
|
|||
}
|
||||
}
|
||||
|
||||
impl HirDisplay for TypeParam {
|
||||
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
|
||||
write!(f, "{}", self.name(f.db))?;
|
||||
let bounds = f.db.generic_predicates_for_param(self.id);
|
||||
let substs = Substs::type_params(f.db, self.id.parent);
|
||||
let predicates = bounds.iter().cloned().map(|b| b.subst(&substs)).collect::<Vec<_>>();
|
||||
if !(predicates.is_empty() || f.omit_verbose_types()) {
|
||||
write!(f, ": ")?;
|
||||
write_bounds_like_dyn_trait(&predicates, f)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
|
||||
pub struct LifetimeParam {
|
||||
pub(crate) id: LifetimeParamId,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue