/// Tries to resolve the target of a `crate use` statement and inlines the
/// target if it is defined locally and would not be documented otherwise,
/// or when it is specifically requested with `please_inline`.
/// (the latter is the case when the import is marked `doc(inline)`)
///
/// Cross-crate inlining occurs later on during crate cleaning
/// and follows different rules.
///
/// Returns `true` if the target has been inlined.
Tries to resolve the target of a `crate use` statement and inlines the
target if it is defined locally and would not be documented otherwise,
or when it is specifically requested with `please_inline`.
(the latter is the case when the import is marked `doc(inline)`)

Cross-crate inlining occurs later on during crate cleaning
and follows different rules.

Returns `true` if the target has been inlined.
Tries to resolve the target of a ` crate use ` statement and inlines the target if it is defined locally and would not be documented otherwise or when it is specifically requested with ` please_inline ` . ( the latter is the case when the import is marked ` doc ( inline ) ` ) Cross - crate inlining occurs later on during crate cleaning and follows different rules . Returns ` true ` if the target has been inlined .
fn maybe_inline_local(
        &mut self,
        id: hir::HirId,
        res: Res,
        renamed: Option<Ident>,
        glob: bool,
        om: &mut Module<'tcx>,
        please_inline: bool,
    ) -> bool {
        fn inherits_doc_hidden(cx: &core::DocContext<'_>, mut node: hir::HirId) -> bool {
            while let Some(id) = cx.tcx.hir().get_enclosing_scope(node) {
                node = id;
                if cx.tcx.hir().attrs(node).lists(sym::doc).has_word(sym::hidden) {
                    return true;
                }
                if node == hir::CRATE_HIR_ID {
                    break;
                }
            }
            false
        }
        debug!("maybe_inline_local res: {:?}", res);
        let tcx = self.cx.tcx;
        let res_did = if let Some(did) = res.opt_def_id() {
            did
        } else {
            return false;
        };
        let use_attrs = tcx.hir().attrs(id);
        // Don't inline `doc(hidden)` imports so they can be stripped at a later stage.
        let is_no_inline = use_attrs.lists(sym::doc).has_word(sym::no_inline)
            || use_attrs.lists(sym::doc).has_word(sym::hidden);
        // For cross-crate impl inlining we need to know whether items are
        // reachable in documentation -- a previously nonreachable item can be
        // made reachable by cross-crate inlining which we're checking here.
        // (this is done here because we need to know this upfront).
        if !res_did.is_local() && !is_no_inline {
            let attrs = clean::inline::load_attrs(self.cx, res_did);
            let self_is_hidden = attrs.lists(sym::doc).has_word(sym::hidden);
            if !self_is_hidden {
                if let Res::Def(kind, did) = res {
                    if kind == DefKind::Mod {
                        crate::visit_lib::LibEmbargoVisitor::new(self.cx).visit_mod(did)
                    } else {
                        // All items need to be handled here in case someone wishes to link
                        // to them with intra-doc links
                        self.cx
                            .renderinfo
                            .get_mut()
                            .access_levels
                            .map
                            .insert(did, AccessLevel::Public);
                    }
                }
            }
            return false;
        }
        let res_hir_id = match res_did.as_local() {
            Some(n) => tcx.hir().local_def_id_to_hir_id(n),
            None => return false,
        };
        let is_private = !self.cx.renderinfo.borrow().access_levels.is_public(res_did);
        let is_hidden = inherits_doc_hidden(self.cx, res_hir_id);
        // Only inline if requested or if the item would otherwise be stripped.
        if (!please_inline && !is_private && !is_hidden) || is_no_inline {
            return false;
        }
        if !self.view_item_stack.insert(res_hir_id) {
            return false;
        }
        let ret = match tcx.hir().get(res_hir_id) {
            Node::Item(&hir::Item { kind: hir::ItemKind::Mod(ref m), .. }) if glob => {
                let prev = mem::replace(&mut self.inlining, true);
                for i in m.item_ids {
                    let i = self.cx.tcx.hir().expect_item(i.id);
                    self.visit_item(i, None, om);
                }
                self.inlining = prev;
                true
            }
            Node::Item(it) if !glob => {
                let prev = mem::replace(&mut self.inlining, true);
                self.visit_item(it, renamed, om);
                self.inlining = prev;
                true
            }
            Node::ForeignItem(it) if !glob => {
                let prev = mem::replace(&mut self.inlining, true);
                self.visit_foreign_item(it, renamed, om);
                self.inlining = prev;
                true
            }
            Node::MacroDef(def) if !glob => {
                om.macros.push(self.visit_local_macro(def, renamed.map(|i| i.name)));
                true
            }
            _ => false,
        };
        self.view_item_stack.remove(&res_hir_id);
        ret
    }
