@@ -60,12 +60,18 @@ impl Location {
6060 // These types are redefined in the framework crate itself.
6161 "Darwin.MacTypes" => "__builtin__" . into ( ) ,
6262
63+ // int8_t, int16_t etc., translated to i8, i16 etc.
64+ "_stdint" => "__builtin__" . into ( ) ,
65+ // Implementation of the above
66+ "DarwinFoundation.types.machine_types" => "__builtin__" . into ( ) ,
67+
6368 // `core::ffi` types
64- "DarwinFoundation.types.machine_types" => "__core__.ffi" . into ( ) ,
6569 "_Builtin_stdarg.va_list" => {
66- error ! ( "va_list is not yet supported" ) ;
70+ warn ! ( "va_list is not yet supported" ) ;
6771 "__core__.ffi" . into ( )
6872 }
73+ // c_float and c_double
74+ "_float" | "_Builtin_float" => "__core__.ffi" . into ( ) ,
6975
7076 // `libc`
7177 name if name. starts_with ( "sys_types" ) => "__libc__" . into ( ) ,
@@ -169,26 +175,6 @@ impl Location {
169175 }
170176 }
171177
172- /// The place from where a given item exists.
173- pub fn import ( & self , config : & Config , emission_library : & str ) -> Option < Cow < ' static , str > > {
174- match self . library_name ( ) {
175- "__builtin__" => None ,
176- // TODO: Use `core::xyz` here.
177- "__core__" => None ,
178- // Rare enough that it's written directly instead of
179- // glob-imported, see `ItemIdentifier::path`.
180- "__bitflags__" | "__libc__" | "block" => None ,
181- "ObjectiveC" => Some ( "objc2::__framework_prelude" . into ( ) ) ,
182- // Not currently needed, but might be useful to emit
183- // `Some("crate")` here in the future.
184- library if library == emission_library => None ,
185- library => {
186- let krate = & config. library ( library) . krate ;
187- Some ( krate. replace ( '-' , "_" ) . into ( ) )
188- }
189- }
190- }
191-
192178 // Feature names are based on the file name, not the whole path to the feature.
193179 pub fn cargo_toml_feature ( & self , config : & Config , emission_library : & str ) -> Option < String > {
194180 match self . library_name ( ) {
@@ -240,7 +226,11 @@ impl Location {
240226
241227 // FIXME: This is currently wrong for nested umbrella frameworks
242228 // (specifically MetalPerformanceShaders).
243- fn cfg_feature < ' a > ( & self , config : & ' a Config , emission_library : & str ) -> Option < Cow < ' a , str > > {
229+ pub fn cfg_feature < ' a > (
230+ & self ,
231+ config : & ' a Config ,
232+ emission_library : & str ,
233+ ) -> Option < Cow < ' a , str > > {
244234 match self . library_name ( ) {
245235 "__builtin__" | "__core__" => None ,
246236 library if library == emission_library => {
@@ -317,10 +307,14 @@ impl<N: ToOptionString> ItemIdentifier<N> {
317307 . get_location ( )
318308 . unwrap_or_else ( || panic ! ( "no entity location: {entity:?}" ) )
319309 . get_expansion_location ( )
320- . file
321- . expect ( "expanded location file" ) ;
310+ . file ;
322311
323- let mut location = Location :: from_file ( file) ;
312+ let mut location = if let Some ( file) = file {
313+ Location :: from_file ( file)
314+ } else {
315+ // Assume item to be a built-in macro like __nonnull if no file.
316+ Location :: new ( "__builtin__" )
317+ } ;
324318
325319 // Defined in multiple places for some reason.
326320 if let Some ( "IOSurfaceRef" | "__IOSurface" ) = name. to_option ( ) {
@@ -399,14 +393,14 @@ impl ItemIdentifier {
399393 pub fn core_ffi ( name : & str ) -> Self {
400394 Self {
401395 name : name. into ( ) ,
402- location : Location :: new ( "ObjectiveC " ) , // Temporary
396+ location : Location :: new ( "__core__.ffi " ) ,
403397 }
404398 }
405399
406- pub fn core_ptr ( name : & str ) -> Self {
400+ pub fn core_ptr_nonnull ( ) -> Self {
407401 Self {
408- name : name . into ( ) ,
409- location : Location :: new ( "ObjectiveC " ) , // Temporary
402+ name : "NonNull" . into ( ) ,
403+ location : Location :: new ( "__core__.ptr " ) ,
410404 }
411405 }
412406
@@ -433,6 +427,32 @@ impl ItemIdentifier {
433427 self . location . library_name ( ) == "Foundation" && self . name == "NSComparator"
434428 }
435429
430+ /// The import needed for a given item to exist.
431+ pub fn import ( & self , config : & Config , emission_library : & str ) -> Option < Cow < ' static , str > > {
432+ match self . library_name ( ) {
433+ "__builtin__" => None ,
434+ "__core__" => match & * self . location ( ) . module_path {
435+ "__core__.ffi" => Some ( "core::ffi::*" . into ( ) ) ,
436+ "__core__.ptr" if self . name == "NonNull" => Some ( "core::ptr::NonNull" . into ( ) ) ,
437+ _ => {
438+ error ! ( "unknown __core__: {self:?}" ) ;
439+ None
440+ }
441+ } ,
442+ // Rare enough that it's written directly instead of
443+ // glob-imported, see `ItemIdentifier::path` below.
444+ "__bitflags__" | "__libc__" | "block" => None ,
445+ "ObjectiveC" => Some ( "objc2::__framework_prelude::*" . into ( ) ) ,
446+ // Not currently needed, but might be useful to emit
447+ // `Some("crate")` here in the future.
448+ library if library == emission_library => None ,
449+ library => {
450+ let krate = & config. library ( library) . krate ;
451+ Some ( format ! ( "{}::*" , krate. replace( '-' , "_" ) ) . into ( ) )
452+ }
453+ }
454+ }
455+
436456 pub fn path ( & self ) -> impl fmt:: Display + ' _ {
437457 struct ItemIdentifierPath < ' a > ( & ' a ItemIdentifier ) ;
438458
0 commit comments