Skip to content

Commit 7fa0b00

Browse files
committed
style: cargo fmt
1 parent a1a601f commit 7fa0b00

3 files changed

Lines changed: 58 additions & 55 deletions

File tree

crates/compiler/src/lowering.rs

Lines changed: 47 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,7 @@ impl Default for LoweringConfig {
355355
}
356356

357357
/// Re-export the proper diagnostic types from typed_ast
358-
pub use zyntax_typed_ast::diagnostics::{
359-
Diagnostic as LoweringDiagnostic, DiagnosticLevel,
360-
};
358+
pub use zyntax_typed_ast::diagnostics::{Diagnostic as LoweringDiagnostic, DiagnosticLevel};
361359

362360
/// Main AST lowering interface
363361
pub trait AstLowering {
@@ -441,7 +439,9 @@ impl LoweringContext {
441439
type_registry,
442440
arena,
443441
symbols,
444-
diagnostics: std::cell::RefCell::new(zyntax_typed_ast::diagnostics::DiagnosticCollector::new()),
442+
diagnostics: std::cell::RefCell::new(
443+
zyntax_typed_ast::diagnostics::DiagnosticCollector::new(),
444+
),
445445
config,
446446
vtable_registry: crate::vtable_registry::VtableRegistry::new(),
447447
associated_type_resolver: crate::associated_type_resolver::AssociatedTypeResolver::new(
@@ -1617,9 +1617,7 @@ impl LoweringContext {
16171617
// infer Dynamic — the return type will be evaluated at runtime.
16181618
let effective_return_type = if matches!(
16191619
func.return_type,
1620-
zyntax_typed_ast::Type::Primitive(
1621-
zyntax_typed_ast::PrimitiveType::Unit
1622-
)
1620+
zyntax_typed_ast::Type::Primitive(zyntax_typed_ast::PrimitiveType::Unit)
16231621
) {
16241622
let has_return_with_value = func.body.as_ref().map_or(false, |body| {
16251623
body.statements.iter().any(|stmt| {
@@ -2071,20 +2069,23 @@ impl LoweringContext {
20712069
// Warn about untyped parameters — they will be treated as Dynamic.
20722070
// Skip warnings for: main(), internal runtime functions ($-prefixed),
20732071
// and stdlib IO functions that intentionally accept DynamicBox.
2074-
if matches!(
2075-
param.ty,
2076-
Type::Any | Type::Unknown | Type::Dynamic
2077-
) {
2072+
if matches!(param.ty, Type::Any | Type::Unknown | Type::Dynamic) {
20782073
let param_name = param.name.resolve_global().unwrap_or_default();
20792074
let is_internal = func_name == "main"
20802075
|| func_name.starts_with('$')
20812076
|| func_name.starts_with("__")
20822077
|| matches!(
20832078
func_name.as_str(),
2084-
"println" | "print" | "eprintln" | "eprint"
2085-
| "println_dynamic" | "print_dynamic"
2086-
| "eprintln_dynamic" | "eprint_dynamic"
2087-
| "format_dynamic" | "to_string"
2079+
"println"
2080+
| "print"
2081+
| "eprintln"
2082+
| "eprint"
2083+
| "println_dynamic"
2084+
| "print_dynamic"
2085+
| "eprintln_dynamic"
2086+
| "eprint_dynamic"
2087+
| "format_dynamic"
2088+
| "to_string"
20882089
);
20892090
if !is_internal {
20902091
self.emit_diagnostic(
@@ -2135,11 +2136,10 @@ impl LoweringContext {
21352136
))
21362137
.with_code(zyntax_typed_ast::diagnostics::codes::W0002)
21372138
.with_help(format!(
2138-
"consider adding a return type annotation to `{}`", func_name
2139+
"consider adding a return type annotation to `{}`",
2140+
func_name
21392141
))
2140-
.with_note(
2141-
"the return type will be inferred dynamically at runtime"
2142-
),
2142+
.with_note("the return type will be inferred dynamically at runtime"),
21432143
);
21442144
// Dynamic maps to I64 at the machine level
21452145
vec![HirType::I64]
@@ -2439,12 +2439,13 @@ impl LoweringContext {
24392439
let type_name = name.resolve_global().unwrap_or_default();
24402440
// Suppress warnings for generic type params (T, U, E, etc.)
24412441
// These are known false positives from stdlib generic types
2442-
let is_generic_param = type_name.len() <= 2
2443-
&& type_name.chars().all(|c| c.is_ascii_uppercase());
2442+
let is_generic_param =
2443+
type_name.len() <= 2 && type_name.chars().all(|c| c.is_ascii_uppercase());
24442444
if !is_generic_param {
24452445
self.emit_diagnostic(
24462446
LoweringDiagnostic::warning(format!(
2447-
"could not resolve type `{}`", type_name
2447+
"could not resolve type `{}`",
2448+
type_name
24482449
))
24492450
.with_note("this type will be treated as a dynamically typed value"),
24502451
);
@@ -2581,7 +2582,8 @@ impl LoweringContext {
25812582
LoweringDiagnostic::error(format!(
25822583
"Global variable '{}' has non-constant initializer: {}",
25832584
var.name, e
2584-
)).with_primary(init_expr.span, "non-constant expression"),
2585+
))
2586+
.with_primary(init_expr.span, "non-constant expression"),
25852587
);
25862588
None
25872589
}
@@ -2642,8 +2644,10 @@ impl LoweringContext {
26422644
_ => {
26432645
self.emit_diagnostic(
26442646
LoweringDiagnostic::error(format!(
2645-
"Invalid discriminant for enum variant '{}'", variant.name
2646-
)).with_primary(variant.span, "invalid discriminant value"),
2647+
"Invalid discriminant for enum variant '{}'",
2648+
variant.name
2649+
))
2650+
.with_primary(variant.span, "invalid discriminant value"),
26472651
);
26482652
variant_idx as u64
26492653
}
@@ -2716,8 +2720,10 @@ impl LoweringContext {
27162720
// Type not found in registry - this shouldn't happen for well-typed programs
27172721
self.emit_diagnostic(
27182722
LoweringDiagnostic::warning(format!(
2719-
"Enum type '{}' not found in type registry", enum_decl.name
2720-
)).with_primary(enum_decl.span, "unknown enum type"),
2723+
"Enum type '{}' not found in type registry",
2724+
enum_decl.name
2725+
))
2726+
.with_primary(enum_decl.span, "unknown enum type"),
27212727
);
27222728
}
27232729

@@ -3844,9 +3850,8 @@ impl LoweringContext {
38443850
Err(e) => {
38453851
// Log the error but don't fail - imports might be resolved externally
38463852
self.emit_diagnostic(
3847-
LoweringDiagnostic::warning(format!(
3848-
"Import resolution warning: {}", e
3849-
)).with_primary(import.span, "failed to resolve import"),
3853+
LoweringDiagnostic::warning(format!("Import resolution warning: {}", e))
3854+
.with_primary(import.span, "failed to resolve import"),
38503855
);
38513856
Vec::new()
38523857
}
@@ -5029,11 +5034,10 @@ impl LoweringPipeline {
50295034
let pass_name = pass.name();
50305035

50315036
if context.config.debug_info {
5032-
context.emit_diagnostic(
5033-
LoweringDiagnostic::new(DiagnosticLevel::Note, format!(
5034-
"Running lowering pass: {}", pass_name
5035-
)),
5036-
);
5037+
context.emit_diagnostic(LoweringDiagnostic::new(
5038+
DiagnosticLevel::Note,
5039+
format!("Running lowering pass: {}", pass_name),
5040+
));
50375041
}
50385042

50395043
pass.run(context)?;
@@ -5206,24 +5210,20 @@ pub mod passes {
52065210
// Validate parameter types
52075211
for param in &func.signature.params {
52085212
if !Self::is_valid_hir_type(&param.ty) {
5209-
context.emit_diagnostic(
5210-
LoweringDiagnostic::error(format!(
5211-
"Invalid parameter type in function {}: {:?}",
5212-
func.name, param.ty
5213-
)),
5214-
);
5213+
context.emit_diagnostic(LoweringDiagnostic::error(format!(
5214+
"Invalid parameter type in function {}: {:?}",
5215+
func.name, param.ty
5216+
)));
52155217
}
52165218
}
52175219

52185220
// Validate return types
52195221
for ret_ty in &func.signature.returns {
52205222
if !Self::is_valid_hir_type(ret_ty) {
5221-
context.emit_diagnostic(
5222-
LoweringDiagnostic::error(format!(
5223-
"Invalid return type in function {}: {:?}",
5224-
func.name, ret_ty
5225-
)),
5226-
);
5223+
context.emit_diagnostic(LoweringDiagnostic::error(format!(
5224+
"Invalid return type in function {}: {:?}",
5225+
func.name, ret_ty
5226+
)));
52275227
}
52285228
}
52295229

crates/compiler/src/ssa.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2721,9 +2721,7 @@ impl SsaBuilder {
27212721
);
27222722
let call_inst = HirInstruction::Call {
27232723
result: Some(result),
2724-
callee: crate::hir::HirCallable::Symbol(
2725-
"$IO$string_concat".to_string(),
2726-
),
2724+
callee: crate::hir::HirCallable::Symbol("$IO$string_concat".to_string()),
27272725
args: vec![left_val, right_val],
27282726
type_args: vec![],
27292727
const_args: vec![],
@@ -3039,10 +3037,13 @@ impl SsaBuilder {
30393037
// when the parser hasn't propagated it (expr.ty is Unit/Unknown/Any)
30403038
let result_type = {
30413039
let raw = self.convert_type(&expr.ty);
3042-
if matches!(raw, HirType::Void) || matches!(&expr.ty, Type::Unknown | Type::Any) {
3040+
if matches!(raw, HirType::Void) || matches!(&expr.ty, Type::Unknown | Type::Any)
3041+
{
30433042
// Try to resolve from function_return_types
30443043
let from_table = callee_func_key.and_then(|fk| {
3045-
self.function_return_types.get(&fk).map(|rt| self.convert_type(rt))
3044+
self.function_return_types
3045+
.get(&fk)
3046+
.map(|rt| self.convert_type(rt))
30463047
});
30473048
if let Some(resolved) = from_table {
30483049
if resolved != HirType::Void {

crates/compiler/src/typed_cfg.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -756,14 +756,16 @@ impl TypedCfgBuilder {
756756
TypedExpression::Call(call) => {
757757
let is_range = match &call.callee.node {
758758
TypedExpression::Variable(name) => {
759-
let mut arena =
760-
zyntax_typed_ast::arena::AstArena::new();
759+
let mut arena = zyntax_typed_ast::arena::AstArena::new();
761760
let range_sym = arena.intern_string("range");
762761
*name == range_sym
763762
}
764763
_ => false,
765764
};
766-
if is_range && (call.positional_args.len() == 2 || call.positional_args.len() == 3) {
765+
if is_range
766+
&& (call.positional_args.len() == 2
767+
|| call.positional_args.len() == 3)
768+
{
767769
Some(call.positional_args.clone())
768770
} else {
769771
None

0 commit comments

Comments
 (0)