pub fn next_def_id(&self, crate_num: CrateNum) -> DefId {
        let start_def_id = {
            let next_id = if crate_num == LOCAL_CRATE {
                self.tcx
                    .hir
                    .definitions()
                    .def_path_table()
                    .next_id(DefIndexAddressSpace::Low)
            } else {
                self.cstore
                    .def_path_table(crate_num)
                    .next_id(DefIndexAddressSpace::Low)
            };

            DefId {
                krate: crate_num,
                index: next_id,
            }
        };

        let mut fake_ids = self.fake_def_ids.borrow_mut();

        let def_id = fake_ids.entry(crate_num).or_insert(start_def_id).clone();
        fake_ids.insert(
            crate_num,
            DefId {
                krate: crate_num,
                index: DefIndex::from_array_index(
                    def_id.index.as_array_index() + 1,
                    def_id.index.address_space(),
                ),
            },
        );

        MAX_DEF_ID.with(|m| {
            m.borrow_mut()
                .entry(def_id.krate.clone())
                .or_insert(start_def_id);
        });

        self.all_fake_def_ids.borrow_mut().insert(def_id);

        def_id.clone()
    }
// This is an ugly hack, but it's the simplest way to handle synthetic impls without greatly
// refactoring either librustdoc or librustc. In particular, allowing new DefIds to be
// registered after the AST is constructed would require storing the defid mapping in a
// RefCell, decreasing the performance for normal compilation for very little gain.
//
// Instead, we construct 'fake' def ids, which start immediately after the last DefId in
// DefIndexAddressSpace::Low. In the Debug impl for clean::Item, we explicitly check for fake
// def ids, as we'll end up with a panic if we use the DefId Debug impl for fake DefIds
This is an ugly hack, but it's the simplest way to handle synthetic impls without greatly
refactoring either librustdoc or librustc. In particular, allowing new DefIds to be
registered after the AST is constructed would require storing the defid mapping in a
RefCell, decreasing the performance for normal compilation for very little gain.

Instead, we construct 'fake' def ids, which start immediately after the last DefId in
DefIndexAddressSpace::Low. In the Debug impl for clean::Item, we explicitly check for fake
def ids, as we'll end up with a panic if we use the DefId Debug impl for fake DefIds
This is an ugly hack but it ' s the simplest way to handle synthetic impls without greatly refactoring either librustdoc or librustc . In particular allowing new DefIds to be registered after the AST is constructed would require storing the defid mapping in a RefCell decreasing the performance for normal compilation for very little gain . Instead we construct ' fake ' def ids which start immediately after the last DefId in DefIndexAddressSpace :: Low . In the Debug impl for clean :: Item we explicitly check for fake def ids as we ' ll end up with a panic if we use the DefId Debug impl for fake DefIds
pub fn next_def_id(&self, crate_num: CrateNum) -> DefId {
        let start_def_id = {
            let next_id = if crate_num == LOCAL_CRATE {
                self.tcx
                    .hir
                    .definitions()
                    .def_path_table()
                    .next_id(DefIndexAddressSpace::Low)
            } else {
                self.cstore
                    .def_path_table(crate_num)
                    .next_id(DefIndexAddressSpace::Low)
            };
            DefId {
                krate: crate_num,
                index: next_id,
            }
        };
        let mut fake_ids = self.fake_def_ids.borrow_mut();
        let def_id = fake_ids.entry(crate_num).or_insert(start_def_id).clone();
        fake_ids.insert(
            crate_num,
            DefId {
                krate: crate_num,
                index: DefIndex::from_array_index(
                    def_id.index.as_array_index() + 1,
                    def_id.index.address_space(),
                ),
            },
        );
        MAX_DEF_ID.with(|m| {
            m.borrow_mut()
                .entry(def_id.krate.clone())
                .or_insert(start_def_id);
        });
        self.all_fake_def_ids.borrow_mut().insert(def_id);
        def_id.clone()
    }
pub fn next_def_id ( & self , crate_num : CrateNum ) -> DefId { let start_def_id = { let next_id = if crate_num == LOCAL_CRATE { self . tcx . hir . definitions ( ) . def_path_table ( ) . next_id ( DefIndexAddressSpace :: Low ) } else { self . cstore . def_path_table ( crate_num ) . next_id ( DefIndexAddressSpace :: Low ) } ; DefId { krate : crate_num , index : next_id , } } ; let mut fake_ids = self . fake_def_ids . borrow_mut ( ) ; let def_id = fake_ids . entry ( crate_num ) . or_insert ( start_def_id ) . clone ( ) ; fake_ids . insert ( crate_num , DefId { krate : crate_num , index : DefIndex :: from_array_index ( def_id . index . as_array_index ( ) + 1 , def_id . index . address_space ( ) , ) , } , ) ; MAX_DEF_ID . with ( | m | { m . borrow_mut ( ) . entry ( def_id . krate . clone ( ) ) . or_insert ( start_def_id ) ; } ) ; self . all_fake_def_ids . borrow_mut ( ) . insert ( def_id ) ; def_id . clone ( ) }
This is an ugly hack, but it's the simplest way to handle synthetic impls without greatly
refactoring either librustdoc or librustc.
This is an ugly hack but it ' s the simplest way to handle synthetic impls without greatly refactoring either librustdoc or librustc .
&self
crate_num
CrateNum
&self
crate_num
CrateNum