mirror of
https://github.com/rust-lang/rust-analyzer
synced 2024-11-15 17:28:09 +00:00
Merge #8863
8863: fix: don't add extra whitespace around fields r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
67c157b7dd
4 changed files with 81 additions and 0 deletions
|
@ -186,6 +186,31 @@ fn test_fn() {
|
||||||
let one = 1;
|
let one = 1;
|
||||||
let s = TestStruct{ ..a };
|
let s = TestStruct{ ..a };
|
||||||
}
|
}
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_fill_struct_fields_blank_line() {
|
||||||
|
check_fix(
|
||||||
|
r#"
|
||||||
|
struct S { a: (), b: () }
|
||||||
|
|
||||||
|
fn f() {
|
||||||
|
S {
|
||||||
|
$0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
r#"
|
||||||
|
struct S { a: (), b: () }
|
||||||
|
|
||||||
|
fn f() {
|
||||||
|
S {
|
||||||
|
a: (),
|
||||||
|
b: (),
|
||||||
|
};
|
||||||
|
}
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,3 +29,13 @@ impl DiagnosticWithFix for RemoveThisSemicolon {
|
||||||
Some(fix("remove_semicolon", "Remove this semicolon", source_change, semicolon))
|
Some(fix("remove_semicolon", "Remove this semicolon", source_change, semicolon))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use crate::diagnostics::tests::check_fix;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn remove_semicolon() {
|
||||||
|
check_fix(r#"fn f() -> i32 { 92$0; }"#, r#"fn f() -> i32 { 92 }"#);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -40,3 +40,45 @@ impl DiagnosticWithFix for ReplaceFilterMapNextWithFindMap {
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(test)]
|
||||||
|
mod tests {
|
||||||
|
use crate::diagnostics::tests::check_fix;
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn replace_with_wind_map() {
|
||||||
|
check_fix(
|
||||||
|
r#"
|
||||||
|
//- /main.rs crate:main deps:core
|
||||||
|
use core::iter::Iterator;
|
||||||
|
use core::option::Option::{self, Some, None};
|
||||||
|
fn foo() {
|
||||||
|
let m = [1, 2, 3].iter().$0filter_map(|x| if *x == 2 { Some (4) } else { None }).next();
|
||||||
|
}
|
||||||
|
//- /core/lib.rs crate:core
|
||||||
|
pub mod option {
|
||||||
|
pub enum Option<T> { Some(T), None }
|
||||||
|
}
|
||||||
|
pub mod iter {
|
||||||
|
pub trait Iterator {
|
||||||
|
type Item;
|
||||||
|
fn filter_map<B, F>(self, f: F) -> FilterMap where F: FnMut(Self::Item) -> Option<B> { FilterMap }
|
||||||
|
fn next(&mut self) -> Option<Self::Item>;
|
||||||
|
}
|
||||||
|
pub struct FilterMap {}
|
||||||
|
impl Iterator for FilterMap {
|
||||||
|
type Item = i32;
|
||||||
|
fn next(&mut self) -> i32 { 7 }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
r#"
|
||||||
|
use core::iter::Iterator;
|
||||||
|
use core::option::Option::{self, Some, None};
|
||||||
|
fn foo() {
|
||||||
|
let m = [1, 2, 3].iter().find_map(|x| if *x == 2 { Some (4) } else { None });
|
||||||
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -378,6 +378,10 @@ impl ast::RecordExprFieldList {
|
||||||
make::tokens::single_space()
|
make::tokens::single_space()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if is_multiline {
|
||||||
|
normalize_ws_between_braces(self.syntax());
|
||||||
|
}
|
||||||
|
|
||||||
let position = match self.fields().last() {
|
let position = match self.fields().last() {
|
||||||
Some(last_field) => {
|
Some(last_field) => {
|
||||||
let comma = match last_field
|
let comma = match last_field
|
||||||
|
|
Loading…
Reference in a new issue