@@ -24,14 +24,24 @@ pub(crate) fn codegen_for_loop(
24
24
variable_tracker. codegen_declare ( id. to_string ( ) , loop_level as u8 + 1 ) ;
25
25
}
26
26
27
+ let invalid_for_loop = || {
28
+ syn:: Error :: new_spanned (
29
+ & for_loop. expr ,
30
+ "Invalid for loop: use [range](cubecl::prelude::range] instead." ,
31
+ )
32
+ . into_compile_error ( )
33
+ } ;
34
+
27
35
match for_loop. expr . as_ref ( ) {
28
36
syn:: Expr :: Call ( call) => {
29
37
let func_name = match call. func . as_ref ( ) {
30
- syn:: Expr :: Path ( path) => path
31
- . path
32
- . get_ident ( )
33
- . expect ( "Codegen: func in for loop should have ident" ) ,
34
- _ => todo ! ( "Codegen: Only path call supported" ) ,
38
+ syn:: Expr :: Path ( path) => match path. path . get_ident ( ) {
39
+ Some ( ident) => ident,
40
+ None => return invalid_for_loop ( ) ,
41
+ } ,
42
+ _ => {
43
+ return invalid_for_loop ( ) ;
44
+ }
35
45
} ;
36
46
37
47
if & func_name. to_string ( ) == "range" {
@@ -64,10 +74,10 @@ pub(crate) fn codegen_for_loop(
64
74
}
65
75
}
66
76
} else {
67
- todo ! ( "Codegen: Only range is supported" )
77
+ invalid_for_loop ( )
68
78
}
69
79
}
70
- _ => todo ! ( "Codegen: Only call is supported {for_loop:?}" ) ,
80
+ _ => invalid_for_loop ( ) ,
71
81
}
72
82
}
73
83
@@ -96,8 +106,10 @@ pub(crate) fn codegen_break() -> TokenStream {
96
106
/// Codegen for return statement
97
107
pub ( crate ) fn codegen_return ( expr_return : & syn:: ExprReturn ) -> TokenStream {
98
108
if expr_return. expr . is_some ( ) {
99
- panic ! ( "Codegen: Only void return is supported." )
109
+ return syn:: Error :: new_spanned ( expr_return, "Codegen: Only void return is supported." )
110
+ . into_compile_error ( ) ;
100
111
}
112
+
101
113
quote:: quote! {
102
114
burn_cube:: frontend:: branch:: return_expand( context) ;
103
115
}
@@ -131,7 +143,11 @@ pub(crate) fn codegen_if(
131
143
burn_cube:: frontend:: branch:: if_else_expand( context, #comptime_bool, _cond. into( ) , |context| #then_block, |context| #else_block) ;
132
144
}
133
145
} else {
134
- todo ! ( "Codegen: Only block else expr is supported" )
146
+ syn:: Error :: new_spanned (
147
+ expr,
148
+ "Unsupported: only `else` block is allowed after an `if` statement." ,
149
+ )
150
+ . into_compile_error ( )
135
151
}
136
152
} else {
137
153
quote:: quote! {
0 commit comments