|
| 1 | +use std::fmt::Write; |
| 2 | + |
1 | 3 | use cairo_lang_debug::DebugWithDb; |
2 | 4 | use cairo_lang_defs::diagnostic_utils::StableLocation; |
3 | 5 | use cairo_lang_defs::ids::{ |
@@ -27,10 +29,12 @@ use crate::diagnostic::{NotFoundItemType, SemanticDiagnostics, SemanticDiagnosti |
27 | 29 | use crate::expr::compute::{ |
28 | 30 | ComputationContext, ContextFunction, Environment, compute_expr_semantic, |
29 | 31 | }; |
| 32 | +use crate::expr::fmt::CountingWriter; |
30 | 33 | use crate::expr::inference::canonic::ResultNoErrEx; |
31 | 34 | use crate::expr::inference::{InferenceData, InferenceError, InferenceId, TypeVar}; |
32 | 35 | use crate::items::attribute::SemanticQueryAttrs; |
33 | 36 | use crate::items::constant::{ConstValue, ConstValueId, resolve_const_expr_and_evaluate}; |
| 37 | +use crate::items::generics::fmt_generic_args; |
34 | 38 | use crate::items::imp::{ImplId, ImplLookupContext}; |
35 | 39 | use crate::resolve::{ResolutionContext, ResolvedConcreteItem, Resolver}; |
36 | 40 | use crate::substitution::SemanticRewriter; |
@@ -305,28 +309,7 @@ impl ConcreteTypeId { |
305 | 309 | } |
306 | 310 | } |
307 | 311 | pub fn format(&self, db: &dyn SemanticGroup) -> String { |
308 | | - let generic_type_format = self.generic_type(db).format(db); |
309 | | - let mut generic_args = self.generic_args(db).into_iter(); |
310 | | - if let Some(first) = generic_args.next() { |
311 | | - // Soft limit for the number of chars in the formatted type. |
312 | | - const CHARS_BOUND: usize = 500; |
313 | | - let mut f = generic_type_format; |
314 | | - f.push_str("::<"); |
315 | | - f.push_str(&first.format(db)); |
316 | | - for arg in generic_args { |
317 | | - f.push_str(", "); |
318 | | - if f.len() > CHARS_BOUND { |
319 | | - // If the formatted type is becoming too long, add short version of arguments. |
320 | | - f.push_str(&arg.short_name(db)); |
321 | | - } else { |
322 | | - f.push_str(&arg.format(db)); |
323 | | - } |
324 | | - } |
325 | | - f.push('>'); |
326 | | - f |
327 | | - } else { |
328 | | - generic_type_format |
329 | | - } |
| 312 | + format!("{:?}", self.debug(db.elongate())) |
330 | 313 | } |
331 | 314 |
|
332 | 315 | /// Returns whether the type has the `#[must_use]` attribute. |
@@ -354,7 +337,9 @@ impl DebugWithDb<dyn SemanticGroup> for ConcreteTypeId { |
354 | 337 | f: &mut std::fmt::Formatter<'_>, |
355 | 338 | db: &(dyn SemanticGroup + 'static), |
356 | 339 | ) -> std::fmt::Result { |
357 | | - write!(f, "{}", self.format(db)) |
| 340 | + let f = &mut CountingWriter::new(f); |
| 341 | + write!(f, "{}", self.generic_type(db).format(db))?; |
| 342 | + fmt_generic_args(&self.generic_args(db), f, db) |
358 | 343 | } |
359 | 344 | } |
360 | 345 |
|
|
0 commit comments