From ec3638adb93ea425f825cc976bcae816f7e5c50b Mon Sep 17 00:00:00 2001 From: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> Date: Wed, 28 Oct 2020 15:42:51 +0100 Subject: do not use associated types placeholder for inlay hint Signed-off-by: Benjamin Coenen <5719034+bnjjj@users.noreply.github.com> --- crates/hir_ty/src/display.rs | 12 ++++++++++-- crates/hir_ty/src/tests.rs | 2 +- crates/hir_ty/src/tests/regression.rs | 2 +- crates/hir_ty/src/tests/traits.rs | 9 +++++---- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/crates/hir_ty/src/display.rs b/crates/hir_ty/src/display.rs index 0bf181a92..822ef4477 100644 --- a/crates/hir_ty/src/display.rs +++ b/crates/hir_ty/src/display.rs @@ -332,7 +332,11 @@ impl HirDisplay for ApplicationTy { let ret_display = if f.omit_verbose_types() { ret.display_truncated(f.db, f.max_size) } else { - ret.display(f.db) + if f.display_target.is_test() { + ret.display_test(f.db) + } else { + ret.display(f.db) + } }; write!(f, " -> {}", ret_display)?; } @@ -472,7 +476,11 @@ impl HirDisplay for ApplicationTy { let ret_display = if f.omit_verbose_types() { sig.ret().display_truncated(f.db, f.max_size) } else { - sig.ret().display(f.db) + if f.display_target.is_test() { + sig.ret().display_test(f.db) + } else { + sig.ret().display(f.db) + } }; write!(f, " -> {}", ret_display)?; } else { diff --git a/crates/hir_ty/src/tests.rs b/crates/hir_ty/src/tests.rs index 29b178ec1..104ef334c 100644 --- a/crates/hir_ty/src/tests.rs +++ b/crates/hir_ty/src/tests.rs @@ -74,7 +74,7 @@ fn check_types_impl(ra_fixture: &str, display_source: bool) { let module = db.module_for_file(file_id); ty.display_source_code(&db, module).unwrap() } else { - ty.display(&db).to_string() + ty.display_test(&db).to_string() }; assert_eq!(expected, actual); checked_one = true; diff --git a/crates/hir_ty/src/tests/regression.rs b/crates/hir_ty/src/tests/regression.rs index 42d08f12c..94d86b0d1 100644 --- a/crates/hir_ty/src/tests/regression.rs +++ b/crates/hir_ty/src/tests/regression.rs @@ -832,7 +832,7 @@ fn issue_4966() { 365..390 'Repeat...nner }': Repeat f64>> 383..388 'inner': Map<|&f64| -> f64> 401..404 'vec': Vec f64>>>> - 407..416 'from_iter': fn from_iter f64>>>, Repeat f64>>>(Repeat f64>>) -> Vec< f64>> as IntoIterator>::Item> + 407..416 'from_iter': fn from_iter f64>>>, Repeat f64>>>(Repeat f64>>) -> Vec f64>>>> 407..424 'from_i...epeat)': Vec f64>>>> 417..423 'repeat': Repeat f64>> 431..434 'vec': Vec f64>>>> diff --git a/crates/hir_ty/src/tests/traits.rs b/crates/hir_ty/src/tests/traits.rs index 4d193dea9..41d097519 100644 --- a/crates/hir_ty/src/tests/traits.rs +++ b/crates/hir_ty/src/tests/traits.rs @@ -907,7 +907,8 @@ fn test(t: T) { (*t); } } #[test] -fn associated_type_inlay_hints() { +fn associated_type_placeholder() { + // inside the generic function, the associated type gets normalized to a placeholder `ApplL::Out` [https://rust-lang.github.io/rustc-guide/traits/associated-types.html#placeholder-associated-types]. check_types( r#" pub trait ApplyL { @@ -923,13 +924,13 @@ impl ApplyL for RefMutL { fn test() { let y: as ApplyL>::Out = no_matter; y; -} //^ ::Out +} //^ ApplyL::Out "#, ); } #[test] -fn associated_type_inlay_hints_2() { +fn associated_type_placeholder_2() { check_types( r#" pub trait ApplyL { @@ -940,7 +941,7 @@ fn foo(t: T) -> ::Out; fn test(t: T) { let y = foo(t); y; -} //^ ::Out +} //^ ApplyL::Out "#, ); } -- cgit v1.2.3