From b334720408814ae15e1cc4e5155fe31133f47801 Mon Sep 17 00:00:00 2001 From: A4-Tacks Date: Tue, 1 Dec 2026 20:19:48 +0800 Subject: [PATCH] fix: correct move bounds when trait with supertraits Example --- ```rust trait T<'a: 'static, $0T: u32>: Super {} ``` **Before this PR** ```rust trait T<'a, T> where 'a: 'static, T: u32: Super {} ``` **After this PR** ```rust trait T<'a, T>: Super where 'a: 'static, T: u32 {} ``` --- crates/ide-assists/src/handlers/move_bounds.rs | 9 +++++++++ crates/syntax/src/syntax_editor/edits.rs | 6 ++++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/crates/ide-assists/src/handlers/move_bounds.rs b/crates/ide-assists/src/handlers/move_bounds.rs index b510b2daba67..1415fbd8d285 100644 --- a/crates/ide-assists/src/handlers/move_bounds.rs +++ b/crates/ide-assists/src/handlers/move_bounds.rs @@ -149,6 +149,15 @@ mod tests { ); } + #[test] + fn move_bounds_to_where_clause_trait_with_supertraits() { + check_assist( + move_bounds_to_where_clause, + r#"trait T<'a: 'static, $0T: u32>: Super {}"#, + r#"trait T<'a, T>: Super where 'a: 'static, T: u32 {}"#, + ); + } + #[test] fn move_bounds_to_where_clause_type_alias() { check_assist( diff --git a/crates/syntax/src/syntax_editor/edits.rs b/crates/syntax/src/syntax_editor/edits.rs index 45ec56be43ae..307e13591c61 100644 --- a/crates/syntax/src/syntax_editor/edits.rs +++ b/crates/syntax/src/syntax_editor/edits.rs @@ -3,7 +3,7 @@ use crate::{ AstToken, Direction, SyntaxElement, SyntaxKind, SyntaxNode, SyntaxToken, T, algo::neighbor, - ast::{self, AstNode, HasGenericParams, HasName, edit::IndentLevel}, + ast::{self, AstNode, HasGenericParams, HasName, HasTypeBounds, edit::IndentLevel}, syntax_editor::{Position, SyntaxEditor}, }; @@ -56,7 +56,9 @@ impl GetOrCreateWhereClause for ast::Impl { impl GetOrCreateWhereClause for ast::Trait { fn where_clause_position(&self) -> Option { - if let Some(gpl) = self.generic_param_list() { + if let Some(tbl) = self.type_bound_list() { + Some(Position::after(tbl.syntax())) + } else if let Some(gpl) = self.generic_param_list() { Some(Position::after(gpl.syntax())) } else if let Some(name) = self.name() { Some(Position::after(name.syntax()))