Skip to content

Commit d976ef8

Browse files
Merge pull request rust-lang#20297 from A4-Tacks/fix-ws-gen-trait-from-impl
Fix generate_trait_from_impl whitespace after vis
2 parents cf88654 + abddbc5 commit d976ef8

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/tools/rust-analyzer/crates/ide-assists/src/handlers/generate_trait_from_impl.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use ide_db::assists::AssistId;
33
use syntax::{
44
AstNode, SyntaxKind, T,
55
ast::{
6-
self, HasGenericParams, HasName,
6+
self, HasGenericParams, HasName, HasVisibility,
77
edit_in_place::{HasVisibilityEdit, Indent},
88
make,
99
},
@@ -164,6 +164,12 @@ pub(crate) fn generate_trait_from_impl(acc: &mut Assists, ctx: &AssistContext<'_
164164
/// `E0449` Trait items always share the visibility of their trait
165165
fn remove_items_visibility(item: &ast::AssocItem) {
166166
if let Some(has_vis) = ast::AnyHasVisibility::cast(item.syntax().clone()) {
167+
if let Some(vis) = has_vis.visibility()
168+
&& let Some(token) = vis.syntax().next_sibling_or_token()
169+
&& token.kind() == SyntaxKind::WHITESPACE
170+
{
171+
ted::remove(token);
172+
}
167173
has_vis.set_visibility(None);
168174
}
169175
}
@@ -333,11 +339,11 @@ impl F$0oo {
333339
struct Foo;
334340
335341
trait NewTrait {
336-
fn a_func() -> Option<()>;
342+
fn a_func() -> Option<()>;
337343
}
338344
339345
impl NewTrait for Foo {
340-
fn a_func() -> Option<()> {
346+
fn a_func() -> Option<()> {
341347
Some(())
342348
}
343349
}"#,

0 commit comments

Comments
 (0)