From 6f0575f08adca0c8a8f38a301913a1cfe636eb94 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Tue, 30 Mar 2021 21:43:23 +0200 Subject: Fix generic arguments being incorrectly offset in qualified trait casts --- crates/hir_def/src/path/lower.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'crates/hir_def') 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 // >::Foo desugars to Trait::Foo Some(trait_ref) => { let path = Path::from_src(trait_ref.path()?, hygiene)?; + let num_segments = path.mod_path.segments.len(); kind = path.mod_path.kind; let mut prefix_segments = path.mod_path.segments; @@ -85,7 +86,8 @@ pub(super) fn lower_path(mut path: ast::Path, hygiene: &Hygiene) -> Option generic_args.extend(prefix_args); // Insert the type reference (T in the above example) as Self parameter for the trait - let last_segment = generic_args.last_mut()?; + let last_segment = + generic_args.iter_mut().rev().nth(num_segments.saturating_sub(1))?; if last_segment.is_none() { *last_segment = Some(Arc::new(GenericArgs::empty())); }; -- cgit v1.2.3