From b50d38c29469601c0546efac01af1b4b393fffd8 Mon Sep 17 00:00:00 2001 From: Dhruv Manilawala Date: Wed, 30 Oct 2024 17:00:57 +0530 Subject: [PATCH] Extend diagnostics only in the builder --- crates/red_knot_python_semantic/src/types/diagnostic.rs | 4 ++++ crates/red_knot_python_semantic/src/types/infer.rs | 4 ++-- crates/ruff_benchmark/benches/red_knot.rs | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/crates/red_knot_python_semantic/src/types/diagnostic.rs b/crates/red_knot_python_semantic/src/types/diagnostic.rs index 884c5aa0854aa..9d64f0b7e9c63 100644 --- a/crates/red_knot_python_semantic/src/types/diagnostic.rs +++ b/crates/red_knot_python_semantic/src/types/diagnostic.rs @@ -255,6 +255,10 @@ impl<'db> TypeCheckDiagnosticsBuilder<'db> { }); } + pub(super) fn extend(&mut self, diagnostics: &TypeCheckDiagnostics) { + self.diagnostics.extend(diagnostics); + } + pub(super) fn finish(mut self) -> TypeCheckDiagnostics { self.diagnostics.shrink_to_fit(); self.diagnostics diff --git a/crates/red_knot_python_semantic/src/types/infer.rs b/crates/red_knot_python_semantic/src/types/infer.rs index 913bf38188e1d..039f923efad32 100644 --- a/crates/red_knot_python_semantic/src/types/infer.rs +++ b/crates/red_knot_python_semantic/src/types/infer.rs @@ -337,7 +337,7 @@ impl<'db> TypeInferenceBuilder<'db> { .declarations .extend(inference.declarations.iter()); self.types.expressions.extend(inference.expressions.iter()); - self.types.diagnostics.extend(&inference.diagnostics); + self.diagnostics.extend(&inference.diagnostics); self.types.has_deferred |= inference.has_deferred; } @@ -3472,7 +3472,7 @@ impl<'db> TypeInferenceBuilder<'db> { pub(super) fn finish(mut self) -> TypeInference<'db> { self.infer_region(); - self.types.diagnostics.extend(self.diagnostics.finish()); + self.types.diagnostics = self.diagnostics.finish(); self.types.shrink_to_fit(); self.types } diff --git a/crates/ruff_benchmark/benches/red_knot.rs b/crates/ruff_benchmark/benches/red_knot.rs index 0cf2a82a4c014..6e52ccc409965 100644 --- a/crates/ruff_benchmark/benches/red_knot.rs +++ b/crates/ruff_benchmark/benches/red_knot.rs @@ -27,10 +27,10 @@ static EXPECTED_DIAGNOSTICS: &[&str] = &[ "/src/tomllib/_parser.py:7:29: Module `collections.abc` has no member `Iterable`", // We don't support terminal statements in control flow yet: "/src/tomllib/_parser.py:66:18: Name `s` used when possibly not defined", - "/src/tomllib/_parser.py:108:17: Conflicting declared types for `second_char`: Unknown, str | None", "/src/tomllib/_parser.py:98:12: Name `char` used when possibly not defined", "/src/tomllib/_parser.py:101:12: Name `char` used when possibly not defined", "/src/tomllib/_parser.py:104:14: Name `char` used when possibly not defined", + "/src/tomllib/_parser.py:108:17: Conflicting declared types for `second_char`: Unknown, str | None", "/src/tomllib/_parser.py:115:14: Name `char` used when possibly not defined", "/src/tomllib/_parser.py:126:12: Name `char` used when possibly not defined", "/src/tomllib/_parser.py:267:9: Conflicting declared types for `char`: Unknown, str | None",