From a95337389295b18855d9185f28344f62ffd01fb9 Mon Sep 17 00:00:00 2001 From: Andrew Gallant Date: Fri, 21 Mar 2025 09:40:47 -0400 Subject: [PATCH] red_knot_python_semantic: remove `Deref` impl on `TypeCheckDiagnostics` I removed this to see how much code was depending internally on the `&[Arc]` representation. Thankfully, it was just one place. So I just removed the `Deref` impl in favor of adding an explicit `iter` method. In general, I think using `Deref` for things like this is _somewhat_ of an abuse. The tip-off is if there are `&self` or `&mut self` methods on the type, then it's probably not a good candidate for `Deref`. --- .../src/types/diagnostic.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/crates/red_knot_python_semantic/src/types/diagnostic.rs b/crates/red_knot_python_semantic/src/types/diagnostic.rs index 1877bf7de4..067f3d4f76 100644 --- a/crates/red_knot_python_semantic/src/types/diagnostic.rs +++ b/crates/red_knot_python_semantic/src/types/diagnostic.rs @@ -17,7 +17,6 @@ use ruff_text_size::{Ranged, TextRange}; use rustc_hash::FxHashSet; use std::borrow::Cow; use std::fmt::Formatter; -use std::ops::Deref; use std::sync::Arc; /// Registers all known type check lints. @@ -985,6 +984,10 @@ impl TypeCheckDiagnostics { self.used_suppressions.shrink_to_fit(); self.diagnostics.shrink_to_fit(); } + + pub fn iter(&self) -> std::slice::Iter<'_, Arc> { + self.diagnostics.iter() + } } impl std::fmt::Debug for TypeCheckDiagnostics { @@ -993,14 +996,6 @@ impl std::fmt::Debug for TypeCheckDiagnostics { } } -impl Deref for TypeCheckDiagnostics { - type Target = [std::sync::Arc]; - - fn deref(&self) -> &Self::Target { - &self.diagnostics - } -} - impl IntoIterator for TypeCheckDiagnostics { type Item = Arc; type IntoIter = std::vec::IntoIter>;