Merge pull request #20297 from A4-Tacks/fix-ws-gen-trait-from-impl
Some checks are pending
metrics / build_metrics (push) Waiting to run
metrics / other_metrics (diesel-1.4.8) (push) Blocked by required conditions
metrics / other_metrics (hyper-0.14.18) (push) Blocked by required conditions
metrics / other_metrics (ripgrep-13.0.0) (push) Blocked by required conditions
metrics / other_metrics (self) (push) Blocked by required conditions
metrics / other_metrics (webrender-2022) (push) Blocked by required conditions
metrics / generate_final_metrics (push) Blocked by required conditions
rustdoc / rustdoc (push) Waiting to run

Fix generate_trait_from_impl whitespace after vis
This commit is contained in:
Chayim Refael Friedman 2025-07-24 09:41:20 +00:00 committed by GitHub
commit 922e04a134
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -3,7 +3,7 @@ use ide_db::assists::AssistId;
use syntax::{
AstNode, SyntaxKind, T,
ast::{
self, HasGenericParams, HasName,
self, HasGenericParams, HasName, HasVisibility,
edit_in_place::{HasVisibilityEdit, Indent},
make,
},
@ -164,6 +164,12 @@ pub(crate) fn generate_trait_from_impl(acc: &mut Assists, ctx: &AssistContext<'_
/// `E0449` Trait items always share the visibility of their trait
fn remove_items_visibility(item: &ast::AssocItem) {
if let Some(has_vis) = ast::AnyHasVisibility::cast(item.syntax().clone()) {
if let Some(vis) = has_vis.visibility()
&& let Some(token) = vis.syntax().next_sibling_or_token()
&& token.kind() == SyntaxKind::WHITESPACE
{
ted::remove(token);
}
has_vis.set_visibility(None);
}
}
@ -333,11 +339,11 @@ impl F$0oo {
struct Foo;
trait NewTrait {
fn a_func() -> Option<()>;
fn a_func() -> Option<()>;
}
impl NewTrait for Foo {
fn a_func() -> Option<()> {
fn a_func() -> Option<()> {
Some(())
}
}"#,