chore: Clippy fixes for 1.80 (#13987)

Piotr Osiewicz created

The biggest hurdle turned out to be use of `Arc<Language>` in maps, as
`clippy::mutable_key_type` started triggering on it (due to - I suppose
- internal mutability on `HighlightMap`?). I switched over to using
`LanguageId` as the key type in some of the callsites, as that's what
`Language` uses anyways for it's hash/eq, though I've still had to
suppress the lint outside of language crate.

/cc @maxdeviant , le clippy guru.

Release Notes:

- N/A

Change summary

Cargo.toml                             |  2 +-
crates/collab/src/db/tests/db_tests.rs |  2 +-
crates/editor/src/editor.rs            |  1 +
crates/gpui/build.rs                   |  2 +-
crates/gpui/src/text_system.rs         | 20 --------------------
crates/language/src/syntax_map.rs      | 11 ++++++-----
crates/project/src/project.rs          |  2 ++
crates/project/src/task_inventory.rs   |  5 -----
8 files changed, 12 insertions(+), 33 deletions(-)

Detailed changes

Cargo.toml 🔗

@@ -518,7 +518,7 @@ single_range_in_vec_init = "allow"
 
 # There are a bunch of rules currently failing in the `style` group, so
 # allow all of those, for now.
-style = "allow"
+style = { level = "allow", priority = -1 }
 
 # Individual rules that have violations in the codebase:
 almost_complete_range = "allow"

crates/collab/src/db/tests/db_tests.rs 🔗

@@ -562,7 +562,7 @@ fn test_fuzzy_like_string() {
     assert_eq!(Database::fuzzy_like_string(" z  "), "%z%");
 }
 
-#[cfg(target = "macos")]
+#[cfg(target_os = "macos")]
 #[gpui::test]
 async fn test_fuzzy_search_users(cx: &mut gpui::TestAppContext) {
     let test_db = tests::TestDb::postgres(cx.executor());

crates/editor/src/editor.rs 🔗

@@ -11093,6 +11093,7 @@ impl Editor {
                 if *singleton_buffer_edited {
                     if let Some(project) = &self.project {
                         let project = project.read(cx);
+                        #[allow(clippy::mutable_key_type)]
                         let languages_affected = multibuffer
                             .read(cx)
                             .all_buffers()

crates/gpui/build.rs 🔗

@@ -7,7 +7,7 @@ use std::env;
 
 fn main() {
     let target = env::var("CARGO_CFG_TARGET_OS");
-
+    println!("cargo::rustc-check-cfg=cfg(gles)");
     match target.as_deref() {
         Ok("macos") => {
             #[cfg(target_os = "macos")]

crates/gpui/src/text_system.rs 🔗

@@ -658,26 +658,6 @@ impl Hash for RenderGlyphParams {
     }
 }
 
-/// The parameters for rendering an emoji glyph.
-#[derive(Clone, Debug, PartialEq)]
-pub struct RenderEmojiParams {
-    pub(crate) font_id: FontId,
-    pub(crate) glyph_id: GlyphId,
-    pub(crate) font_size: Pixels,
-    pub(crate) scale_factor: f32,
-}
-
-impl Eq for RenderEmojiParams {}
-
-impl Hash for RenderEmojiParams {
-    fn hash<H: Hasher>(&self, state: &mut H) {
-        self.font_id.0.hash(state);
-        self.glyph_id.0.hash(state);
-        self.font_size.0.to_bits().hash(state);
-        self.scale_factor.to_bits().hash(state);
-    }
-}
-
 /// The configuration details for identifying a specific font.
 #[derive(Clone, Debug, Eq, PartialEq, Hash)]
 pub struct Font {

crates/language/src/syntax_map.rs 🔗

@@ -1207,7 +1207,7 @@ fn get_injections(
     language_registry: &Arc<LanguageRegistry>,
     depth: usize,
     changed_ranges: &[Range<usize>],
-    combined_injection_ranges: &mut HashMap<Arc<Language>, Vec<tree_sitter::Range>>,
+    combined_injection_ranges: &mut HashMap<LanguageId, (Arc<Language>, Vec<tree_sitter::Range>)>,
     queue: &mut BinaryHeap<ParseStep>,
 ) {
     let mut query_cursor = QueryCursorHandle::new();
@@ -1223,7 +1223,7 @@ fn get_injections(
                 .now_or_never()
                 .and_then(|language| language.ok())
             {
-                combined_injection_ranges.insert(language, Vec::new());
+                combined_injection_ranges.insert(language.id, (language, Vec::new()));
             }
         }
     }
@@ -1276,8 +1276,9 @@ fn get_injections(
                 if let Some(language) = language {
                     if combined {
                         combined_injection_ranges
-                            .entry(language.clone())
-                            .or_default()
+                            .entry(language.id)
+                            .or_insert_with(|| (language.clone(), vec![]))
+                            .1
                             .extend(content_ranges);
                     } else {
                         queue.push(ParseStep {
@@ -1303,7 +1304,7 @@ fn get_injections(
         }
     }
 
-    for (language, mut included_ranges) in combined_injection_ranges.drain() {
+    for (_, (language, mut included_ranges)) in combined_injection_ranges.drain() {
         included_ranges.sort_unstable_by(|a, b| {
             Ord::cmp(&a.start_byte, &b.start_byte).then_with(|| Ord::cmp(&a.end_byte, &b.end_byte))
         });

crates/project/src/project.rs 🔗

@@ -4106,6 +4106,7 @@ impl Project {
             return;
         }
 
+        #[allow(clippy::mutable_key_type)]
         let language_server_lookup_info: HashSet<(Model<Worktree>, Arc<Language>)> = buffers
             .into_iter()
             .filter_map(|buffer| {
@@ -11066,6 +11067,7 @@ async fn populate_labels_for_symbols(
     lsp_adapter: Option<Arc<CachedLspAdapter>>,
     output: &mut Vec<Symbol>,
 ) {
+    #[allow(clippy::mutable_key_type)]
     let mut symbols_by_language = HashMap::<Option<Arc<Language>>, Vec<CoreSymbol>>::default();
 
     let mut unknown_path = None;

crates/project/src/task_inventory.rs 🔗

@@ -444,11 +444,6 @@ mod test_inventory {
 
     use super::{task_source_kind_preference, TaskSourceKind, UnboundedSender};
 
-    #[derive(Debug, Clone, PartialEq, Eq)]
-    pub struct TestTask {
-        name: String,
-    }
-
     pub(super) fn static_test_source(
         task_names: impl IntoIterator<Item = String>,
         updates: UnboundedSender<()>,