Replies: 1 comment
-
| It turns out the whole function source code can be obtained from the span of  for item in stable_mir::all_local_items() {
    let inst = Instance::try_from(item).unwrap();
    let TyKind::RigidTy(RigidTy::FnDef(fn_def, _)) = inst.ty().kind() else {
        continue;
    };
    let Some(body) = fn_def.body() else {
        continue;
    };
    let src_whole_fn = source_code_with(body.span, tcx, &src_map);
    println!(" - {:?} ({:?}): {src_whole_fn}", item.name(), item.span());
} | 
Beta Was this translation helpful? Give feedback.
                  
                    0 replies
                  
                
            
  
    Sign up for free
    to join this conversation on GitHub.
    Already have an account?
    Sign in to comment
  
        
    
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Both of stable_mir's Instance and rustc_middle's Instance points to a function, but the span doesn't point to the whole function in source code.
Telling from the output, stable item and rustc_middle instance point to the same location, but only limited to fn without body.
While hir body gives the span of whole fn including name and sigature (example).
Beta Was this translation helpful? Give feedback.
All reactions