Skip to content

Commit dfdcda1

Browse files
committed
Apply rustfmt style changes
1 parent cc69c51 commit dfdcda1

185 files changed

Lines changed: 25478 additions & 15902 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

crates/compiler/src/analysis.rs

Lines changed: 155 additions & 120 deletions
Large diffs are not rendered by default.

crates/compiler/src/associated_type_resolver.rs

Lines changed: 47 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,10 @@
3636
//! assert_eq!(item_type, Type::I32);
3737
//! ```
3838
39+
use crate::{CompilerError, CompilerResult};
3940
use std::collections::HashMap;
4041
use std::sync::Arc;
41-
use zyntax_typed_ast::{Type, TypeId, InternedString, ImplDef};
42-
use crate::{CompilerError, CompilerResult};
42+
use zyntax_typed_ast::{ImplDef, InternedString, Type, TypeId};
4343

4444
/// Resolves associated type projections to concrete types
4545
///
@@ -70,12 +70,7 @@ impl AssociatedTypeResolver {
7070
/// * `trait_id` - The trait being implemented
7171
/// * `for_type_id` - The type implementing the trait
7272
/// * `impl_def` - The implementation definition with associated type bindings
73-
pub fn register_impl(
74-
&mut self,
75-
trait_id: TypeId,
76-
for_type_id: TypeId,
77-
impl_def: Arc<ImplDef>,
78-
) {
73+
pub fn register_impl(&mut self, trait_id: TypeId, for_type_id: TypeId, impl_def: Arc<ImplDef>) {
7974
self.impl_registry.insert((trait_id, for_type_id), impl_def);
8075
}
8176

@@ -122,19 +117,20 @@ impl AssociatedTypeResolver {
122117
let for_type_id = self.extract_type_id(self_ty)?;
123118

124119
// Look up the implementation
125-
let impl_def = self.find_impl(trait_id, for_type_id)
126-
.ok_or_else(|| CompilerError::Analysis(format!(
120+
let impl_def = self.find_impl(trait_id, for_type_id).ok_or_else(|| {
121+
CompilerError::Analysis(format!(
127122
"No implementation of trait {:?} found for type {:?}",
128123
trait_id, self_ty
129-
)))?;
124+
))
125+
})?;
130126

131127
// Look up the associated type binding in the impl
132-
let concrete_type = impl_def.associated_types
133-
.get(&assoc_name)
134-
.ok_or_else(|| CompilerError::Analysis(format!(
128+
let concrete_type = impl_def.associated_types.get(&assoc_name).ok_or_else(|| {
129+
CompilerError::Analysis(format!(
135130
"Associated type '{}' not found in implementation of trait {:?} for type {:?}",
136131
assoc_name, trait_id, self_ty
137-
)))?;
132+
))
133+
})?;
138134

139135
Ok(concrete_type.clone())
140136
}
@@ -149,11 +145,7 @@ impl AssociatedTypeResolver {
149145
/// # Returns
150146
///
151147
/// The implementation definition if found, None otherwise.
152-
fn find_impl(
153-
&self,
154-
trait_id: TypeId,
155-
for_type_id: TypeId,
156-
) -> Option<&Arc<ImplDef>> {
148+
fn find_impl(&self, trait_id: TypeId, for_type_id: TypeId) -> Option<&Arc<ImplDef>> {
157149
self.impl_registry.get(&(trait_id, for_type_id))
158150
}
159151

@@ -180,12 +172,10 @@ impl AssociatedTypeResolver {
180172

181173
// Primitive types don't have type IDs - they would need special handling
182174
// In a full implementation, we might create synthetic TypeIds for primitives
183-
Type::Primitive(_) => {
184-
Err(CompilerError::Analysis(format!(
185-
"Primitive types cannot have trait implementations yet: {:?}",
186-
ty
187-
)))
188-
}
175+
Type::Primitive(_) => Err(CompilerError::Analysis(format!(
176+
"Primitive types cannot have trait implementations yet: {:?}",
177+
ty
178+
))),
189179

190180
// Type variables and other abstract types cannot be resolved yet
191181
_ => Err(CompilerError::Analysis(format!(
@@ -199,9 +189,9 @@ impl AssociatedTypeResolver {
199189
///
200190
/// Returns an iterator over (trait_id, for_type_id, impl_def) tuples.
201191
pub fn impls(&self) -> impl Iterator<Item = (TypeId, TypeId, &Arc<ImplDef>)> {
202-
self.impl_registry.iter().map(|((trait_id, for_type_id), impl_def)| {
203-
(*trait_id, *for_type_id, impl_def)
204-
})
192+
self.impl_registry
193+
.iter()
194+
.map(|((trait_id, for_type_id), impl_def)| (*trait_id, *for_type_id, impl_def))
205195
}
206196

207197
/// Clear all registered implementations
@@ -226,8 +216,8 @@ impl Default for AssociatedTypeResolver {
226216
#[cfg(test)]
227217
mod tests {
228218
use super::*;
229-
use zyntax_typed_ast::{TypeBound, AssociatedTypeDef, MethodImpl, PrimitiveType};
230219
use zyntax_typed_ast::arena::AstArena;
220+
use zyntax_typed_ast::{AssociatedTypeDef, MethodImpl, PrimitiveType, TypeBound};
231221

232222
fn create_test_impl(
233223
arena: &mut AstArena,
@@ -365,11 +355,15 @@ mod tests {
365355
variance: vec![],
366356
nullability: zyntax_typed_ast::NullabilityKind::NonNull,
367357
},
368-
arena.intern_string("Output"), // Wrong name
358+
arena.intern_string("Output"), // Wrong name
369359
);
370360

371361
// Should error because impl only has "Item", not "Output"
372-
assert!(result.is_err(), "Expected error for missing associated type, got: {:?}", result);
362+
assert!(
363+
result.is_err(),
364+
"Expected error for missing associated type, got: {:?}",
365+
result
366+
);
373367
}
374368

375369
#[test]
@@ -382,11 +376,23 @@ mod tests {
382376
let vec_string = TypeId::new(3);
383377

384378
// Register impl Iterator for Vec<i32>
385-
let impl1 = create_test_impl(&mut arena, iterator_trait, vec_i32, "Item", Type::Primitive(PrimitiveType::I32));
379+
let impl1 = create_test_impl(
380+
&mut arena,
381+
iterator_trait,
382+
vec_i32,
383+
"Item",
384+
Type::Primitive(PrimitiveType::I32),
385+
);
386386
resolver.register_impl(iterator_trait, vec_i32, Arc::new(impl1));
387387

388388
// Register impl Iterator for Vec<String>
389-
let impl2 = create_test_impl(&mut arena, iterator_trait, vec_string, "Item", Type::Primitive(PrimitiveType::String));
389+
let impl2 = create_test_impl(
390+
&mut arena,
391+
iterator_trait,
392+
vec_string,
393+
"Item",
394+
Type::Primitive(PrimitiveType::String),
395+
);
390396
resolver.register_impl(iterator_trait, vec_string, Arc::new(impl2));
391397

392398
// Resolve for Vec<i32>
@@ -426,7 +432,13 @@ mod tests {
426432
let iterator_trait = TypeId::new(1);
427433
let vec_type = TypeId::new(2);
428434

429-
let impl_def = create_test_impl(&mut arena, iterator_trait, vec_type, "Item", Type::Primitive(PrimitiveType::I32));
435+
let impl_def = create_test_impl(
436+
&mut arena,
437+
iterator_trait,
438+
vec_type,
439+
"Item",
440+
Type::Primitive(PrimitiveType::I32),
441+
);
430442
resolver.register_impl(iterator_trait, vec_type, Arc::new(impl_def));
431443

432444
assert_eq!(resolver.impl_count(), 1);

0 commit comments

Comments
 (0)