on master help sign in
clippy lint
commit06aca7691c845d129abc49fb649ea7c42376a077 authorBlaž Hrastnik <blaz@mxxn.io> dateWed 24 Mar 2021, 14:52 (6 years ago) parent8a0ab44
10 files changed+33−30
helix-core/src/auto_pairs.rs+1 helix-core/src/comment.rs+1 helix-core/src/graphemes.rs+6−2 helix-core/src/history.rs+1−1 helix-core/src/match_brackets.rs+1 helix-core/src/position.rs+1−1 helix-core/src/selection.rs+3−3 helix-core/src/syntax.rs+11−11 helix-core/src/transaction.rs+2−6 helix-syntax/build.rs+6−6
helix-core/src/auto_pairs.rs+1
@@ -24,6 +24,7 @@ const CLOSE_BEFORE: &str = ")]}'\":;> \n"; // includes space and newline
2424
2525// TODO: delete implementation where it erases the whole bracket (|) -> |
2626
27+#[must_use]
2728pub fn hook(doc: &Rope, selection: &Selection, ch: char) -> Option<Transaction> {
2829 for &(open, close) in PAIRS {
2930 if open == ch {
helix-core/src/comment.rs+1
@@ -37,6 +37,7 @@ fn find_line_comment(
3737 (commented, skipped, min)
3838}
3939
40+#[must_use]
4041pub fn toggle_line_comments(doc: &Rope, selection: &Selection) -> Transaction {
4142 let text = doc.slice(..);
4243 let mut changes: Vec<Change> = Vec::new();
helix-core/src/graphemes.rs+6−2
@@ -3,6 +3,7 @@ use ropey::{iter::Chunks, str_utils::byte_to_char_idx, RopeSlice};
33use unicode_segmentation::{GraphemeCursor, GraphemeIncomplete};
44use unicode_width::UnicodeWidthStr;
55
6+#[must_use]
67pub fn grapheme_width(g: &str) -> usize {
78 if g.as_bytes()[0] <= 127 {
89 // Fast-path ascii.
@@ -26,6 +27,7 @@ pub fn grapheme_width(g: &str) -> usize {
2627 }
2728}
2829
30+#[must_use]
2931pub fn nth_prev_grapheme_boundary(slice: RopeSlice, char_idx: usize, n: usize) -> usize {
3032 // Bounds check
3133 debug_assert!(char_idx <= slice.len_chars());
@@ -71,6 +73,7 @@ pub fn prev_grapheme_boundary(slice: RopeSlice, char_idx: usize) -> usize {
7173 nth_prev_grapheme_boundary(slice, char_idx, 1)
7274}
7375
76+#[must_use]
7477pub fn nth_next_grapheme_boundary(slice: RopeSlice, char_idx: usize, n: usize) -> usize {
7578 // Bounds check
7679 debug_assert!(char_idx <= slice.len_chars());
@@ -138,12 +141,12 @@ pub fn is_grapheme_boundary(slice: RopeSlice, char_idx: usize) -> bool {
138141 let (ctx_chunk, ctx_byte_start, _, _) = slice.chunk_at_byte(n - 1);
139142 gc.provide_context(ctx_chunk, ctx_byte_start);
140143 }
141− _ => unreachable!(),
144+ Err(_) => unreachable!(),
142145 }
143146 }
144147}
145148
146−/// An iterator over the graphemes of a RopeSlice.
149+/// An iterator over the graphemes of a `RopeSlice`.
147150#[derive(Clone)]
148151pub struct RopeGraphemes<'a> {
149152 text: RopeSlice<'a>,
@@ -154,6 +157,7 @@ pub struct RopeGraphemes<'a> {
154157}
155158
156159impl<'a> RopeGraphemes<'a> {
160+ #[must_use]
157161 pub fn new(slice: RopeSlice) -> RopeGraphemes {
158162 let mut chunks = slice.chunks();
159163 let first_chunk = chunks.next().unwrap_or("");
helix-core/src/history.rs+1−1
@@ -53,7 +53,7 @@ impl History {
5353 }
5454
5555 #[inline]
56− pub fn at_root(&self) -> bool {
56+ pub const fn at_root(&self) -> bool {
5757 self.cursor == 0
5858 }
5959
helix-core/src/match_brackets.rs+1
@@ -3,6 +3,7 @@ use crate::{Range, Rope, Selection, Syntax};
33// const PAIRS: &[(char, char)] = &[('(', ')'), ('{', '}'), ('[', ']')];
44// limit matching pairs to only ( ) { } [ ] < >
55
6+#[must_use]
67pub fn find(syntax: &Syntax, doc: &Rope, pos: usize) -> Option<usize> {
78 let tree = syntax.root_layer.tree.as_ref().unwrap();
89
helix-core/src/position.rs+1−1
@@ -37,7 +37,7 @@ impl Position {
3737
3838impl From<(usize, usize)> for Position {
3939 fn from(tuple: (usize, usize)) -> Self {
40− Position {
40+ Self {
4141 row: tuple.0,
4242 col: tuple.1,
4343 }
helix-core/src/selection.rs+3−3
@@ -99,14 +99,14 @@ impl Range {
9999 #[must_use]
100100 pub fn extend(&self, from: usize, to: usize) -> Self {
101101 if from <= self.anchor && to >= self.anchor {
102− return Range {
102+ return Self {
103103 anchor: from,
104104 head: to,
105105 horiz: None,
106106 };
107107 }
108108
109− Range {
109+ Self {
110110 anchor: self.anchor,
111111 head: if abs_difference(from, self.anchor) > abs_difference(to, self.anchor) {
112112 from
@@ -253,7 +253,7 @@ impl Selection {
253253
254254 // fast path for a single selection (cursor)
255255 if ranges.len() == 1 {
256− return Selection {
256+ return Self {
257257 ranges,
258258 primary_index: 0,
259259 };
helix-core/src/syntax.rs+11−11
@@ -66,10 +66,10 @@ impl LanguageConfiguration {
6666 language,
6767 &highlights_query,
6868 &injections_query,
69− &locals_query,
69+ locals_query,
7070 )
7171 .unwrap(); // TODO: no unwrap
72− config.configure(&scopes);
72+ config.configure(scopes);
7373 Some(Arc::new(config))
7474 }
7575 })
@@ -90,8 +90,8 @@ pub struct Loader {
9090}
9191
9292impl Loader {
93− fn init() -> Loader {
94− let mut loader = Loader {
93+ fn init() -> Self {
94+ let mut loader = Self {
9595 language_configs: Vec::new(),
9696 language_config_ids_by_file_type: HashMap::new(),
9797 };
@@ -331,7 +331,7 @@ impl Syntax {
331331
332332 let mut result = HighlightIter {
333333 source,
334− byte_offset: range.map(|r| r.start).unwrap_or(0), // TODO: simplify
334+ byte_offset: range.map_or(0, |r| r.start), // TODO: simplify
335335 injection_callback,
336336 cancellation_flag,
337337 iter_count: 0,
@@ -1019,12 +1019,12 @@ impl<'a> HighlightIterLayer<'a> {
10191019
10201020 if queue.is_empty() {
10211021 break;
1022− } else {
1023− let (next_config, next_depth, next_ranges) = queue.remove(0);
1024− config = next_config;
1025− depth = next_depth;
1026− ranges = next_ranges;
10271022 }
1023+
1024+ let (next_config, next_depth, next_ranges) = queue.remove(0);
1025+ config = next_config;
1026+ depth = next_depth;
1027+ ranges = next_ranges;
10281028 }
10291029
10301030 Ok(result)
@@ -1292,7 +1292,7 @@ where
12921292 // If this capture represents an injection, then process the injection.
12931293 if match_.pattern_index < layer.config.locals_pattern_index {
12941294 let (language_name, content_node, include_children) =
1295− injection_for_match(&layer.config, &layer.config.query, &match_, self.source);
1295+ injection_for_match(layer.config, &layer.config.query, &match_, self.source);
12961296
12971297 // Explicitly remove this match so that none of its other captures will remain
12981298 // in the stream of captures.
helix-core/src/transaction.rs+2−6
@@ -84,11 +84,7 @@ impl ChangeSet {
8484 }
8585
8686 let new_last = match self.changes.as_mut_slice() {
87− [.., Insert(prev)] => {
88− prev.push_tendril(&fragment);
89− return;
90− }
91− [.., Insert(prev), Delete(_)] => {
87+ [.., Insert(prev)] | [.., Insert(prev), Delete(_)] => {
9288 prev.push_tendril(&fragment);
9389 return;
9490 }
@@ -115,7 +111,7 @@ impl ChangeSet {
115111 /// Combine two changesets together.
116112 /// In other words, If `this` goes `docA` → `docB` and `other` represents `docB` → `docC`, the
117113 /// returned value will represent the change `docA` → `docC`.
118− pub fn compose(self, other: ChangeSet) -> Self {
114+ pub fn compose(self, other: Self) -> Self {
119115 debug_assert!(self.len_after() == other.len);
120116
121117 let len = self.changes.len();
helix-syntax/build.rs+6−6
@@ -11,7 +11,7 @@ fn get_debug() -> bool {
1111 env::var("DEBUG").unwrap() == "true"
1212}
1313
14−fn collect_tree_sitter_dirs(ignore: Vec<String>) -> Vec<String> {
14+fn collect_tree_sitter_dirs(ignore: &[String]) -> Vec<String> {
1515 let mut dirs = Vec::new();
1616 for entry in fs::read_dir("languages").unwrap().flatten() {
1717 let path = entry.path();
@@ -97,12 +97,12 @@ fn build_dir(dir: &str, language: &str) {
9797 eprintln!("You can fix in using 'git submodule init && git submodule update --recursive'.");
9898 std::process::exit(1);
9999 }
100− let (c, cpp) = collect_src_files(&dir);
100+ let (c, cpp) = collect_src_files(dir);
101101 if !c.is_empty() {
102− build_c(c, &language);
102+ build_c(c, language);
103103 }
104104 if !cpp.is_empty() {
105− build_cpp(cpp, &language);
105+ build_cpp(cpp, language);
106106 }
107107}
108108
@@ -111,7 +111,7 @@ fn main() {
111111 "tree-sitter-typescript".to_string(),
112112 "tree-sitter-cpp".to_string(),
113113 ];
114− let dirs = collect_tree_sitter_dirs(ignore);
114+ let dirs = collect_tree_sitter_dirs(&ignore);
115115
116116 let mut n_jobs = 0;
117117 let pool = threadpool::Builder::new().build(); // by going through the builder, it'll use num_cpus
@@ -123,7 +123,7 @@ fn main() {
123123
124124 pool.execute(move || {
125125 let language = &dir[12..]; // skip tree-sitter- prefix
126− build_dir(&dir, &language);
126+ build_dir(&dir, language);
127127
128128 // report progress
129129 tx.send(1).unwrap();