mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-22 12:37:32 +00:00
better formatting when adding trait members
* it's conventional not to use one-liners * new placement is more predictable, b/c it does not depend on header's length
This commit is contained in:
parent
16256ee2c6
commit
a27fc96aa1
@ -109,6 +109,7 @@ fn add_missing_impl_members_inner(
|
|||||||
let replaced_text_range = TextUnit::of_str(&func_bodies);
|
let replaced_text_range = TextUnit::of_str(&func_bodies);
|
||||||
|
|
||||||
edit.replace(changed_range, func_bodies);
|
edit.replace(changed_range, func_bodies);
|
||||||
|
// FIXME: place the cursor on the first unimplemented?
|
||||||
edit.set_cursor(
|
edit.set_cursor(
|
||||||
changed_range.start() + replaced_text_range - TextUnit::of_str(&trailing_whitespace),
|
changed_range.start() + replaced_text_range - TextUnit::of_str(&trailing_whitespace),
|
||||||
);
|
);
|
||||||
@ -138,7 +139,7 @@ fn build_func_body(def: &ast::FnDef) -> String {
|
|||||||
|
|
||||||
for child in def.syntax().children_with_tokens() {
|
for child in def.syntax().children_with_tokens() {
|
||||||
match (child.prev_sibling_or_token().map(|c| c.kind()), child.kind()) {
|
match (child.prev_sibling_or_token().map(|c| c.kind()), child.kind()) {
|
||||||
(_, SyntaxKind::SEMI) => buf.push_str(" { unimplemented!() }"),
|
(_, SyntaxKind::SEMI) => buf.push_str(" {\n unimplemented!()\n}"),
|
||||||
(_, SyntaxKind::ATTR) | (_, SyntaxKind::COMMENT) => {}
|
(_, SyntaxKind::ATTR) | (_, SyntaxKind::COMMENT) => {}
|
||||||
(Some(SyntaxKind::ATTR), SyntaxKind::WHITESPACE)
|
(Some(SyntaxKind::ATTR), SyntaxKind::WHITESPACE)
|
||||||
| (Some(SyntaxKind::COMMENT), SyntaxKind::WHITESPACE) => {}
|
| (Some(SyntaxKind::COMMENT), SyntaxKind::WHITESPACE) => {}
|
||||||
@ -182,8 +183,12 @@ struct S;
|
|||||||
|
|
||||||
impl Foo for S {
|
impl Foo for S {
|
||||||
fn bar(&self) {}
|
fn bar(&self) {}
|
||||||
fn foo(&self) { unimplemented!() }
|
fn foo(&self) {
|
||||||
fn baz(&self) { unimplemented!() }<|>
|
unimplemented!()
|
||||||
|
}
|
||||||
|
fn baz(&self) {
|
||||||
|
unimplemented!()
|
||||||
|
}<|>
|
||||||
}",
|
}",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -216,7 +221,9 @@ struct S;
|
|||||||
|
|
||||||
impl Foo for S {
|
impl Foo for S {
|
||||||
fn bar(&self) {}
|
fn bar(&self) {}
|
||||||
fn foo(&self) { unimplemented!() }<|>
|
fn foo(&self) {
|
||||||
|
unimplemented!()
|
||||||
|
}<|>
|
||||||
}",
|
}",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -233,7 +240,9 @@ impl Foo for S { <|> }",
|
|||||||
trait Foo { fn foo(&self); }
|
trait Foo { fn foo(&self); }
|
||||||
struct S;
|
struct S;
|
||||||
impl Foo for S {
|
impl Foo for S {
|
||||||
fn foo(&self) { unimplemented!() }<|>
|
fn foo(&self) {
|
||||||
|
unimplemented!()
|
||||||
|
}<|>
|
||||||
}",
|
}",
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -250,7 +259,9 @@ impl Foo for S {}<|>",
|
|||||||
trait Foo { fn foo(&self); }
|
trait Foo { fn foo(&self); }
|
||||||
struct S;
|
struct S;
|
||||||
impl Foo for S {
|
impl Foo for S {
|
||||||
fn foo(&self) { unimplemented!() }<|>
|
fn foo(&self) {
|
||||||
|
unimplemented!()
|
||||||
|
}<|>
|
||||||
}",
|
}",
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@ -301,7 +312,9 @@ struct S;
|
|||||||
|
|
||||||
mod my_mod {
|
mod my_mod {
|
||||||
impl crate::Foo for S {
|
impl crate::Foo for S {
|
||||||
fn valid(some: u32) -> bool { unimplemented!() }<|>
|
fn valid(some: u32) -> bool {
|
||||||
|
unimplemented!()
|
||||||
|
}<|>
|
||||||
}
|
}
|
||||||
}",
|
}",
|
||||||
)
|
)
|
||||||
@ -329,7 +342,9 @@ trait Foo {
|
|||||||
}
|
}
|
||||||
struct S;
|
struct S;
|
||||||
impl Foo for S {
|
impl Foo for S {
|
||||||
fn foo(&self) { unimplemented!() }<|>
|
fn foo(&self) {
|
||||||
|
unimplemented!()
|
||||||
|
}<|>
|
||||||
}"#,
|
}"#,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user