10840: fix: Omit generic defaults for types in hover messages r=jonas-schievink a=Veykril

Fixes #9198

We have ranged hovers now which query specifically for the type of an expression/pattern, so if interested in seeing the default, the user can use that functionality instead.

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
bors[bot] 2021-11-23 15:21:47 +00:00 committed by GitHub
commit 054873ce15
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 17 additions and 5 deletions

View File

@ -639,7 +639,7 @@ impl HirDisplay for Ty {
if let Some(sig) = sig { if let Some(sig) = sig {
if sig.params().is_empty() { if sig.params().is_empty() {
write!(f, "||")?; write!(f, "||")?;
} else if f.omit_verbose_types() { } else if f.should_truncate() {
write!(f, "|{}|", TYPE_HINT_TRUNCATION)?; write!(f, "|{}|", TYPE_HINT_TRUNCATION)?;
} else { } else {
write!(f, "|")?; write!(f, "|")?;

View File

@ -444,7 +444,7 @@ fn find_std_module(famous_defs: &FamousDefs, name: &str) -> Option<hir::Module>
fn local(db: &RootDatabase, it: hir::Local) -> Option<Markup> { fn local(db: &RootDatabase, it: hir::Local) -> Option<Markup> {
let ty = it.ty(db); let ty = it.ty(db);
let ty = ty.display(db); let ty = ty.display_truncated(db, None);
let is_mut = if it.is_mut(db) { "mut " } else { "" }; let is_mut = if it.is_mut(db) { "mut " } else { "" };
let desc = match it.source(db).value { let desc = match it.source(db).value {
Either::Left(ident) => { Either::Left(ident) => {

View File

@ -607,10 +607,22 @@ fn main() {
*zz* *zz*
```rust ```rust
let zz: Test<i32, u8> let zz: Test<i32>
``` ```
"#]], "#]],
); );
check_hover_range(
r#"
struct Test<K, T = u8> { k: K, t: T }
fn main() {
let $0zz$0 = Test { t: 23u8, k: 33 };
}"#,
expect![[r#"
```rust
Test<i32, u8>
```"#]],
);
} }
#[test] #[test]

View File

@ -1443,14 +1443,14 @@ fn main() {
//^^^^^^^^^ i32 //^^^^^^^^^ i32
let multiply = let multiply =
//^^^^^^^^ || -> i32 //^^^^^^^^ |i32, i32| -> i32
| a, b| a * b | a, b| a * b
//^ i32 ^ i32 //^ i32 ^ i32
; ;
let _: i32 = multiply(1, 2); let _: i32 = multiply(1, 2);
let multiply_ref = &multiply; let multiply_ref = &multiply;
//^^^^^^^^^^^^ &|| -> i32 //^^^^^^^^^^^^ &|i32, i32| -> i32
let return_42 = || 42; let return_42 = || 42;
//^^^^^^^^^ || -> i32 //^^^^^^^^^ || -> i32