Auto-fix clippy::collapsible_if violations (#36428)

Release Notes:

- N/A
This commit is contained in:
Piotr Osiewicz 2025-08-19 15:27:24 +02:00 committed by GitHub
parent 9e8ec72bd5
commit 8f567383e4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
281 changed files with 6628 additions and 7089 deletions

View file

@ -510,17 +510,16 @@ pub fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
vim.switch_mode(Mode::Normal, true, window, cx);
}
vim.update_editor(cx, |_, editor, cx| {
if let Some(first_sel) = initial_selections {
if let Some(tx_id) = editor
if let Some(first_sel) = initial_selections
&& let Some(tx_id) = editor
.buffer()
.update(cx, |multi, cx| multi.last_transaction_id(cx))
{
let last_sel = editor.selections.disjoint_anchors();
editor.modify_transaction_selection_history(tx_id, |old| {
old.0 = first_sel;
old.1 = Some(last_sel);
});
}
{
let last_sel = editor.selections.disjoint_anchors();
editor.modify_transaction_selection_history(tx_id, |old| {
old.0 = first_sel;
old.1 = Some(last_sel);
});
}
});
})
@ -1713,14 +1712,12 @@ impl Vim {
match c {
'%' => {
self.update_editor(cx, |_, editor, cx| {
if let Some((_, buffer, _)) = editor.active_excerpt(cx) {
if let Some(file) = buffer.read(cx).file() {
if let Some(local) = file.as_local() {
if let Some(str) = local.path().to_str() {
ret.push_str(str)
}
}
}
if let Some((_, buffer, _)) = editor.active_excerpt(cx)
&& let Some(file) = buffer.read(cx).file()
&& let Some(local) = file.as_local()
&& let Some(str) = local.path().to_str()
{
ret.push_str(str)
}
});
}
@ -1954,19 +1951,19 @@ impl ShellExec {
return;
};
if let Some(mut stdin) = running.stdin.take() {
if let Some(snapshot) = input_snapshot {
let range = range.clone();
cx.background_spawn(async move {
for chunk in snapshot.text_for_range(range) {
if stdin.write_all(chunk.as_bytes()).log_err().is_none() {
return;
}
if let Some(mut stdin) = running.stdin.take()
&& let Some(snapshot) = input_snapshot
{
let range = range.clone();
cx.background_spawn(async move {
for chunk in snapshot.text_for_range(range) {
if stdin.write_all(chunk.as_bytes()).log_err().is_none() {
return;
}
stdin.flush().log_err();
})
.detach();
}
}
stdin.flush().log_err();
})
.detach();
};
let output = cx

View file

@ -63,15 +63,15 @@ impl Vim {
}
fn literal(&mut self, action: &Literal, window: &mut Window, cx: &mut Context<Self>) {
if let Some(Operator::Literal { prefix }) = self.active_operator() {
if let Some(prefix) = prefix {
if let Some(keystroke) = Keystroke::parse(&action.0).ok() {
window.defer(cx, |window, cx| {
window.dispatch_keystroke(keystroke, cx);
});
}
return self.handle_literal_input(prefix, "", window, cx);
if let Some(Operator::Literal { prefix }) = self.active_operator()
&& let Some(prefix) = prefix
{
if let Some(keystroke) = Keystroke::parse(&action.0).ok() {
window.defer(cx, |window, cx| {
window.dispatch_keystroke(keystroke, cx);
});
}
return self.handle_literal_input(prefix, "", window, cx);
}
self.insert_literal(Some(action.1), "", window, cx);

View file

@ -1811,10 +1811,10 @@ fn previous_word_end(
.ignore_punctuation(ignore_punctuation);
let mut point = point.to_point(map);
if point.column < map.buffer_snapshot.line_len(MultiBufferRow(point.row)) {
if let Some(ch) = map.buffer_snapshot.chars_at(point).next() {
point.column += ch.len_utf8() as u32;
}
if point.column < map.buffer_snapshot.line_len(MultiBufferRow(point.row))
&& let Some(ch) = map.buffer_snapshot.chars_at(point).next()
{
point.column += ch.len_utf8() as u32;
}
for _ in 0..times {
let new_point = movement::find_preceding_boundary_point(
@ -1986,10 +1986,10 @@ fn previous_subword_end(
.ignore_punctuation(ignore_punctuation);
let mut point = point.to_point(map);
if point.column < map.buffer_snapshot.line_len(MultiBufferRow(point.row)) {
if let Some(ch) = map.buffer_snapshot.chars_at(point).next() {
point.column += ch.len_utf8() as u32;
}
if point.column < map.buffer_snapshot.line_len(MultiBufferRow(point.row))
&& let Some(ch) = map.buffer_snapshot.chars_at(point).next()
{
point.column += ch.len_utf8() as u32;
}
for _ in 0..times {
let new_point = movement::find_preceding_boundary_point(
@ -2054,10 +2054,10 @@ pub(crate) fn last_non_whitespace(
let classifier = map.buffer_snapshot.char_classifier_at(from.to_point(map));
// NOTE: depending on clip_at_line_end we may already be one char back from the end.
if let Some((ch, _)) = map.buffer_chars_at(end_of_line).next() {
if classifier.kind(ch) != CharKind::Whitespace {
return end_of_line.to_display_point(map);
}
if let Some((ch, _)) = map.buffer_chars_at(end_of_line).next()
&& classifier.kind(ch) != CharKind::Whitespace
{
return end_of_line.to_display_point(map);
}
for (ch, offset) in map.reverse_buffer_chars_at(end_of_line) {

View file

@ -74,10 +74,10 @@ impl Vim {
editor.change_selections(Default::default(), window, cx, |s| {
s.move_with(|map, selection| {
let mut cursor = selection.head();
if kind.linewise() {
if let Some(column) = original_columns.get(&selection.id) {
*cursor.column_mut() = *column
}
if kind.linewise()
&& let Some(column) = original_columns.get(&selection.id)
{
*cursor.column_mut() = *column
}
cursor = map.clip_point(cursor, Bias::Left);
selection.collapse_to(cursor, selection.goal)

View file

@ -256,10 +256,8 @@ impl Vim {
}
});
if should_jump {
if let Some(anchor) = anchor {
self.motion(Motion::Jump { anchor, line }, window, cx)
}
if should_jump && let Some(anchor) = anchor {
self.motion(Motion::Jump { anchor, line }, window, cx)
}
}
}

View file

@ -221,14 +221,14 @@ impl Vim {
if actions.is_empty() {
return None;
}
if globals.replayer.is_none() {
if let Some(recording_register) = globals.recording_register {
globals
.recordings
.entry(recording_register)
.or_default()
.push(ReplayableAction::Action(Repeat.boxed_clone()));
}
if globals.replayer.is_none()
&& let Some(recording_register) = globals.recording_register
{
globals
.recordings
.entry(recording_register)
.or_default()
.push(ReplayableAction::Action(Repeat.boxed_clone()));
}
let mut mode = None;
@ -320,10 +320,10 @@ impl Vim {
// vim doesn't treat 3a1 as though you literally repeated a1
// 3 times, instead it inserts the content thrice at the insert position.
if let Some(to_repeat) = repeatable_insert(&actions[0]) {
if let Some(ReplayableAction::Action(action)) = actions.last() {
if NormalBefore.partial_eq(&**action) {
actions.pop();
}
if let Some(ReplayableAction::Action(action)) = actions.last()
&& NormalBefore.partial_eq(&**action)
{
actions.pop();
}
let mut new_actions = actions.clone();

View file

@ -100,10 +100,10 @@ fn cover_or_next<I: Iterator<Item = (Range<usize>, Range<usize>)>>(
for (open_range, close_range) in ranges {
let start_off = open_range.start;
let end_off = close_range.end;
if let Some(range_filter) = range_filter {
if !range_filter(open_range.clone(), close_range.clone()) {
continue;
}
if let Some(range_filter) = range_filter
&& !range_filter(open_range.clone(), close_range.clone())
{
continue;
}
let candidate = CandidateWithRanges {
candidate: CandidateRange {
@ -1060,11 +1060,11 @@ fn text_object(
.filter_map(|(r, m)| if m == target { Some(r) } else { None })
.collect();
matches.sort_by_key(|r| r.start);
if let Some(buffer_range) = matches.first() {
if !buffer_range.is_empty() {
let range = excerpt.map_range_from_buffer(buffer_range.clone());
return Some(range.start.to_display_point(map)..range.end.to_display_point(map));
}
if let Some(buffer_range) = matches.first()
&& !buffer_range.is_empty()
{
let range = excerpt.map_range_from_buffer(buffer_range.clone());
return Some(range.start.to_display_point(map)..range.end.to_display_point(map));
}
let buffer_range = excerpt.map_range_from_buffer(around_range.clone());
return Some(buffer_range.start.to_display_point(map)..buffer_range.end.to_display_point(map));
@ -1529,25 +1529,25 @@ fn surrounding_markers(
Some((ch, _)) => ch,
_ => '\0',
};
if let Some((ch, range)) = movement::chars_after(map, point).next() {
if ch == open_marker && before_ch != '\\' {
if open_marker == close_marker {
let mut total = 0;
for ((ch, _), (before_ch, _)) in movement::chars_before(map, point).tuple_windows()
{
if ch == '\n' {
break;
}
if ch == open_marker && before_ch != '\\' {
total += 1;
}
if let Some((ch, range)) = movement::chars_after(map, point).next()
&& ch == open_marker
&& before_ch != '\\'
{
if open_marker == close_marker {
let mut total = 0;
for ((ch, _), (before_ch, _)) in movement::chars_before(map, point).tuple_windows() {
if ch == '\n' {
break;
}
if total % 2 == 0 {
opening = Some(range)
if ch == open_marker && before_ch != '\\' {
total += 1;
}
} else {
}
if total % 2 == 0 {
opening = Some(range)
}
} else {
opening = Some(range)
}
}
@ -1558,10 +1558,10 @@ fn surrounding_markers(
break;
}
if let Some((before_ch, _)) = chars_before.peek() {
if *before_ch == '\\' {
continue;
}
if let Some((before_ch, _)) = chars_before.peek()
&& *before_ch == '\\'
{
continue;
}
if ch == open_marker {

View file

@ -412,20 +412,20 @@ impl MarksState {
let mut to_write = HashMap::default();
for (key, value) in &new_points {
if self.is_global_mark(key) {
if self.global_marks.get(key) != Some(&MarkLocation::Path(path.clone())) {
if let Some(workspace_id) = self.workspace_id(cx) {
let path = path.clone();
let key = key.clone();
cx.background_spawn(async move {
DB.set_global_mark_path(workspace_id, key, path).await
})
.detach_and_log_err(cx);
}
self.global_marks
.insert(key.clone(), MarkLocation::Path(path.clone()));
if self.is_global_mark(key)
&& self.global_marks.get(key) != Some(&MarkLocation::Path(path.clone()))
{
if let Some(workspace_id) = self.workspace_id(cx) {
let path = path.clone();
let key = key.clone();
cx.background_spawn(async move {
DB.set_global_mark_path(workspace_id, key, path).await
})
.detach_and_log_err(cx);
}
self.global_marks
.insert(key.clone(), MarkLocation::Path(path.clone()));
}
if old_points.and_then(|o| o.get(key)) != Some(value) {
to_write.insert(key.clone(), value.clone());
@ -456,15 +456,15 @@ impl MarksState {
buffer: &Entity<Buffer>,
cx: &mut Context<Self>,
) {
if let MarkLocation::Buffer(entity_id) = old_path {
if let Some(old_marks) = self.multibuffer_marks.remove(&entity_id) {
let buffer_marks = old_marks
.into_iter()
.map(|(k, v)| (k, v.into_iter().map(|anchor| anchor.text_anchor).collect()))
.collect();
self.buffer_marks
.insert(buffer.read(cx).remote_id(), buffer_marks);
}
if let MarkLocation::Buffer(entity_id) = old_path
&& let Some(old_marks) = self.multibuffer_marks.remove(&entity_id)
{
let buffer_marks = old_marks
.into_iter()
.map(|(k, v)| (k, v.into_iter().map(|anchor| anchor.text_anchor).collect()))
.collect();
self.buffer_marks
.insert(buffer.read(cx).remote_id(), buffer_marks);
}
self.watch_buffer(MarkLocation::Path(new_path.clone()), buffer, cx);
self.serialize_buffer_marks(new_path, buffer, cx);
@ -512,10 +512,9 @@ impl MarksState {
.watched_buffers
.get(&buffer_id.clone())
.map(|(path, _, _)| path.clone())
&& let Some(new_path) = this.path_for_buffer(&buffer, cx)
{
if let Some(new_path) = this.path_for_buffer(&buffer, cx) {
this.rename_buffer(old_path, new_path, &buffer, cx)
}
this.rename_buffer(old_path, new_path, &buffer, cx)
}
}
_ => {}
@ -897,13 +896,13 @@ impl VimGlobals {
self.stop_recording_after_next_action = false;
}
}
if self.replayer.is_none() {
if let Some(recording_register) = self.recording_register {
self.recordings
.entry(recording_register)
.or_default()
.push(ReplayableAction::Action(action));
}
if self.replayer.is_none()
&& let Some(recording_register) = self.recording_register
{
self.recordings
.entry(recording_register)
.or_default()
.push(ReplayableAction::Action(action));
}
}
@ -1330,10 +1329,10 @@ impl MarksMatchInfo {
let mut offset = 0;
for chunk in chunks {
line.push_str(chunk.text);
if let Some(highlight_style) = chunk.syntax_highlight_id {
if let Some(highlight) = highlight_style.style(cx.theme().syntax()) {
highlights.push((offset..offset + chunk.text.len(), highlight))
}
if let Some(highlight_style) = chunk.syntax_highlight_id
&& let Some(highlight) = highlight_style.style(cx.theme().syntax())
{
highlights.push((offset..offset + chunk.text.len(), highlight))
}
offset += chunk.text.len();
}

View file

@ -174,12 +174,11 @@ impl Vim {
if ch.to_string() == pair.start {
let start = offset;
let mut end = start + 1;
if surround {
if let Some((next_ch, _)) = chars_and_offset.peek() {
if next_ch.eq(&' ') {
end += 1;
}
}
if surround
&& let Some((next_ch, _)) = chars_and_offset.peek()
&& next_ch.eq(&' ')
{
end += 1;
}
edits.push((start..end, ""));
anchors.push(start..start);
@ -193,12 +192,11 @@ impl Vim {
if ch.to_string() == pair.end {
let mut start = offset;
let end = start + 1;
if surround {
if let Some((next_ch, _)) = reverse_chars_and_offsets.peek() {
if next_ch.eq(&' ') {
start -= 1;
}
}
if surround
&& let Some((next_ch, _)) = reverse_chars_and_offsets.peek()
&& next_ch.eq(&' ')
{
start -= 1;
}
edits.push((start..end, ""));
break;

View file

@ -217,10 +217,11 @@ impl NeovimConnection {
.expect("Could not set nvim cursor position");
}
if let Some(NeovimData::Get { mode, state }) = self.data.back() {
if *mode == Mode::Normal && *state == marked_text {
return;
}
if let Some(NeovimData::Get { mode, state }) = self.data.back()
&& *mode == Mode::Normal
&& *state == marked_text
{
return;
}
self.data.push_back(NeovimData::Put {
state: marked_text.to_string(),

View file

@ -788,10 +788,10 @@ impl Vim {
editor.selections.line_mode = false;
editor.unregister_addon::<VimAddon>();
editor.set_relative_line_number(None, cx);
if let Some(vim) = Vim::globals(cx).focused_vim() {
if vim.entity_id() == cx.entity().entity_id() {
Vim::globals(cx).focused_vim = None;
}
if let Some(vim) = Vim::globals(cx).focused_vim()
&& vim.entity_id() == cx.entity().entity_id()
{
Vim::globals(cx).focused_vim = None;
}
}
@ -833,10 +833,10 @@ impl Vim {
if self.exit_temporary_mode {
self.exit_temporary_mode = false;
// Don't switch to insert mode if the action is temporary_normal.
if let Some(action) = keystroke_event.action.as_ref() {
if action.as_any().downcast_ref::<TemporaryNormal>().is_some() {
return;
}
if let Some(action) = keystroke_event.action.as_ref()
&& action.as_any().downcast_ref::<TemporaryNormal>().is_some()
{
return;
}
self.switch_mode(Mode::Insert, false, window, cx)
}
@ -1006,10 +1006,10 @@ impl Vim {
Some((point, goal))
})
}
if last_mode == Mode::Insert || last_mode == Mode::Replace {
if let Some(prior_tx) = prior_tx {
editor.group_until_transaction(prior_tx, cx)
}
if (last_mode == Mode::Insert || last_mode == Mode::Replace)
&& let Some(prior_tx) = prior_tx
{
editor.group_until_transaction(prior_tx, cx)
}
editor.change_selections(SelectionEffects::no_scroll(), window, cx, |s| {
@ -1031,14 +1031,16 @@ impl Vim {
}
let snapshot = s.display_map();
if let Some(pending) = s.pending.as_mut() {
if pending.selection.reversed && mode.is_visual() && !last_mode.is_visual() {
let mut end = pending.selection.end.to_point(&snapshot.buffer_snapshot);
end = snapshot
.buffer_snapshot
.clip_point(end + Point::new(0, 1), Bias::Right);
pending.selection.end = snapshot.buffer_snapshot.anchor_before(end);
}
if let Some(pending) = s.pending.as_mut()
&& pending.selection.reversed
&& mode.is_visual()
&& !last_mode.is_visual()
{
let mut end = pending.selection.end.to_point(&snapshot.buffer_snapshot);
end = snapshot
.buffer_snapshot
.clip_point(end + Point::new(0, 1), Bias::Right);
pending.selection.end = snapshot.buffer_snapshot.anchor_before(end);
}
s.move_with(|map, selection| {
@ -1536,12 +1538,12 @@ impl Vim {
if self.mode == Mode::Insert && self.current_tx.is_some() {
if self.current_anchor.is_none() {
self.current_anchor = Some(newest);
} else if self.current_anchor.as_ref().unwrap() != &newest {
if let Some(tx_id) = self.current_tx.take() {
self.update_editor(cx, |_, editor, cx| {
editor.group_until_transaction(tx_id, cx)
});
}
} else if self.current_anchor.as_ref().unwrap() != &newest
&& let Some(tx_id) = self.current_tx.take()
{
self.update_editor(cx, |_, editor, cx| {
editor.group_until_transaction(tx_id, cx)
});
}
} else if self.mode == Mode::Normal && newest.start != newest.end {
if matches!(newest.goal, SelectionGoal::HorizontalRange { .. }) {