pub fn dump_function(
    goal: (&str, usize),
    path: &Path,
    sysroot: &Path,
    fmt: &Format,
    items: &mut Vec<Item>,
) -> anyhow::Result<bool> {
    let contents = std::fs::read_to_string(path)?;
    let mut show = false;
    let mut seen = false;
    let mut prev_loc = Loc::default();

    let mut files = BTreeMap::new();
    let mut names = BTreeMap::new();

    let mut current_item = None;
    for (ix, line) in parse_file(&contents)
        .expect("Should be able to parse file")
        .1
        .iter()
        .enumerate()
    {
        if let Statement::Label(label) = line {
            if let Some(dem) = demangle::demangled(label.id) {
                let hashed = format!("{dem:?}");
                let name = format!("{dem:#?}");
                let name_entry = names.entry(name.clone()).or_insert(0);

                show = (name.as_ref(), *name_entry) == goal || hashed == goal.0;
                current_item = Some(Item {
                    name,
                    hashed,
                    index: *name_entry,
                    len: ix,
                });
                *name_entry += 1;
                seen |= show;
            }
        }

        if let Statement::Directive(Directive::File(f)) = line {
            if !fmt.rust {
                continue;
            }
            files.entry(f.index).or_insert_with(|| {
                if let Ok(payload) = std::fs::read_to_string(f.name) {
                    return (f.name, CachedLines::without_ending(payload));
                } else if f.name.starts_with("/rustc/") {
                    if let Some(x) = f.name.splitn(4, '/').last() {
                        let src = sysroot.join("lib/rustlib/src/rust").join(x);
                        if let Ok(payload) = std::fs::read_to_string(src) {
                            return (f.name, CachedLines::without_ending(payload));
                        }
                    }
                }
                // if file is not found - ust create a dummy
                (f.name, CachedLines::without_ending(String::new()))
            });
            continue;
        }
        if show {
            if let Statement::Directive(Directive::Loc(loc)) = &line {
                if !fmt.rust {
                    continue;
                }
                if loc.line == 0 {
                    continue;
                }
                if loc == &prev_loc {
                    continue;
                }
                prev_loc = *loc;
                if let Some((fname, file)) = files.get(&loc.file) {
                    let rust_line = &file[loc.line as usize - 1];
                    let pos = format!("\t\t// {} : {}", fname, loc.line);
                    println!("{}", color!(pos, OwoColorize::cyan));
                    println!(
                        "\t\t{}",
                        color!(rust_line.trim_start(), OwoColorize::bright_red)
                    );
                }
            } else {
                #[allow(clippy::collapsible_else_if)]
                if fmt.full_name {
                    println!("{line:#}");
                } else {
                    println!("{line}");
                }
            }
        }

        if line.is_end_of_fn() {
            if let Some(mut cur) = current_item.take() {
                cur.len = ix - cur.len;
                if goal.0.is_empty() || cur.name.contains(goal.0) {
                    items.push(cur);
                }
            }
            if seen {
                return Ok(true);
            }
        }
    }
    Ok(seen)
}
/// try to print `goal` from `path`, collect available items otherwise
try to print `goal` from `path`, collect available items otherwise
try to print ` goal ` from ` path ` collect available items otherwise
pub fn dump_function(
    goal: (&str, usize),
    path: &Path,
    sysroot: &Path,
    fmt: &Format,
    items: &mut Vec<Item>,
) -> anyhow::Result<bool> {
    let contents = std::fs::read_to_string(path)?;
    let mut show = false;
    let mut seen = false;
    let mut prev_loc = Loc::default();
    let mut files = BTreeMap::new();
    let mut names = BTreeMap::new();
    let mut current_item = None;
    for (ix, line) in parse_file(&contents)
        .expect("Should be able to parse file")
        .1
        .iter()
        .enumerate()
    {
        if let Statement::Label(label) = line {
            if let Some(dem) = demangle::demangled(label.id) {
                let hashed = format!("{dem:?}");
                let name = format!("{dem:#?}");
                let name_entry = names.entry(name.clone()).or_insert(0);
                show = (name.as_ref(), *name_entry) == goal || hashed == goal.0;
                current_item = Some(Item {
                    name,
                    hashed,
                    index: *name_entry,
                    len: ix,
                });
                *name_entry += 1;
                seen |= show;
            }
        }
        if let Statement::Directive(Directive::File(f)) = line {
            if !fmt.rust {
                continue;
            }
            files.entry(f.index).or_insert_with(|| {
                if let Ok(payload) = std::fs::read_to_string(f.name) {
                    return (f.name, CachedLines::without_ending(payload));
                } else if f.name.starts_with("/rustc/") {
                    if let Some(x) = f.name.splitn(4, '/').last() {
                        let src = sysroot.join("lib/rustlib/src/rust").join(x);
                        if let Ok(payload) = std::fs::read_to_string(src) {
                            return (f.name, CachedLines::without_ending(payload));
                        }
                    }
                }
                // if file is not found - ust create a dummy
                (f.name, CachedLines::without_ending(String::new()))
            });
            continue;
        }
        if show {
            if let Statement::Directive(Directive::Loc(loc)) = &line {
                if !fmt.rust {
                    continue;
                }
                if loc.line == 0 {
                    continue;
                }
                if loc == &prev_loc {
                    continue;
                }
                prev_loc = *loc;
                if let Some((fname, file)) = files.get(&loc.file) {
                    let rust_line = &file[loc.line as usize - 1];
                    let pos = format!("\t\t// {} : {}", fname, loc.line);
                    println!("{}", color!(pos, OwoColorize::cyan));
                    println!(
                        "\t\t{}",
                        color!(rust_line.trim_start(), OwoColorize::bright_red)
                    );
                }
            } else {
                #[allow(clippy::collapsible_else_if)]
                if fmt.full_name {
                    println!("{line:#}");
                } else {
                    println!("{line}");
                }
            }
        }
        if line.is_end_of_fn() {
            if let Some(mut cur) = current_item.take() {
                cur.len = ix - cur.len;
                if goal.0.is_empty() || cur.name.contains(goal.0) {
                    items.push(cur);
                }
            }
            if seen {
                return Ok(true);
            }
        }
    }
    Ok(seen)
}
pub fn dump_function ( goal : ( & str , usize ) , path : & Path , sysroot : & Path , fmt : & Format , items : & mut Vec < Item > , ) -> anyhow :: Result < bool > { let contents = std :: fs :: read_to_string ( path ) ? ; let mut show = false ; let mut seen = false ; let mut prev_loc = Loc :: default ( ) ; let mut files = BTreeMap :: new ( ) ; let mut names = BTreeMap :: new ( ) ; let mut current_item = None ; for ( ix , line ) in parse_file ( & contents ) . expect ( " " ) . 1 . iter ( ) . enumerate ( ) { if let Statement :: Label ( label ) = line { if let Some ( dem ) = demangle :: demangled ( label . id ) { let hashed = format ! ( " " ) ; let name = format ! ( " " ) ; let name_entry = names . entry ( name . clone ( ) ) . or_insert ( 0 ) ; show = ( name . as_ref ( ) , * name_entry ) == goal || hashed == goal . 0 ; current_item = Some ( Item { name , hashed , index : * name_entry , len : ix , } ) ; * name_entry += 1 ; seen |= show ; } } if let Statement :: Directive ( Directive :: File ( f ) ) = line { if ! fmt . rust { continue ; } files . entry ( f . index ) . or_insert_with ( | | { if let Ok ( payload ) = std :: fs :: read_to_string ( f . name ) { return ( f . name , CachedLines :: without_ending ( payload ) ) ; } else if f . name . starts_with ( " " ) { if let Some ( x ) = f . name . splitn ( 4 , '/' ) . last ( ) { let src = sysroot . join ( " " ) . join ( x ) ; if let Ok ( payload ) = std :: fs :: read_to_string ( src ) { return ( f . name , CachedLines :: without_ending ( payload ) ) ; } } } // if file is not found - ust create a dummy ( f . name , CachedLines :: without_ending ( String :: new ( ) ) ) } ) ; continue ; } if show { if let Statement :: Directive ( Directive :: Loc ( loc ) ) = & line { if ! fmt . rust { continue ; } if loc . line == 0 { continue ; } if loc == & prev_loc { continue ; } prev_loc = * loc ; if let Some ( ( fname , file ) ) = files . get ( & loc . file ) { let rust_line = & file [ loc . line as usize - 1 ] ; let pos = format ! ( " \t \t " fname loc line ) ; println ! ( " " color ( pos OwoColorize cyan ) ) ; println ! ( " \t \t " color ( rust_line trim_start ( ) OwoColorize bright_red ) ) ; } } else { # [ allow ( clippy collapsible_else_if ) ] if fmt . full_name { println ! ( " " ) ; } else { println ! ( " " ) ; } } } if line . is_end_of_fn ( ) { if let Some ( mut cur ) = current_item . take ( ) { cur . len = ix - cur . len ; if goal . 0 . is_empty ( ) || cur . name . contains ( goal . 0 ) { items . push ( cur ) ; } } if seen { return Ok ( true ) ; } } } Ok ( seen ) }
try to print `goal` from `path`, collect available items otherwise
try to print ` goal ` from ` path ` collect available items otherwise
goal
(&str, usize)
path
&Path
sysroot
&Path
fmt
&Format
items
&mut Vec<Item>