mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 06:41:48 +00:00
Merge #8266
8266: Fix generic arguments being incorrectly offset in qualified trait casts r=flodiebold a=Veykril We reverse the segments and generic args of the lowered path after building it, this wasn't accounted for when inserting the self parameter in `Type as Trait` segments. Fixes #5886 Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
commit
c69f6f31d1
2 changed files with 46 additions and 1 deletions
|
@ -74,6 +74,7 @@ pub(super) fn lower_path(mut path: ast::Path, hygiene: &Hygiene) -> Option<Path>
|
|||
// <T as Trait<A>>::Foo desugars to Trait<Self=T, A>::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<Path>
|
|||
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()));
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue