Skip to content
This repository was archived by the owner on Dec 29, 2022. It is now read-only.

Commit 3f38776

Browse files
authored
Merge pull request #1027 from alexheretic/master
cargo fmt
2 parents 783bfd0 + e5938b7 commit 3f38776

33 files changed

+1134
-882
lines changed

build.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,7 @@ fn commit_hash() -> Option<String> {
5353

5454
fn commit_date() -> Option<String> {
5555
Command::new("git")
56-
.args(&["log",
57-
"-1",
58-
"--date=short",
59-
"--pretty=format:%cd"])
56+
.args(&["log", "-1", "--date=short", "--pretty=format:%cd"])
6057
.output()
6158
.ok()
6259
.and_then(|r| String::from_utf8(r.stdout).ok())

src/actions/diagnostics.rs

Lines changed: 47 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@ use std::collections::HashMap;
1818
use std::iter;
1919
use std::path::{Path, PathBuf};
2020

21-
use languageserver_types::{DiagnosticRelatedInformation, DiagnosticSeverity, Location, NumberOrString, Range};
2221
use crate::lsp_data::ls_util;
23-
use serde_json;
22+
use languageserver_types::{
23+
DiagnosticRelatedInformation, DiagnosticSeverity, Location, NumberOrString, Range,
24+
};
25+
use log::debug;
2426
use rls_span::compiler::DiagnosticSpan;
25-
use url::Url;
2627
use serde_derive::Deserialize;
27-
use log::debug;
28+
use serde_json;
29+
use url::Url;
2830

2931
pub use languageserver_types::Diagnostic;
3032

@@ -240,8 +242,7 @@ fn make_related_information<'a>(
240242
},
241243
message: label.trim().to_owned(),
242244
})
243-
})
244-
.collect();
245+
}).collect();
245246

246247
related_information.sort_by_key(|info| info.location.range.start);
247248

@@ -264,8 +265,7 @@ fn make_suggestions<'a>(
264265
.as_ref()
265266
.and_then(|label| label_suggestion(span, label))
266267
})
267-
})
268-
.collect();
268+
}).collect();
269269

270270
// Suggestions are displayed at primary span, so if the change is somewhere
271271
// else, be sure to specify that
@@ -313,7 +313,9 @@ trait IsWithin {
313313

314314
impl<T: PartialOrd<T>> IsWithin for ::std::ops::Range<T> {
315315
fn is_within(&self, other: &Self) -> bool {
316-
self.start >= other.start && self.start <= other.end && self.end <= other.end
316+
self.start >= other.start
317+
&& self.start <= other.end
318+
&& self.end <= other.end
317319
&& self.end >= other.start
318320
}
319321
}
@@ -372,7 +374,8 @@ mod diagnostic_message_test {
372374
}
373375

374376
fn to_messages(&self) -> Vec<(String, Vec<String>)> {
375-
(self.single_file_results()
377+
(self
378+
.single_file_results()
376379
.iter()
377380
.map(|(diagnostic, _)| {
378381
(
@@ -385,8 +388,7 @@ mod diagnostic_message_test {
385388
.map(|d| d.message.clone())
386389
.collect(),
387390
)
388-
})
389-
.collect())
391+
}).collect())
390392
}
391393

392394
fn to_primary_messages(&self) -> Vec<String> {
@@ -656,7 +658,8 @@ help: consider borrowing here: `&string`"#,
656658
"the operation is ineffective. Consider reducing it to `1`\n\n\
657659
note: #[warn(identity_op)] implied by #[warn(clippy)]\n\
658660
help: for further information visit "
659-
.to_owned() + link
661+
.to_owned()
662+
+ link
660663
);
661664

662665
assert!(messages[0].1.is_empty(), "{:?}", messages[0].1);
@@ -677,21 +680,28 @@ help: consider borrowing here: `&string`"#,
677680
assert_eq!(diag.diagnostics.len(), 1, "{:#?}", diag.diagnostics);
678681

679682
let file = &diag.diagnostics.keys().nth(0).unwrap();
680-
assert!(file.to_str().unwrap().ends_with("src/main.rs"), "Unexpected file {:?}", file);
683+
assert!(
684+
file.to_str().unwrap().ends_with("src/main.rs"),
685+
"Unexpected file {:?}",
686+
file
687+
);
681688

682689
let diagnostic = &diag.diagnostics.values().nth(0).unwrap()[0];
683690
assert_eq!(diagnostic.0.source, Some("rustc".into()));
684-
assert_eq!(diagnostic.0.range, Range {
685-
start: Position::new(2, 4),
686-
end: Position::new(2, 27),
687-
});
691+
assert_eq!(
692+
diagnostic.0.range,
693+
Range {
694+
start: Position::new(2, 4),
695+
end: Position::new(2, 27),
696+
}
697+
);
688698

689699
let messages = diag.to_messages();
690700
assert_eq!(
691701
messages[0].0,
692702
"no method named `write_fmt` found for type `std::string::String` \
693-
in the current scope\n\n\
694-
help: items from traits can only be used if the trait is in scope"
703+
in the current scope\n\n\
704+
help: items from traits can only be used if the trait is in scope"
695705
);
696706

697707
assert!(messages[0].1.is_empty(), "{:?}", messages[0].1);
@@ -713,21 +723,25 @@ help: consider borrowing here: `&string`"#,
713723
assert_eq!(diag.diagnostics.len(), 1, "{:#?}", diag.diagnostics);
714724

715725
let file = &diag.diagnostics.keys().nth(0).unwrap();
716-
assert!(file.to_str().unwrap().ends_with("src/main.rs"), "Unexpected file {:?}", file);
726+
assert!(
727+
file.to_str().unwrap().ends_with("src/main.rs"),
728+
"Unexpected file {:?}",
729+
file
730+
);
717731

718732
let diagnostic = &diag.diagnostics.values().nth(0).unwrap()[0];
719733
assert_eq!(diagnostic.0.source, Some("rustc".into()));
720-
assert_eq!(diagnostic.0.range, Range {
721-
start: Position::new(4, 4),
722-
end: Position::new(4, 33),
723-
});
724-
725-
let messages = diag.to_messages();
726734
assert_eq!(
727-
messages[0].0,
728-
"expected token: `,`"
735+
diagnostic.0.range,
736+
Range {
737+
start: Position::new(4, 4),
738+
end: Position::new(4, 33),
739+
}
729740
);
730741

