rust-lang / rust-lang/rust

rustdoc: Feature request: Also render the alignment under `--show-type-layout`

Open
#137,648 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

A-align A-rustdoc-type-layout C-feature-request T-rustdoc
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

Description

Problem

It can be tedious to query the size/alignment of non-generic types (struct, enum, union), which one might want to do for many reasons. Currently, you have to do one of the following:

  1. Compile a crate that has access to the type in question and print the value.
  2. Print the value from the playground, if the crate is available there (which probably wont be the case for anything you're currently working on.)
  3. Inspect compiler output via -Zprint-type-sizes.

All of these have the problem of having to compile code to get an answer.

Proposed Solution

The ideal solution would be to display the size & alignment of types in the cargo doc generated output, so you wouldn't have to build a crate.

Notes

I have no idea how feasible this is, but given that cargo doc already compiles and runs doc tests, it doesn't seem unreasonable.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by examining rustdoc's existing --show-type-layout behavior and compare it with compiler output from -Zprint-type-sizes. Trace how cargo doc renders type layout information. Done means cargo doc output reports both size and alignment for non-generic structs, enums, and unions without requiring extra code to be compiled.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
documentation
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.