@@ -20,13 +20,16 @@ impl<'a> Index<'a> {
20
20
// While doing so, reject conflicting definitions.
21
21
let mut globals = FastHashMap :: with_capacity_and_hasher ( tu. decls . len ( ) , Default :: default ( ) ) ;
22
22
for ( handle, decl) in tu. decls . iter ( ) {
23
- let ident = decl_ident ( decl) ;
24
- let name = ident. name ;
25
- if let Some ( old) = globals. insert ( name, handle) {
26
- return Err ( Error :: Redefinition {
27
- previous : decl_ident ( & tu. decls [ old] ) . span ,
28
- current : ident. span ,
29
- } ) ;
23
+ if let Some ( ident) = decl_ident ( decl) {
24
+ let name = ident. name ;
25
+ if let Some ( old) = globals. insert ( name, handle) {
26
+ return Err ( Error :: Redefinition {
27
+ previous : decl_ident ( & tu. decls [ old] )
28
+ . expect ( "decl should have ident for redefinition" )
29
+ . span ,
30
+ current : ident. span ,
31
+ } ) ;
32
+ }
30
33
}
31
34
}
32
35
@@ -130,7 +133,7 @@ impl<'a> DependencySolver<'a, '_> {
130
133
return if dep_id == id {
131
134
// A declaration refers to itself directly.
132
135
Err ( Error :: RecursiveDeclaration {
133
- ident : decl_ident ( decl) . span ,
136
+ ident : decl_ident ( decl) . expect ( "decl should have ident" ) . span ,
134
137
usage : dep. usage ,
135
138
} )
136
139
} else {
@@ -146,14 +149,19 @@ impl<'a> DependencySolver<'a, '_> {
146
149
. unwrap_or ( 0 ) ;
147
150
148
151
Err ( Error :: CyclicDeclaration {
149
- ident : decl_ident ( & self . module . decls [ dep_id] ) . span ,
152
+ ident : decl_ident ( & self . module . decls [ dep_id] )
153
+ . expect ( "decl should have ident" )
154
+ . span ,
150
155
path : self . path [ start_at..]
151
156
. iter ( )
152
157
. map ( |curr_dep| {
153
158
let curr_id = curr_dep. decl ;
154
159
let curr_decl = & self . module . decls [ curr_id] ;
155
160
156
- ( decl_ident ( curr_decl) . span , curr_dep. usage )
161
+ (
162
+ decl_ident ( curr_decl) . expect ( "decl should have ident" ) . span ,
163
+ curr_dep. usage ,
164
+ )
157
165
} )
158
166
. collect ( ) ,
159
167
} )
@@ -182,13 +190,14 @@ impl<'a> DependencySolver<'a, '_> {
182
190
}
183
191
}
184
192
185
- const fn decl_ident < ' a > ( decl : & ast:: GlobalDecl < ' a > ) -> ast:: Ident < ' a > {
193
+ const fn decl_ident < ' a > ( decl : & ast:: GlobalDecl < ' a > ) -> Option < ast:: Ident < ' a > > {
186
194
match decl. kind {
187
- ast:: GlobalDeclKind :: Fn ( ref f) => f. name ,
188
- ast:: GlobalDeclKind :: Var ( ref v) => v. name ,
189
- ast:: GlobalDeclKind :: Const ( ref c) => c. name ,
190
- ast:: GlobalDeclKind :: Override ( ref o) => o. name ,
191
- ast:: GlobalDeclKind :: Struct ( ref s) => s. name ,
192
- ast:: GlobalDeclKind :: Type ( ref t) => t. name ,
195
+ ast:: GlobalDeclKind :: Fn ( ref f) => Some ( f. name ) ,
196
+ ast:: GlobalDeclKind :: Var ( ref v) => Some ( v. name ) ,
197
+ ast:: GlobalDeclKind :: Const ( ref c) => Some ( c. name ) ,
198
+ ast:: GlobalDeclKind :: Override ( ref o) => Some ( o. name ) ,
199
+ ast:: GlobalDeclKind :: Struct ( ref s) => Some ( s. name ) ,
200
+ ast:: GlobalDeclKind :: Type ( ref t) => Some ( t. name ) ,
201
+ ast:: GlobalDeclKind :: ConstAssert ( _) => None ,
193
202
}
194
203
}
0 commit comments