File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed 
compiler/rustc_middle/src/ty Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -64,6 +64,28 @@ bitflags! {
6464/// Moreover, Rust only allows recursive data types through indirection. 
6565/// 
6666/// [adt]: https://en.wikipedia.org/wiki/Algebraic_data_type 
67+ /// 
68+ /// # Recursive types 
69+ /// 
70+ /// It may seem impossible to represent recursive types using [`Ty`], 
71+ /// since [`TyKind::Adt`] includes [`AdtDef`], which includes its fields, 
72+ /// creating a cycle. However, `AdtDef` does not actually include the *types* 
73+ /// of its fields; it includes just their [`DefId`]s. 
74+ /// 
75+ /// For example, the following type: 
76+ /// 
77+ /// ``` 
78+ /// struct S { x: Box<S> } 
79+ /// ``` 
80+ /// 
81+ /// is essentially represented with [`Ty`] as the following pseudocode: 
82+ /// 
83+ /// ``` 
84+ /// struct S { x } 
85+ /// ``` 
86+ /// 
87+ /// where `x` here represents the `DefId` of `S.x`. Then, the `DefId` 
88+ /// can be used with [`TyCtxt::type_of()`] to get the type of the field. 
6789pub  struct  AdtDef  { 
6890    /// The `DefId` of the struct, enum or union item. 
6991pub  did :  DefId , 
Original file line number Diff line number Diff line change @@ -1735,7 +1735,7 @@ impl ReprOptions {
17351735
17361736impl < ' tcx >  FieldDef  { 
17371737    /// Returns the type of this field. The resulting type is not normalized. The `subst` is 
1738- /// typically obtained via the second field of `TyKind::AdtDef` . 
1738+ /// typically obtained via the second field of [ `TyKind::Adt`] . 
17391739pub  fn  ty ( & self ,  tcx :  TyCtxt < ' tcx > ,  subst :  SubstsRef < ' tcx > )  -> Ty < ' tcx >  { 
17401740        tcx. type_of ( self . did ) . subst ( tcx,  subst) 
17411741    } 
 
 
   
 
     
   
   
          
    
    
     
    
      
     
     
    You can’t perform that action at this time.
  
 
    
  
    
      
        
     
       
      
     
   
 
    
    
  
 
  
 
     
    
0 commit comments