- 
                Notifications
    You must be signed in to change notification settings 
- Fork 13.9k
Add unstable docs for rustc_attrs #73787
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
          
     Merged
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            4 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      f772587
              
                Add unstable docs for rustc_attrs
              
              
                pickfire 725918f
              
                Update src/doc/unstable-book/src/language-features/rustc-attrs.md
              
              
                pickfire 0e6f109
              
                Add preamable on rustc-attrs doc discussion
              
              
                pickfire 49b4804
              
                Ignore example compile in rustc-attrs doc
              
              
                pickfire File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
        
          
          
            53 changes: 53 additions & 0 deletions
          
          53 
        
  src/doc/unstable-book/src/language-features/rustc-attrs.md
  
  
      
      
   
        
      
      
    
  
    
      This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
      Learn more about bidirectional Unicode characters
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| # `rustc_attrs` | ||
|  | ||
| This feature has no tracking issue, and is therefore internal to | ||
| the compiler, not being intended for general use. | ||
|  | ||
| Note: `rustc_attrs` enables many rustc-internal attributes and this page | ||
| only discuss a few of them. | ||
|  | ||
| ------------------------ | ||
|  | ||
| The `rustc_attrs` feature allows debugging rustc type layouts by using | ||
| `#[rustc_layout(...)]` to debug layout at compile time (it even works | ||
| with `cargo check`) as an alternative to `rustc -Z print-type-sizes` | ||
| that is way more verbose. | ||
|  | ||
| Options provided by `#[rustc_layout(...)]` are `debug`, `size`, `abi`. | ||
| Note that it only work best with sized type without generics. | ||
|  | ||
| ## Examples | ||
|  | ||
| ```rust,ignore | ||
|         
                  RalfJung marked this conversation as resolved.
              Outdated
          
            Show resolved
            Hide resolved | ||
| #![feature(rustc_attrs)] | ||
|  | ||
| #[rustc_layout(abi, size)] | ||
| pub enum X { | ||
| Y(u8, u8, u8), | ||
| Z(isize), | ||
| } | ||
| ``` | ||
|  | ||
| When that is compiled, the compiler will error with something like | ||
|  | ||
| ```text | ||
| error: abi: Aggregate { sized: true } | ||
| --> src/lib.rs:4:1 | ||
| | | ||
| 4 | / pub enum T { | ||
| 5 | | Y(u8, u8, u8), | ||
| 6 | | Z(isize), | ||
| 7 | | } | ||
| | |_^ | ||
|  | ||
| error: size: Size { raw: 16 } | ||
| --> src/lib.rs:4:1 | ||
| | | ||
| 4 | / pub enum T { | ||
| 5 | | Y(u8, u8, u8), | ||
| 6 | | Z(isize), | ||
| 7 | | } | ||
| | |_^ | ||
|  | ||
| error: aborting due to 2 previous errors | ||
| ``` | ||
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.