File tree Expand file tree Collapse file tree 2 files changed +32
-1
lines changed 
compiler/rustc_typeck/src Expand file tree Collapse file tree 2 files changed +32
-1
lines changed Original file line number Diff line number Diff line change @@ -26,6 +26,17 @@ use rustc_trait_selection::traits::{ObligationCause, ObligationCauseCode};
2626use  std:: cell:: { Cell ,  RefCell } ; 
2727use  std:: ops:: Deref ; 
2828
29+ /// The `FnCtxt` stores type-checking context needed to type-check bodies of 
30+ /// functions, closures, and `const`s, including performing type inference 
31+ /// with [`InferCtxt`]. 
32+ /// 
33+ /// This is in contrast to [`ItemCtxt`], which is used to type-check item *signatures* 
34+ /// and thus does not perform type inference. 
35+ /// 
36+ /// See [`ItemCtxt`]'s docs for more. 
37+ /// 
38+ /// [`ItemCtxt`]: crate::collect::ItemCtxt 
39+ /// [`InferCtxt`]: infer::InferCtxt 
2940pub  struct  FnCtxt < ' a ,  ' tcx >  { 
3041    pub ( super )  body_id :  hir:: HirId , 
3142
Original file line number Diff line number Diff line change @@ -94,7 +94,27 @@ pub fn provide(providers: &mut Providers) {
9494/////////////////////////////////////////////////////////////////////////// 
9595
9696/// Context specific to some particular item. This is what implements 
97- /// `AstConv`. It has information about the predicates that are defined 
97+ /// [`AstConv`]. 
98+ /// 
99+ /// # `ItemCtxt` vs `FnCtxt` 
100+ /// 
101+ /// `ItemCtxt` is primarily used to type-check item signatures and lower them 
102+ /// from HIR to their [`ty::Ty`] representation, which is exposed using [`AstConv`]. 
103+ /// It's also used for the bodies of items like structs where the body (the fields) 
104+ /// are just signatures. 
105+ /// 
106+ /// This is in contrast to [`FnCtxt`], which is used to type-check bodies of 
107+ /// functions, closures, and `const`s -- anywhere that expressions and statements show up. 
108+ /// 
109+ /// An important thing to note is that `ItemCtxt` does no inference -- it has no [`InferCtxt`] -- 
110+ /// while `FnCtxt` does do inference. 
111+ /// 
112+ /// [`FnCtxt`]: crate::check::FnCtxt 
113+ /// [`InferCtxt`]: rustc_infer::infer::InferCtxt 
114+ /// 
115+ /// # Trait predicates 
116+ /// 
117+ /// `ItemCtxt` has information about the predicates that are defined 
98118/// on the trait. Unfortunately, this predicate information is 
99119/// available in various different forms at various points in the 
100120/// process. So we can't just store a pointer to e.g., the AST or the 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments