rust/src/librustc_session
Yuki Okushi a82390407a
Rollup merge of #67215 - nnethercote:fix-Zprint-type-size-zero-sized-fields, r=pnkfelix
Fix `-Z print-type-sizes`'s handling of zero-sized fields.

Currently, the type `struct S { x: u32, y: u32, tag: () }` is
incorrectly described like this:
```
print-type-size type: `S`: 8 bytes, alignment: 4 bytes
print-type-size     field `.x`: 4 bytes
print-type-size     field `.tag`: 0 bytes, offset: 0 bytes, alignment: 1 bytes
print-type-size     padding: 4 bytes
print-type-size     field `.y`: 4 bytes, alignment: 4 bytes
```
Specifically:
- The `padding` line is wrong. (There is no padding.)
- The `offset` and `alignment` on the `.tag` line shouldn't be printed.

The problem is that multiple fields can end up with the same offset, and
the printing code doesn't handle this correctly.

This commit fixes it by adjusting the field sorting so that zero-sized fields
are dealt with before non-zero-sized fields. With that in place, the
printing code works correctly.

The commit also corrects the "something is very wrong" comment.

The new output looks like this:
```
print-type-size type: `S`: 8 bytes, alignment: 4 bytes
print-type-size     field `.tag`: 0 bytes
print-type-size     field `.x`: 4 bytes
print-type-size     field `.y`: 4 bytes
```
r? @pnkfelix
2019-12-12 10:09:21 +09:00
..
Cargo.toml Move Session to librustc_session 2019-12-03 12:19:16 -05:00
cgu_reuse_tracker.rs Move cgu_reuse_tracker to librustc_session 2019-12-03 12:18:32 -05:00
code_stats.rs Fix -Z print-type-sizes's handling of zero-sized fields. 2019-12-11 15:09:19 +11:00
config.rs Add options to --extern flag. 2019-12-09 08:08:13 -08:00
filesearch.rs Move Session to librustc_session 2019-12-03 12:19:16 -05:00
lib.rs Move Session to librustc_session 2019-12-03 12:19:16 -05:00
lint.rs Move BufferedEarlyLint to librustc_session 2019-12-03 12:19:16 -05:00
node_id.rs Move BufferedEarlyLint to librustc_session 2019-12-03 12:19:16 -05:00
parse.rs Deduplicate CrateConfig 2019-12-03 12:19:17 -05:00
search_paths.rs Move Session to librustc_session 2019-12-03 12:19:16 -05:00
session.rs Use as_ref().map() rather than is_some().to_option() 2019-12-06 12:23:44 +00:00
utils.rs Move NativeLibraryKind to rustc_session 2019-12-03 12:19:16 -05:00