mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-01 06:11:35 +00:00
Fix trait object hir formatting behind pointer and references
This commit is contained in:
parent
e5f252ade7
commit
643bbf15a2
2 changed files with 57 additions and 6 deletions
|
@ -221,7 +221,16 @@ impl HirDisplay for ApplicationTy {
|
||||||
}
|
}
|
||||||
TypeCtor::RawPtr(m) => {
|
TypeCtor::RawPtr(m) => {
|
||||||
let t = self.parameters.as_single();
|
let t = self.parameters.as_single();
|
||||||
write!(f, "*{}{}", m.as_keyword_for_ptr(), t.display(f.db))?;
|
let ty_display = t.display(f.db);
|
||||||
|
|
||||||
|
write!(f, "*{}", m.as_keyword_for_ptr())?;
|
||||||
|
if matches!(t, Ty::Dyn(predicates) if predicates.len() > 1) {
|
||||||
|
write!(f, "(")?;
|
||||||
|
write!(f, "{}", ty_display)?;
|
||||||
|
write!(f, ")")?;
|
||||||
|
} else {
|
||||||
|
write!(f, "{}", ty_display)?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
TypeCtor::Ref(m) => {
|
TypeCtor::Ref(m) => {
|
||||||
let t = self.parameters.as_single();
|
let t = self.parameters.as_single();
|
||||||
|
@ -230,7 +239,15 @@ impl HirDisplay for ApplicationTy {
|
||||||
} else {
|
} else {
|
||||||
t.display(f.db)
|
t.display(f.db)
|
||||||
};
|
};
|
||||||
write!(f, "&{}{}", m.as_keyword_for_ref(), ty_display)?;
|
|
||||||
|
write!(f, "&{}", m.as_keyword_for_ref())?;
|
||||||
|
if matches!(t, Ty::Dyn(predicates) if predicates.len() > 1) {
|
||||||
|
write!(f, "(")?;
|
||||||
|
write!(f, "{}", ty_display)?;
|
||||||
|
write!(f, ")")?;
|
||||||
|
} else {
|
||||||
|
write!(f, "{}", ty_display)?;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
TypeCtor::Never => write!(f, "!")?,
|
TypeCtor::Never => write!(f, "!")?,
|
||||||
TypeCtor::Tuple { .. } => {
|
TypeCtor::Tuple { .. } => {
|
||||||
|
@ -636,14 +653,14 @@ impl HirDisplay for GenericPredicate {
|
||||||
|
|
||||||
impl HirDisplay for Obligation {
|
impl HirDisplay for Obligation {
|
||||||
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
|
fn hir_fmt(&self, f: &mut HirFormatter) -> Result<(), HirDisplayError> {
|
||||||
Ok(match self {
|
match self {
|
||||||
Obligation::Trait(tr) => write!(f, "Implements({})", tr.display(f.db))?,
|
Obligation::Trait(tr) => write!(f, "Implements({})", tr.display(f.db)),
|
||||||
Obligation::Projection(proj) => write!(
|
Obligation::Projection(proj) => write!(
|
||||||
f,
|
f,
|
||||||
"Normalize({} => {})",
|
"Normalize({} => {})",
|
||||||
proj.projection_ty.display(f.db),
|
proj.projection_ty.display(f.db),
|
||||||
proj.ty.display(f.db)
|
proj.ty.display(f.db)
|
||||||
)?,
|
),
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1023,6 +1023,40 @@ mod collections {
|
||||||
type Item=T;
|
type Item=T;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn multi_dyn_trait_bounds() {
|
||||||
|
check_with_config(
|
||||||
|
InlayHintsConfig {
|
||||||
|
type_hints: true,
|
||||||
|
parameter_hints: false,
|
||||||
|
chaining_hints: false,
|
||||||
|
max_length: None,
|
||||||
|
},
|
||||||
|
r#"
|
||||||
|
//- /main.rs crate:main
|
||||||
|
pub struct Vec<T> {}
|
||||||
|
|
||||||
|
impl<T> Vec<T> {
|
||||||
|
pub fn new() -> Self { Vec {} }
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct Box<T> {}
|
||||||
|
|
||||||
|
trait Display {}
|
||||||
|
trait Sync {}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
let _v = Vec::<Box<&(dyn Display + Sync)>>::new();
|
||||||
|
//^^ Vec<Box<&(dyn Display + Sync)>>
|
||||||
|
let _v = Vec::<Box<*const (dyn Display + Sync)>>::new();
|
||||||
|
//^^ Vec<Box<*const (dyn Display + Sync)>>
|
||||||
|
let _v = Vec::<Box<dyn Display + Sync>>::new();
|
||||||
|
//^^ Vec<Box<dyn Display + Sync>>
|
||||||
|
}
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue