Enable clippy::useless_conversion (#8767)

This PR enables the
[`clippy::useless_conversion`](https://rust-lang.github.io/rust-clippy/master/index.html#/useless_conversion)
rule and fixes the outstanding violations.

Release Notes:

- N/A
This commit is contained in:
Marshall Bowers
2024-03-03 10:22:55 -05:00
committed by GitHub
parent 20d133322a
commit fe04f69caf
30 changed files with 53 additions and 66 deletions
+7 -13
View File
@@ -502,7 +502,7 @@ impl DisplaySnapshot {
/// Returns text chunks starting at the end of the given display row in reverse until the start of the file
pub fn reverse_text_chunks(&self, display_row: u32) -> impl Iterator<Item = &str> {
(0..=display_row).into_iter().rev().flat_map(|row| {
(0..=display_row).rev().flat_map(|row| {
self.block_snapshot
.chunks(row..row + 1, false, Highlights::default())
.map(|h| h.text)
@@ -1455,10 +1455,8 @@ pub mod tests {
}"#
.unindent();
let theme = SyntaxTheme::new_test(vec![
("mod.body", Hsla::red().into()),
("fn.name", Hsla::blue().into()),
]);
let theme =
SyntaxTheme::new_test(vec![("mod.body", Hsla::red()), ("fn.name", Hsla::blue())]);
let language = Arc::new(
Language::new(
LanguageConfig {
@@ -1545,10 +1543,8 @@ pub mod tests {
}"#
.unindent();
let theme = SyntaxTheme::new_test(vec![
("mod.body", Hsla::red().into()),
("fn.name", Hsla::blue().into()),
]);
let theme =
SyntaxTheme::new_test(vec![("mod.body", Hsla::red()), ("fn.name", Hsla::blue())]);
let language = Arc::new(
Language::new(
LanguageConfig {
@@ -1616,10 +1612,8 @@ pub mod tests {
async fn test_chunks_with_text_highlights(cx: &mut gpui::TestAppContext) {
cx.update(|cx| init_test(cx, |_| {}));
let theme = SyntaxTheme::new_test(vec![
("operator", Hsla::red().into()),
("string", Hsla::green().into()),
]);
let theme =
SyntaxTheme::new_test(vec![("operator", Hsla::red()), ("string", Hsla::green())]);
let language = Arc::new(
Language::new(
LanguageConfig {
+6 -9
View File
@@ -2004,7 +2004,7 @@ impl EditorElement {
let text_width = bounds.size.width - gutter_dimensions.width;
let overscroll = size(em_width, px(0.));
let _snapshot = {
editor.set_visible_line_count((bounds.size.height / line_height).into(), cx);
editor.set_visible_line_count(bounds.size.height / line_height, cx);
let editor_width = text_width - gutter_dimensions.margin - overscroll.width - em_width;
let wrap_width = match editor.soft_wrap_mode(cx) {
@@ -2037,7 +2037,7 @@ impl EditorElement {
// The scroll position is a fractional point, the whole number of which represents
// the top of the window in terms of display rows.
let start_row = scroll_position.y as u32;
let height_in_lines = f32::from(bounds.size.height / line_height);
let height_in_lines = bounds.size.height / line_height;
let max_row = snapshot.max_point().row();
// Add 1 to ensure selections bleed off screen
@@ -2262,7 +2262,7 @@ impl EditorElement {
});
let scroll_max = point(
f32::from((scroll_width - text_size.width) / em_width).max(0.0),
((scroll_width - text_size.width) / em_width).max(0.0),
max_row as f32,
);
@@ -2722,11 +2722,8 @@ impl EditorElement {
};
let scroll_position = position_map.snapshot.scroll_position();
let x = f32::from(
(scroll_position.x * max_glyph_width - delta.x) / max_glyph_width,
);
let y =
f32::from((scroll_position.y * line_height - delta.y) / line_height);
let x = (scroll_position.x * max_glyph_width - delta.x) / max_glyph_width;
let y = (scroll_position.y * line_height - delta.y) / line_height;
let scroll_position =
point(x, y).clamp(&point(0., 0.), &position_map.scroll_max);
editor.scroll(scroll_position, axis, cx);
@@ -3268,7 +3265,7 @@ impl PositionMap {
let position = position - text_bounds.origin;
let y = position.y.max(px(0.)).min(self.size.height);
let x = position.x + (scroll_position.x * self.em_width);
let row = (f32::from(y / self.line_height) + scroll_position.y) as u32;
let row = ((y / self.line_height) + scroll_position.y) as u32;
let (column, x_overshoot_after_line_end) = if let Some(line) = self
.line_layouts
-1
View File
@@ -62,7 +62,6 @@ pub fn expand_macro_recursively(
project
.read(cx)
.language_servers_for_buffer(buffer.read(cx), cx)
.into_iter()
.find_map(|(adapter, server)| {
if adapter.name.0.as_ref() == "rust-analyzer" {
Some((
+3 -4
View File
@@ -62,7 +62,7 @@ impl Editor {
line_height: Pixels,
cx: &mut ViewContext<Editor>,
) -> bool {
let visible_lines = f32::from(viewport_height / line_height);
let visible_lines = viewport_height / line_height;
let display_map = self.display_map.update(cx, |map, cx| map.snapshot(cx));
let mut scroll_position = self.scroll_manager.scroll_position(&display_map);
let max_scroll_top = if matches!(self.mode, EditorMode::AutoHeight { .. }) {
@@ -241,11 +241,10 @@ impl Editor {
let scroll_right = scroll_left + viewport_width;
if target_left < scroll_left {
self.scroll_manager.anchor.offset.x = (target_left / max_glyph_width).into();
self.scroll_manager.anchor.offset.x = target_left / max_glyph_width;
true
} else if target_right > scroll_right {
self.scroll_manager.anchor.offset.x =
((target_right - viewport_width) / max_glyph_width).into();
self.scroll_manager.anchor.offset.x = (target_right - viewport_width) / max_glyph_width;
true
} else {
false