One big cleanup pass of clippy lints

Co-authored-by: Mikayla <mikayla@zed.dev>
This commit is contained in:
ForLoveOfCats 2022-08-10 17:39:24 -04:00 committed by K Simmons
parent e7540d2833
commit 8ba2f77148
138 changed files with 1328 additions and 1366 deletions

View file

@ -33,7 +33,7 @@ impl Anchor {
} else {
buffer
.fragment_id_for_anchor(self)
.cmp(&buffer.fragment_id_for_anchor(other))
.cmp(buffer.fragment_id_for_anchor(other))
};
fragment_id_comparison
@ -43,17 +43,17 @@ impl Anchor {
pub fn min(&self, other: &Self, buffer: &BufferSnapshot) -> Self {
if self.cmp(other, buffer).is_le() {
self.clone()
*self
} else {
other.clone()
*other
}
}
pub fn max(&self, other: &Self, buffer: &BufferSnapshot) -> Self {
if self.cmp(other, buffer).is_ge() {
self.clone()
*self
} else {
other.clone()
*other
}
}
@ -67,7 +67,7 @@ impl Anchor {
pub fn bias_left(&self, buffer: &BufferSnapshot) -> Anchor {
if self.bias == Bias::Left {
self.clone()
*self
} else {
buffer.anchor_before(self)
}
@ -75,13 +75,13 @@ impl Anchor {
pub fn bias_right(&self, buffer: &BufferSnapshot) -> Anchor {
if self.bias == Bias::Right {
self.clone()
*self
} else {
buffer.anchor_after(self)
}
}
pub fn summary<'a, D>(&self, content: &'a BufferSnapshot) -> D
pub fn summary<D>(&self, content: &BufferSnapshot) -> D
where
D: TextDimension,
{
@ -100,7 +100,7 @@ where
T: ToOffset,
{
fn to_offset(&self, snapshot: &BufferSnapshot) -> Range<usize> {
self.start.to_offset(snapshot)..self.end.to_offset(&snapshot)
self.start.to_offset(snapshot)..self.end.to_offset(snapshot)
}
fn to_point(&self, snapshot: &BufferSnapshot) -> Range<Point> {
@ -122,7 +122,7 @@ impl AnchorRangeExt for Range<Anchor> {
fn cmp(&self, other: &Range<Anchor>, buffer: &BufferSnapshot) -> Result<Ordering> {
Ok(match self.start.cmp(&other.start, buffer) {
Ordering::Equal => other.end.cmp(&self.end, buffer),
ord @ _ => ord,
ord => ord,
})
}
}

View file

@ -41,6 +41,10 @@ impl Locator {
pub fn len(&self) -> usize {
self.0.len()
}
pub fn is_empty(&self) -> bool {
self.len() == 0
}
}
impl Default for Locator {

View file

@ -26,6 +26,12 @@ impl OperationKey {
}
}
impl<T: Operation> Default for OperationQueue<T> {
fn default() -> Self {
OperationQueue::new()
}
}
impl<T: Operation> OperationQueue<T> {
pub fn new() -> Self {
OperationQueue(SumTree::new())
@ -35,6 +41,10 @@ impl<T: Operation> OperationQueue<T> {
self.0.summary().len
}
pub fn is_empty(&self) -> bool {
self.len() == 0
}
pub fn insert(&mut self, mut ops: Vec<T>) {
ops.sort_by_key(|op| op.lamport_timestamp());
ops.dedup_by_key(|op| op.lamport_timestamp());

View file

@ -548,7 +548,7 @@ mod tests {
let composed = patches[0].compose(&patches[1]);
log::info!("composed patch: {:?}", &composed);
let mut actual_chars = initial_chars.clone();
let mut actual_chars = initial_chars;
for edit in composed.0 {
actual_chars.splice(
edit.new.start as usize..edit.new.start as usize + edit.old.len(),
@ -570,7 +570,7 @@ mod tests {
apply_patch(&mut expected, &old, &inserted);
apply_patch(&mut expected, &new, &inserted);
let mut actual = original.clone();
let mut actual = original;
apply_patch(&mut actual, &composed, &expected);
assert_eq!(
actual.into_iter().collect::<String>(),

View file

@ -23,7 +23,7 @@ impl Point {
Point::new(0, 0)
}
pub fn from_str(s: &str) -> Self {
pub fn parse_str(s: &str) -> Self {
let mut point = Self::zero();
for (row, line) in s.split('\n').enumerate() {
point.row = row as u32;

View file

@ -123,6 +123,10 @@ impl Rope {
self.chunks.extent(&())
}
pub fn is_empty(&self) -> bool {
self.len() == 0
}
pub fn max_point(&self) -> Point {
self.chunks.extent(&())
}
@ -152,7 +156,7 @@ impl Rope {
Bytes::new(self, range)
}
pub fn chunks<'a>(&'a self) -> Chunks<'a> {
pub fn chunks(&self) -> Chunks {
self.chunks_in_range(0..self.len())
}
@ -896,7 +900,7 @@ impl sum_tree::Summary for TextSummary {
}
}
impl<'a> std::ops::Add<Self> for TextSummary {
impl std::ops::Add<Self> for TextSummary {
type Output = Self;
fn add(mut self, rhs: Self) -> Self::Output {
@ -946,7 +950,7 @@ pub trait TextDimension: 'static + for<'a> Dimension<'a, ChunkSummary> {
fn add_assign(&mut self, other: &Self);
}
impl<'a, D1: TextDimension, D2: TextDimension> TextDimension for (D1, D2) {
impl<D1: TextDimension, D2: TextDimension> TextDimension for (D1, D2) {
fn from_text_summary(summary: &TextSummary) -> Self {
(
D1::from_text_summary(summary),

View file

@ -42,7 +42,7 @@ fn test_random_edits(mut rng: StdRng) {
let mut reference_string = RandomCharIter::new(&mut rng)
.take(reference_string_len)
.collect::<String>();
let mut buffer = Buffer::new(0, 0, reference_string.clone().into());
let mut buffer = Buffer::new(0, 0, reference_string.clone());
LineEnding::normalize(&mut reference_string);
buffer.history.group_interval = Duration::from_millis(rng.gen_range(0..=200));
@ -56,7 +56,7 @@ fn test_random_edits(mut rng: StdRng) {
for _i in 0..operations {
let (edits, _) = buffer.randomly_edit(&mut rng, 5);
for (old_range, new_text) in edits.iter().rev() {
reference_string.replace_range(old_range.clone(), &new_text);
reference_string.replace_range(old_range.clone(), new_text);
}
assert_eq!(buffer.text(), reference_string);
@ -677,9 +677,9 @@ fn test_concurrent_edits() {
buffer1.apply_op(buf2_op.clone()).unwrap();
buffer1.apply_op(buf3_op.clone()).unwrap();
buffer2.apply_op(buf1_op.clone()).unwrap();
buffer2.apply_op(buf3_op.clone()).unwrap();
buffer3.apply_op(buf1_op.clone()).unwrap();
buffer3.apply_op(buf2_op.clone()).unwrap();
buffer2.apply_op(buf3_op).unwrap();
buffer3.apply_op(buf1_op).unwrap();
buffer3.apply_op(buf2_op).unwrap();
assert_eq!(buffer1.text(), "a12c34e56");
assert_eq!(buffer2.text(), "a12c34e56");
@ -704,7 +704,7 @@ fn test_random_concurrent_edits(mut rng: StdRng) {
let mut network = Network::new(rng.clone());
for i in 0..peers {
let mut buffer = Buffer::new(i as ReplicaId, 0, base_text.clone().into());
let mut buffer = Buffer::new(i as ReplicaId, 0, base_text.clone());
buffer.history.group_interval = Duration::from_millis(rng.gen_range(0..=200));
buffers.push(buffer);
replica_ids.push(i as u16);

View file

@ -530,7 +530,7 @@ impl Buffer {
let mut version = clock::Global::new();
let visible_text = Rope::from(history.base_text.as_ref());
if visible_text.len() > 0 {
if !visible_text.is_empty() {
let insertion_timestamp = InsertionTimestamp {
replica_id: 0,
local: 1,
@ -860,7 +860,7 @@ impl Buffer {
return;
}
let edits = ranges.into_iter().zip(new_text.into_iter());
let edits = ranges.iter().zip(new_text.iter());
let mut edits_patch = Patch::default();
let mut insertion_slices = Vec::new();
let cx = Some(version.clone());
@ -1242,6 +1242,7 @@ impl Buffer {
}
}
#[allow(clippy::needless_collect)]
pub fn undo_to_transaction(&mut self, transaction_id: TransactionId) -> Vec<Operation> {
let transactions = self
.history
@ -1249,6 +1250,7 @@ impl Buffer {
.iter()
.map(|entry| entry.transaction.clone())
.collect::<Vec<_>>();
transactions
.into_iter()
.map(|transaction| self.undo_or_redo(transaction).unwrap())
@ -1270,6 +1272,7 @@ impl Buffer {
}
}
#[allow(clippy::needless_collect)]
pub fn redo_to_transaction(&mut self, transaction_id: TransactionId) -> Vec<Operation> {
let transactions = self
.history
@ -1277,6 +1280,7 @@ impl Buffer {
.iter()
.map(|entry| entry.transaction.clone())
.collect::<Vec<_>>();
transactions
.into_iter()
.map(|transaction| self.undo_or_redo(transaction).unwrap())
@ -1293,7 +1297,7 @@ impl Buffer {
id: self.local_clock.tick(),
version: self.version(),
counts,
transaction_version: transaction.start.clone(),
transaction_version: transaction.start,
};
self.apply_undo(&undo)?;
let operation = Operation::Undo {
@ -1490,6 +1494,7 @@ impl Buffer {
start..end
}
#[allow(clippy::type_complexity)]
pub fn randomly_edit<T>(
&mut self,
rng: &mut T,
@ -1574,6 +1579,10 @@ impl BufferSnapshot {
self.visible_text.len()
}
pub fn is_empty(&self) -> bool {
self.len() == 0
}
pub fn chars(&self) -> impl Iterator<Item = char> + '_ {
self.chars_at(0)
}
@ -1609,8 +1618,8 @@ impl BufferSnapshot {
.filter(|&len| {
let left = self
.chars_for_range(offset - len..offset)
.flat_map(|c| char::to_lowercase(c));
let right = needle[..len].chars().flat_map(|c| char::to_lowercase(c));
.flat_map(char::to_lowercase);
let right = needle[..len].chars().flat_map(char::to_lowercase);
left.eq(right)
})
.last()
@ -1684,15 +1693,12 @@ impl BufferSnapshot {
&self.version
}
pub fn chars_at<'a, T: ToOffset>(&'a self, position: T) -> impl Iterator<Item = char> + 'a {
pub fn chars_at<T: ToOffset>(&self, position: T) -> impl Iterator<Item = char> + '_ {
let offset = position.to_offset(self);
self.visible_text.chars_at(offset)
}
pub fn reversed_chars_at<'a, T: ToOffset>(
&'a self,
position: T,
) -> impl Iterator<Item = char> + 'a {
pub fn reversed_chars_at<T: ToOffset>(&self, position: T) -> impl Iterator<Item = char> + '_ {
let offset = position.to_offset(self);
self.visible_text.reversed_chars_at(offset)
}
@ -1702,13 +1708,13 @@ impl BufferSnapshot {
self.visible_text.reversed_chunks_in_range(range)
}
pub fn bytes_in_range<'a, T: ToOffset>(&'a self, range: Range<T>) -> rope::Bytes<'a> {
pub fn bytes_in_range<T: ToOffset>(&self, range: Range<T>) -> rope::Bytes<'_> {
let start = range.start.to_offset(self);
let end = range.end.to_offset(self);
self.visible_text.bytes_in_range(start..end)
}
pub fn text_for_range<'a, T: ToOffset>(&'a self, range: Range<T>) -> Chunks<'a> {
pub fn text_for_range<T: ToOffset>(&self, range: Range<T>) -> Chunks<'_> {
let start = range.start.to_offset(self);
let end = range.end.to_offset(self);
self.visible_text.chunks_in_range(start..end)
@ -1729,7 +1735,7 @@ impl BufferSnapshot {
.all(|chunk| chunk.matches(|c: char| !c.is_whitespace()).next().is_none())
}
pub fn text_summary_for_range<'a, D, O: ToOffset>(&'a self, range: Range<O>) -> D
pub fn text_summary_for_range<D, O: ToOffset>(&self, range: Range<O>) -> D
where
D: TextDimension,
{
@ -1788,7 +1794,7 @@ impl BufferSnapshot {
})
}
fn summary_for_anchor<'a, D>(&'a self, anchor: &Anchor) -> D
fn summary_for_anchor<D>(&self, anchor: &Anchor) -> D
where
D: TextDimension,
{
@ -2048,7 +2054,7 @@ impl<'a, D: TextDimension + Ord, F: FnMut(&FragmentSummary) -> bool> Iterator fo
break;
}
if !fragment.was_visible(&self.since, &self.undos) && fragment.visible {
if !fragment.was_visible(self.since, self.undos) && fragment.visible {
let mut visible_end = cursor.end(&None).visible;
if fragment.id == *self.range.end.0 {
visible_end = cmp::min(
@ -2070,7 +2076,7 @@ impl<'a, D: TextDimension + Ord, F: FnMut(&FragmentSummary) -> bool> Iterator fo
}
self.new_end = new_end;
} else if fragment.was_visible(&self.since, &self.undos) && !fragment.visible {
} else if fragment.was_visible(self.since, self.undos) && !fragment.visible {
let mut deleted_end = cursor.end(&None).deleted;
if fragment.id == *self.range.end.0 {
deleted_end = cmp::min(
@ -2354,10 +2360,7 @@ impl Operation {
}
pub fn is_edit(&self) -> bool {
match self {
Operation::Edit { .. } => true,
_ => false,
}
matches!(self, Operation::Edit { .. })
}
}
@ -2423,7 +2426,7 @@ impl LineEnding {
}
pub trait ToOffset {
fn to_offset<'a>(&self, snapshot: &BufferSnapshot) -> usize;
fn to_offset(&self, snapshot: &BufferSnapshot) -> usize;
}
impl ToOffset for Point {
@ -2464,7 +2467,7 @@ impl<'a, T: ToOffset> ToOffset for &'a T {
}
pub trait ToPoint {
fn to_point<'a>(&self, snapshot: &BufferSnapshot) -> Point;
fn to_point(&self, snapshot: &BufferSnapshot) -> Point;
}
impl ToPoint for Anchor {
@ -2492,7 +2495,7 @@ impl ToPoint for Point {
}
pub trait ToPointUtf16 {
fn to_point_utf16<'a>(&self, snapshot: &BufferSnapshot) -> PointUtf16;
fn to_point_utf16(&self, snapshot: &BufferSnapshot) -> PointUtf16;
}
impl ToPointUtf16 for Anchor {
@ -2520,7 +2523,7 @@ impl ToPointUtf16 for Point {
}
pub trait ToOffsetUtf16 {
fn to_offset_utf16<'a>(&self, snapshot: &BufferSnapshot) -> OffsetUtf16;
fn to_offset_utf16(&self, snapshot: &BufferSnapshot) -> OffsetUtf16;
}
impl ToOffsetUtf16 for Anchor {