742+
let messages = diag.to_messages();
743+
assert_eq!(messages[0].0, "expected token: `,`");
744+
731745
assert!(messages[0].1.is_empty(), "{:?}", messages[0].1);
732746
}
733747
}
@@ -845,7 +859,10 @@ mod diagnostic_suggestion_test {
845859
.find(|s| s.new_text == "use std::fmt::Write;\n\n")
846860
.expect("`use std::fmt::Write;` not found");
847861

848-
assert_eq!(change_to_mut.label, "Line 1: Add `use std::fmt::Write;\n\n`");
862+
assert_eq!(
863+
change_to_mut.label,
864+
"Line 1: Add `use std::fmt::Write;\n\n`"
865+
);
849866

850867
assert_eq!(
851868
change_to_mut.range,

src/actions/format.rs

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ use std::io::Write;
1717
use std::path::{Path, PathBuf};
1818
use std::process::{Command, Stdio};
1919

20-
use rand::{Rng, thread_rng};
2120
use log::debug;
22-
use rustfmt_nightly::{Config, Session, Input};
21+
use rand::{thread_rng, Rng};
22+
use rustfmt_nightly::{Config, Input, Session};
2323
use serde_json;
2424

2525
/// Specified which `rustfmt` to use.
@@ -28,14 +28,14 @@ pub enum Rustfmt {
2828
/// (Path to external `rustfmt`, cwd where it should be spawned at)
2929
External(PathBuf, PathBuf),
3030
/// Statically linked `rustfmt`
31-
Internal
31+
Internal,
3232
}
3333

3434
impl From<Option<(String, PathBuf)>> for Rustfmt {
3535
fn from(value: Option<(String, PathBuf)>) -> Rustfmt {
3636
match value {
3737
Some((path, cwd)) => Rustfmt::External(PathBuf::from(path), cwd),
38-
None => Rustfmt::Internal
38+
None => Rustfmt::Internal,
3939
}
4040
}
4141
}
@@ -49,7 +49,12 @@ impl Rustfmt {
4949
}
5050
}
5151

52-
fn format_external(path: &PathBuf, cwd: &PathBuf, input: String, cfg: Config) -> Result<String, String> {
52+
fn format_external(
53+
path: &PathBuf,
54+
cwd: &PathBuf,
55+
input: String,
56+
cfg: Config,
57+
) -> Result<String, String> {
5358
let (_file_handle, config_path) = gen_config_file(&cfg)?;
5459
let args = rustfmt_args(&cfg, &config_path);
5560

@@ -62,19 +67,25 @@ fn format_external(path: &PathBuf, cwd: &PathBuf, input: String, cfg: Config) ->
6267
.map_err(|_| format!("Couldn't spawn `{}`", path.display()))?;
6368

6469
{
65-
let stdin = rustfmt.stdin.as_mut()
70+
let stdin = rustfmt
71+
.stdin
72+
.as_mut()
6673
.ok_or_else(|| "Failed to open rustfmt stdin".to_string())?;
67-
stdin.write_all(input.as_bytes())
74+
stdin
75+
.write_all(input.as_bytes())
6876
.map_err(|_| "Failed to pass input to rustfmt".to_string())?;
6977
}
7078

71-
rustfmt.wait_with_output()
79+
rustfmt
80+
.wait_with_output()
7281
.map_err(|err| format!("Error running rustfmt: {}", err))
73-
.and_then(|out| String::from_utf8(out.stdout)
74-
.map_err(|_| "Formatted code is not valid UTF-8".to_string()))
82+
.and_then(|out| {
83+
String::from_utf8(out.stdout)
84+
.map_err(|_| "Formatted code is not valid UTF-8".to_string())
85+
})
7586
}
7687

77-
fn format_internal(input: String, config:Config) -> Result<String, String> {
88+
fn format_internal(input: String, config: Config) -> Result<String, String> {
7889
let mut buf = Vec::<u8>::new();
7990

8091
{
@@ -100,8 +111,7 @@ fn format_internal(input: String, config:Config) -> Result<String, String> {
100111
}
101112
}
102113

103-
String::from_utf8(buf)
104-
.map_err(|_| "Reformat output is not a valid UTF-8".into())
114+
String::from_utf8(buf).map_err(|_| "Reformat output is not a valid UTF-8".into())
105115
}
106116

107117
fn random_file() -> Result<(File, PathBuf), String> {

src/actions/hover.rs

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ use rls_span::{Column, Row, Span, ZeroIndexed};
2121
use rls_vfs::{self as vfs, Vfs};
2222
use rustfmt_nightly::NewlineStyle;
2323

24-
use std::path::{Path, PathBuf};
2524
use log::*;
25+
use std::path::{Path, PathBuf};
2626

2727
/// Cleanup documentation code blocks. The `docs` are expected to have
2828
/// the preceeding `///` or `//!` prefixes already trimmed away. Rust code
@@ -217,8 +217,7 @@ fn extract_and_process_docs(vfs: &Vfs, file: &Path, row_start: Row<ZeroIndexed>)
217217
"failed to extract docs: row: {:?}, file: {:?} ({:?})",
218218
row_start, file, e
219219
);
220-
})
221-
.ok()
220+
}).ok()
222221
.map(|docs| docs.join("\n"))
223222
.map(|docs| process_docs(&docs))
224223
.and_then(empty_to_none)
@@ -544,13 +543,13 @@ fn skip_path_components<P: AsRef<Path>>(
544543
skip_components: usize,
545544
) -> PathBuf {
546545
if path.starts_with(prefix) {
547-
let comps: PathBuf = path.components().skip(skip_components).fold(
548-
PathBuf::new(),
549-
|mut comps, comp| {
550-
comps.push(comp);
551-
comps
552-
},
553-
);
546+
let comps: PathBuf =
547+
path.components()
548+
.skip(skip_components)
549+
.fold(PathBuf::new(), |mut comps, comp| {
550+
comps.push(comp);
551+
comps
552+
});
554553
comps
555554
} else {
556555
path
@@ -648,7 +647,11 @@ fn racer_match_to_def(ctx: &InitActionContext, m: &racer::Match) -> Option<Def>
648647
let matchstr_len = matchstr.len() as u32;
649648
let docs = m.docs.trim().to_string();
650649
m.coords.map(|coords| {
651-
assert!(coords.row.0 > 0, "racer_match_to_def: racer returned `0` for a 1-based row: {:?}", m);
650+
assert!(
651+
coords.row.0 > 0,
652+
"racer_match_to_def: racer returned `0` for a 1-based row: {:?}",
653+
m
654+
);
652655
let (row, col1) = requests::from_racer_coord(coords);
653656
let col2 = Column::new_zero_indexed(col1.0 + matchstr_len);
654657
let row = Row::new_zero_indexed(row.0 - 1);
@@ -775,8 +778,7 @@ fn format_object(rustfmt: Rustfmt, fmt_config: &FmtConfig, the_type: String) ->
775778
} else {
776779
part.to_string()
777780
}
778-
})
779-
.collect::<Vec<String>>();
781+
}).collect::<Vec<String>>();
780782
decl = &decl[0..pos];
781783
if hidden_count != tuple_parts.len() {
782784
format!("{}({})", decl, tuple_parts.join(", "))
@@ -826,8 +828,7 @@ fn format_method(rustfmt: Rustfmt, fmt_config: &FmtConfig, the_type: String) ->
826828
};
827829
let line = line.trim_left_matches(should_trim);
828830
format!("{}\n", line)
829-
})
830-
.collect()
831+
}).collect()
831832
}
832833
Err(e) => {
833834
error!("format_method: error: {:?}, input: {:?}", e, method);
@@ -942,7 +943,7 @@ pub mod test {
942943
use crate::lsp_data::{Position, TextDocumentIdentifier, TextDocumentPositionParams};
943944
use crate::server::{Output, RequestId};
944945
use rls_analysis as analysis;
945-
use serde_derive::{Serialize, Deserialize};
946+
use serde_derive::{Deserialize, Serialize};
946947
use serde_json as json;
947948
use url::Url;
948949

@@ -1175,8 +1176,7 @@ pub mod test {
11751176
let result = test.run(&self.project_dir, &self.ctx);
11761177
result.save(&save_dir).unwrap();
11771178
result
1178-
})
1179-
.collect();
1179+
}).collect();
11801180

11811181
let failures: Vec<TestFailure> = results
11821182
.iter()
@@ -1195,8 +1195,7 @@ pub mod test {
11951195
}
11961196
Err(e) => Some((Err(e), actual_result)),
11971197
}
1198-
})
1199-
.filter(|failed_result| failed_result.is_some())
1198+
}).filter(|failed_result| failed_result.is_some())
12001199
.map(|failed_result| failed_result.unwrap())
12011200
.map(|failed_result| match failed_result {
12021201
(Ok(expect_result), actual_result) => {
@@ -1221,8 +1220,7 @@ pub mod test {
12211220
actual_file: save_file,
12221221
}
12231222
}
1224-
})
1225-
.collect();
1223+
}).collect();
12261224

12271225
Ok(failures)
12281226
}
@@ -1251,8 +1249,7 @@ pub mod test {
12511249
.scan(0, |_, ch| if ch.is_whitespace() { Some(1) } else { None })
12521250
.fuse()
12531251
.sum()
1254-
})
1255-
.unwrap_or(0);
1252+
}).unwrap_or(0);
12561253

12571254
text.lines()
12581255
.map(|line| line.chars().skip(indent).collect::<String>())

0 commit comments

Comments
 (0)