on master help sign in
address clippy warnings
commitb5c38812e923581a31eb5d38ddb96d44afd6505d authorBlaž Hrastnik <blaz@mxxn.io> dateThu 28 May 2020, 14:45 (6 years ago) parent23109f1
4 files changed+20−11
helix-core/src/lib.rs+3 helix-core/src/selection.rs+12−4 helix-core/src/state.rs+1 helix-core/src/transaction.rs+4−7
helix-core/src/lib.rs+3
@@ -3,6 +3,9 @@ mod selection;
33mod state;
44mod transaction;
55
6+pub use ropey::Rope;
7+pub use tendril::StrTendril as Tendril;
8+
69pub use buffer::Buffer;
710
811pub use selection::Range as SelectionRange;
helix-core/src/selection.rs+12−4
@@ -30,12 +30,14 @@ impl Range {
3030
3131 /// Start of the range.
3232 #[inline]
33+ #[must_use]
3334 pub fn from(&self) -> usize {
3435 std::cmp::min(self.anchor, self.head)
3536 }
3637
3738 /// End of the range.
3839 #[inline]
40+ #[must_use]
3941 pub fn to(&self) -> usize {
4042 std::cmp::max(self.anchor, self.head)
4143 }
@@ -47,6 +49,7 @@ impl Range {
4749 }
4850
4951 /// Check two ranges for overlap.
52+ #[must_use]
5053 pub fn overlaps(&self, other: &Self) -> bool {
5154 // cursor overlap is checked differently
5255 if self.is_empty() {
@@ -59,6 +62,7 @@ impl Range {
5962 // TODO: map
6063
6164 /// Extend the range to cover at least `from` `to`.
65+ #[must_use]
6266 pub fn extend(&self, from: usize, to: usize) -> Self {
6367 if from <= self.anchor && to >= self.anchor {
6468 return Range {
@@ -90,12 +94,14 @@ pub struct Selection {
9094impl Selection {
9195 // map
9296 // eq
97+
98+ #[must_use]
9399 pub fn primary(&self) -> Range {
94100 self.ranges[self.primary_index]
95101 }
96102
97103 /// Ensure selection containing only the primary selection.
98− pub fn as_single(self) -> Self {
104+ pub fn into_single(self) -> Self {
99105 if self.ranges.len() == 1 {
100106 self
101107 } else {
@@ -109,6 +115,7 @@ impl Selection {
109115 // add_range // push
110116 // replace_range
111117
118+ #[must_use]
112119 /// Constructs a selection holding a single range.
113120 pub fn single(anchor: usize, head: usize) -> Self {
114121 Self {
@@ -117,11 +124,12 @@ impl Selection {
117124 }
118125 }
119126
127+ #[must_use]
120128 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 {
122130 let primary = ranges[primary_index];
123− ranges.sort_unstable_by_key(|range| range.from());
124− let mut primary_index = ranges.iter().position(|&range| range == primary).unwrap();
131+ ranges.sort_unstable_by_key(Range::from);
132+ primary_index = ranges.iter().position(|&range| range == primary).unwrap();
125133
126134 let mut result: SmallVec<[Range; 1]> = SmallVec::new();
127135
helix-core/src/state.rs+1
@@ -8,6 +8,7 @@ pub struct State {
88}
99
1010impl State {
11+ #[must_use]
1112 pub fn new(buffer: Buffer) -> Self {
1213 Self {
1314 buffer,
helix-core/src/transaction.rs+4−7
@@ -14,10 +14,7 @@
1414// distance: usize,
1515// }
1616
17−use crate::{Buffer, Selection};
18−
19−use ropey::Rope;
20−use tendril::StrTendril as Tendril;
17+use crate::{Buffer, Rope, Selection, Tendril};
2118
2219// TODO: divided into three different operations, I sort of like having just
2320// Splice { extent, Option<text>, distance } better.
@@ -56,6 +53,7 @@ pub struct ChangeSet {
5653}
5754
5855impl ChangeSet {
56+ #[must_use]
5957 pub fn new(buf: &Buffer) -> Self {
6058 let len = buf.contents.len_chars();
6159 Self {
@@ -105,8 +103,7 @@ impl ChangeSet {
105103 head_a = a;
106104 head_b = changes_b.next();
107105 }
108− (None, _) => return Err(()),
109− (_, None) => return Err(()),
106+ (None, _) | (_, None) => return Err(()),
110107 (Some(Retain(i)), Some(Retain(j))) => match i.cmp(&j) {
111108 Ordering::Less => {
112109 changes.push(Retain(i));
@@ -221,7 +218,7 @@ impl ChangeSet {
221218
222219 let mut pos = 0;
223220
224− for change in self.changes.iter() {
221+ for change in &self.changes {
225222 use Change::*;
226223 match change {
227224 Retain(n) => {