aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--crates/hir_def/src/path/lower.rs4
-rw-r--r--crates/hir_ty/src/tests/traits.rs43
2 files changed, 46 insertions, 1 deletions
diff --git a/crates/hir_def/src/path/lower.rs b/crates/hir_def/src/path/lower.rs
index 505493a74..4de951fd3 100644
--- a/crates/hir_def/src/path/lower.rs
+++ b/crates/hir_def/src/path/lower.rs
@@ -74,6 +74,7 @@ pub(super) fn lower_path(mut path: ast::Path, hygiene: &Hygiene) -> Option<Path>
74 // <T as Trait<A>>::Foo desugars to Trait<Self=T, A>::Foo 74 // <T as Trait<A>>::Foo desugars to Trait<Self=T, A>::Foo
75 Some(trait_ref) => { 75 Some(trait_ref) => {
76 let path = Path::from_src(trait_ref.path()?, hygiene)?; 76 let path = Path::from_src(trait_ref.path()?, hygiene)?;
77 let num_segments = path.mod_path.segments.len();
77 kind = path.mod_path.kind; 78 kind = path.mod_path.kind;
78 79
79 let mut prefix_segments = path.mod_path.segments; 80 let mut prefix_segments = path.mod_path.segments;
@@ -85,7 +86,8 @@ pub(super) fn lower_path(mut path: ast::Path, hygiene: &Hygiene) -> Option<Path>
85 generic_args.extend(prefix_args); 86 generic_args.extend(prefix_args);
86 87
87 // Insert the type reference (T in the above example) as Self parameter for the trait 88 // Insert the type reference (T in the above example) as Self parameter for the trait
88 let last_segment = generic_args.last_mut()?; 89 let last_segment =
90 generic_args.iter_mut().rev().nth(num_segments.saturating_sub(1))?;
89 if last_segment.is_none() { 91 if last_segment.is_none() {
90 *last_segment = Some(Arc::new(GenericArgs::empty())); 92 *last_segment = Some(Arc::new(GenericArgs::empty()));
91 }; 93 };
diff --git a/crates/hir_ty/src/tests/traits.rs b/crates/hir_ty/src/tests/traits.rs
index 2ba97f814..65b71fdfa 100644
--- a/crates/hir_ty/src/tests/traits.rs
+++ b/crates/hir_ty/src/tests/traits.rs
@@ -3370,3 +3370,46 @@ fn test() {
3370 "#]], 3370 "#]],
3371 ) 3371 )
3372} 3372}
3373
3374#[test]
3375fn qualified_path_as_qualified_trait() {
3376 check_infer(
3377 r#"
3378mod foo {
3379
3380 pub trait Foo {
3381 type Target;
3382 }
3383 pub trait Bar {
3384 type Output;
3385 fn boo() -> Self::Output {
3386 loop {}
3387 }
3388 }
3389}
3390
3391struct F;
3392impl foo::Foo for F {
3393 type Target = ();
3394}
3395impl foo::Bar for F {
3396 type Output = <F as foo::Foo>::Target;
3397}
3398
3399fn foo() {
3400 use foo::Bar;
3401 let x = <F as Bar>::boo();
3402}
3403
3404 "#,
3405 expect![[r#"
3406 132..163 '{ ... }': Bar::Output<Self>
3407 146..153 'loop {}': !
3408 151..153 '{}': ()
3409 306..358 '{ ...o(); }': ()
3410 334..335 'x': ()
3411 338..353 '<F as Bar>::boo': fn boo<F>() -> <F as Bar>::Output
3412 338..355 '<F as ...:boo()': ()
3413 "#]],
3414 );
3415}