on master help sign in
address clippy warnings
b5c3881Blaž Hrastnik
helix-core/src/lib.rs+3
@@ -3,6 +3,9 @@ mod selection;
3mod state;
3mod state;
4mod transaction;
4mod transaction;
5
5
6+pub use ropey::Rope;
7+pub use tendril::StrTendril as Tendril;
8+
6pub use buffer::Buffer;
9pub use buffer::Buffer;
7
10
8pub use selection::Range as SelectionRange;
11pub use selection::Range as SelectionRange;
helix-core/src/selection.rs+12−4
@@ -30,12 +30,14 @@ impl Range {
30
30
31 /// Start of the range.
31 /// Start of the range.
32 #[inline]
32 #[inline]
33+ #[must_use]
33 pub fn from(&self) -> usize {
34 pub fn from(&self) -> usize {
34 std::cmp::min(self.anchor, self.head)
35 std::cmp::min(self.anchor, self.head)
35 }
36 }
36
37
37 /// End of the range.
38 /// End of the range.
38 #[inline]
39 #[inline]
40+ #[must_use]
39 pub fn to(&self) -> usize {
41 pub fn to(&self) -> usize {
40 std::cmp::max(self.anchor, self.head)
42 std::cmp::max(self.anchor, self.head)
41 }
43 }
@@ -47,6 +49,7 @@ impl Range {
47 }
49 }
48
50
49 /// Check two ranges for overlap.
51 /// Check two ranges for overlap.
52+ #[must_use]
50 pub fn overlaps(&self, other: &Self) -> bool {
53 pub fn overlaps(&self, other: &Self) -> bool {
51 // cursor overlap is checked differently
54 // cursor overlap is checked differently
52 if self.is_empty() {
55 if self.is_empty() {
@@ -59,6 +62,7 @@ impl Range {
59 // TODO: map
62 // TODO: map
60
63
61 /// Extend the range to cover at least `from` `to`.
64 /// Extend the range to cover at least `from` `to`.
65+ #[must_use]
62 pub fn extend(&self, from: usize, to: usize) -> Self {
66 pub fn extend(&self, from: usize, to: usize) -> Self {
63 if from <= self.anchor && to >= self.anchor {
67 if from <= self.anchor && to >= self.anchor {
64 return Range {
68 return Range {
@@ -90,12 +94,14 @@ pub struct Selection {
90impl Selection {
94impl Selection {
91 // map
95 // map
92 // eq
96 // eq
97+
98+ #[must_use]
93 pub fn primary(&self) -> Range {
99 pub fn primary(&self) -> Range {
94 self.ranges[self.primary_index]
100 self.ranges[self.primary_index]
95 }
101 }
96
102
97 /// Ensure selection containing only the primary selection.
103 /// Ensure selection containing only the primary selection.
98− pub fn as_single(self) -> Self {
104+ pub fn into_single(self) -> Self {
99 if self.ranges.len() == 1 {
105 if self.ranges.len() == 1 {
100 self
106 self
101 } else {
107 } else {
@@ -109,6 +115,7 @@ impl Selection {
109 // add_range // push
115 // add_range // push
110 // replace_range
116 // replace_range
111
117
118+ #[must_use]
112 /// Constructs a selection holding a single range.
119 /// Constructs a selection holding a single range.
113 pub fn single(anchor: usize, head: usize) -> Self {
120 pub fn single(anchor: usize, head: usize) -> Self {
114 Self {
121 Self {
@@ -117,11 +124,12 @@ impl Selection {
117 }
124 }
118 }
125 }
119
126
127+ #[must_use]
120 pub fn new(ranges: SmallVec<[Range; 1]>, primary_index: usize) -> Self {
128 pub fn new(ranges: SmallVec<[Range; 1]>, primary_index: usize) -> Self {
121− fn normalize(mut ranges: SmallVec<[Range; 1]>, primary_index: usize) -> Selection {
129+ fn normalize(mut ranges: SmallVec<[Range; 1]>, mut primary_index: usize) -> Selection {
122 let primary = ranges[primary_index];
130 let primary = ranges[primary_index];
123− ranges.sort_unstable_by_key(|range| range.from());
131+ ranges.sort_unstable_by_key(Range::from);
124− let mut primary_index = ranges.iter().position(|&range| range == primary).unwrap();
132+ primary_index = ranges.iter().position(|&range| range == primary).unwrap();
125
133
126 let mut result: SmallVec<[Range; 1]> = SmallVec::new();
134 let mut result: SmallVec<[Range; 1]> = SmallVec::new();
127
135
helix-core/src/state.rs+1
@@ -8,6 +8,7 @@ pub struct State {
8}
8}
9
9
10impl State {
10impl State {
11+ #[must_use]
11 pub fn new(buffer: Buffer) -> Self {
12 pub fn new(buffer: Buffer) -> Self {
12 Self {
13 Self {
13 buffer,
14 buffer,
helix-core/src/transaction.rs+4−7
@@ -14,10 +14,7 @@
14// distance: usize,
14// distance: usize,
15// }
15// }
16
16
17−use crate::{Buffer, Selection};
17+use crate::{Buffer, Rope, Selection, Tendril};
18−
19−use ropey::Rope;
20−use tendril::StrTendril as Tendril;
21
18
22// TODO: divided into three different operations, I sort of like having just
19// TODO: divided into three different operations, I sort of like having just
23// Splice { extent, Option<text>, distance } better.
20// Splice { extent, Option<text>, distance } better.
@@ -56,6 +53,7 @@ pub struct ChangeSet {
56}
53}
57
54
58impl ChangeSet {
55impl ChangeSet {
56+ #[must_use]
59 pub fn new(buf: &Buffer) -> Self {
57 pub fn new(buf: &Buffer) -> Self {
60 let len = buf.contents.len_chars();
58 let len = buf.contents.len_chars();
61 Self {
59 Self {
@@ -105,8 +103,7 @@ impl ChangeSet {
105 head_a = a;
103 head_a = a;
106 head_b = changes_b.next();
104 head_b = changes_b.next();
107 }
105 }
108− (None, _) => return Err(()),
109− (_, None) => return Err(()),
106+ (None, _) | (_, None) => return Err(()),
110 (Some(Retain(i)), Some(Retain(j))) => match i.cmp(&j) {
107 (Some(Retain(i)), Some(Retain(j))) => match i.cmp(&j) {
111 Ordering::Less => {
108 Ordering::Less => {
112 changes.push(Retain(i));
109 changes.push(Retain(i));
@@ -221,7 +218,7 @@ impl ChangeSet {
221
218
222 let mut pos = 0;
219 let mut pos = 0;
223
220
224− for change in self.changes.iter() {
221+ for change in &self.changes {
225 use Change::*;
222 use Change::*;
226 match change {
223 match change {
227 Retain(n) => {
224 Retain(n) => {