fn maybe_inline_local ( & mut self , id : hir :: HirId , res : Res , renamed : Option < Ident > , glob : bool , om : & mut Module < ' tcx > , please_inline : bool , ) -> bool { fn inherits_doc_hidden ( cx : & core :: DocContext < ' _ > , mut node : hir :: HirId ) -> bool { while let Some ( id ) = cx . tcx . hir ( ) . get_enclosing_scope ( node ) { node = id ; if cx . tcx . hir ( ) . attrs ( node ) . lists ( sym :: doc ) . has_word ( sym :: hidden ) { return true ; } if node == hir :: CRATE_HIR_ID { break ; } } false } debug ! ( " " res ) ; let tcx = self . cx . tcx ; let res_did = if let Some ( did ) = res . opt_def_id ( ) { did } else { return false ; } ; let use_attrs = tcx . hir ( ) . attrs ( id ) ; // Don't inline `doc(hidden)` imports so they can be stripped at a later stage. let is_no_inline = use_attrs . lists ( sym :: doc ) . has_word ( sym :: no_inline ) || use_attrs . lists ( sym :: doc ) . has_word ( sym :: hidden ) ; // For cross-crate impl inlining we need to know whether items are // reachable in documentation -- a previously nonreachable item can be // made reachable by cross-crate inlining which we're checking here. // (this is done here because we need to know this upfront). if ! res_did . is_local ( ) && ! is_no_inline { let attrs = clean :: inline :: load_attrs ( self . cx , res_did ) ; let self_is_hidden = attrs . lists ( sym :: doc ) . has_word ( sym :: hidden ) ; if ! self_is_hidden { if let Res :: Def ( kind , did ) = res { if kind == DefKind :: Mod { crate :: visit_lib :: LibEmbargoVisitor :: new ( self . cx ) . visit_mod ( did ) } else { // All items need to be handled here in case someone wishes to link // to them with intra-doc links self . cx . renderinfo . get_mut ( ) . access_levels . map . insert ( did , AccessLevel :: Public ) ; } } } return false ; } let res_hir_id = match res_did . as_local ( ) { Some ( n ) => tcx . hir ( ) . local_def_id_to_hir_id ( n ) , None => return false , } ; let is_private = ! self . cx . renderinfo . borrow ( ) . access_levels . is_public ( res_did ) ; let is_hidden = inherits_doc_hidden ( self . cx , res_hir_id ) ; // Only inline if requested or if the item would otherwise be stripped. if ( ! please_inline && ! is_private && ! is_hidden ) || is_no_inline { return false ; } if ! self . view_item_stack . insert ( res_hir_id ) { return false ; } let ret = match tcx . hir ( ) . get ( res_hir_id ) { Node :: Item ( & hir :: Item { kind : hir :: ItemKind :: Mod ( ref m ) , .. } ) if glob => { let prev = mem :: replace ( & mut self . inlining , true ) ; for i in m . item_ids { let i = self . cx . tcx . hir ( ) . expect_item ( i . id ) ; self . visit_item ( i , None , om ) ; } self . inlining = prev ; true } Node :: Item ( it ) if ! glob => { let prev = mem :: replace ( & mut self . inlining , true ) ; self . visit_item ( it , renamed , om ) ; self . inlining = prev ; true } Node :: ForeignItem ( it ) if ! glob => { let prev = mem :: replace ( & mut self . inlining , true ) ; self . visit_foreign_item ( it , renamed , om ) ; self . inlining = prev ; true } Node :: MacroDef ( def ) if ! glob => { om . macros . push ( self . visit_local_macro ( def , renamed . map ( | i | i . name ) ) ) ; true } _ => false , } ; self . view_item_stack . remove ( & res_hir_id ) ; ret }
Tries to resolve the target of a `crate use` statement and inlines the
target if it is defined locally and would not be documented otherwise,
or when it is specifically requested with `please_inline`.
Tries to resolve the target of a ` crate use ` statement and inlines the target if it is defined locally and would not be documented otherwise or when it is specifically requested with ` please_inline ` .
&mut self
id
hir::HirId
res
Res
renamed
Option<Ident>
glob
bool
om
&mut Module<'tcx>
please_inline
bool