Skip to content

add tool to "enforce" semantic line breaks #1485

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

Draft
wants to merge 1,872 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
1872 commits
Select commit Hold shift + click to select a range
87968b4
Describe how to trigger perf runs (#1237)
lqd Oct 21, 2021
f68aff5
Switch date-check to Rust 2021
camelid Oct 21, 2021
b060087
Update author field
camelid Oct 21, 2021
68dbb45
Add documentation for LLVM CFI support
rcvalle Oct 14, 2021
ddaebd8
Fix `rustc_mir` related links (#1228)
Lee-Janggun Oct 28, 2021
f3fb373
Edit "About this guide" for semantic line feeds
pierwill Oct 28, 2021
70966e5
Some minor adjustments to the diagnostic documentation
xFrednet Oct 28, 2021
0f69d33
Edit introduction to bootstrapping
pierwill Oct 24, 2021
292072d
enhance subtree docs, link to clippy docs
calebcartwright Nov 2, 2021
dac568c
Ensure date-check cron job is using latest stable Rust
camelid Nov 3, 2021
f146da3
Update some date-check comments
camelid Nov 3, 2021
2ad51b6
Fix date
camelid Nov 4, 2021
a034fad
tiny capitalization fix
dmitris Nov 4, 2021
8a8452c
Remove some legacy test suites.
ehuss Nov 4, 2021
ffcc629
Add note to emphasize replacing TARGET_TRIPLE (#1250)
asquared31415 Nov 6, 2021
196ef69
Fix typo: [upv.rs_mentioned] -> [upvars_mentioned]
chubei Nov 7, 2021
6b9c8ae
Fix broken link in "Bootstrapping"
camelid Nov 10, 2021
f1297f5
Fix compare-mode documentation
rukai Nov 14, 2021
0fc1fa9
Spelling fixes
rukai Nov 15, 2021
24132fa
Unify `x.py` usage (#1258)
ken-matsui Nov 15, 2021
766f9d7
Fix broken links related to `rustc_borrowck` (#1259)
JohnTitor Nov 16, 2021
5fbfe93
Fix an invalid link on Diagnostic Items (#1261)
ken-matsui Nov 16, 2021
a2fc963
Describe drop elaboration (#1240)
ecstatic-morse Nov 18, 2021
6a27fc2
make it compile with 1.56.0
simon-perriard Nov 24, 2021
1f0c4f0
make it compile with 1.56.0
simon-perriard Nov 24, 2021
94e9e67
make it compile with 1.56.0 no warning
simon-perriard Nov 24, 2021
285b3e4
Document more compiletest headers.
ehuss Nov 4, 2021
9660c15
Apply suggestions from pierwill
ehuss Nov 5, 2021
aaf6ccc
Document rustfix-only-machine-applicable
ehuss Nov 5, 2021
8a817bc
Update for review comments.
ehuss Nov 19, 2021
c4776cb
Fix some links
JohnTitor Nov 15, 2021
2cee5a9
Improve 'Running tests manually' section
rukai Nov 27, 2021
a374e7d
Update LLVM coverage mapping format version supported by rustc (#1267)
richkadel Dec 3, 2021
3df5cc9
Improve documentation on r?
rukai Dec 5, 2021
0c0e4f2
Update src/getting-started.md
rukai Dec 7, 2021
6c1f5c7
Fix some broken links
camelid Dec 5, 2021
b6cf9a7
Update HIR chapter to use `HirId` instead of `NodeId`
camelid Dec 5, 2021
f9db2f4
Update rustdoc internals
jsha Dec 5, 2021
5dd756b
Fix some broken links (#1274)
Badel2 Dec 13, 2021
35dce02
Update humor docs for special-casing ferris emoji
mheiber Dec 15, 2021
7340eb8
Move date-check comment to fix Markdown syntax
camelid Dec 15, 2021
9bf0028
remove rustfix item in test intro (#1277)
wangkirin Dec 20, 2021
a11e5f4
Streamline "Getting Started" (#1279)
nnethercote Dec 24, 2021
f6a190e
Fix link in contributing.md (#1280)
BGR360 Dec 27, 2021
8754644
Update link to moved section (#1282)
camelid Dec 29, 2021
a992723
Streamline "Getting Started" some more.
nnethercote Jan 5, 2022
acc6718
Address review comments in #1286.
nnethercote Jan 6, 2022
18b93ae
Address more review comments in #1286.
nnethercote Jan 6, 2022
a10c5be
Clean up section about FCPs (#1287)
camelid Jan 18, 2022
60bc9ab
Spelling: Rename `rust` to `Rust` (#1288)
jubnzv Jan 18, 2022
4d46bd0
Add inline assembly internals (#1266)
Amanieu Jan 18, 2022
78dd6a4
Reorganize and expand the testing chapters. (#1281)
ehuss Jan 18, 2022
341abec
Clarify that r? works in comments.
iwanders Jan 20, 2022
8763adb
git.md: Expanded a note to try to stress what you need to do if you'r…
pnkfelix Jan 26, 2022
dc47b51
mention test folders for cfg(bootstrap) (#1294)
Manishearth Feb 5, 2022
d1822b9
Triage some date references (#1293)
JohnTitor Feb 10, 2022
62f5839
Correction, building stage3 compiler (#1298)
raoulstrackx Feb 11, 2022
5e38eb6
Link to The Rust Performance Book (#1300)
pierwill Feb 17, 2022
cb3fb94
Edit "Queries" chapter (#1301)
pierwill Feb 17, 2022
2c9be18
Fix link
pierwill Feb 17, 2022
1fa751d
Fix heading levels in the query chapter (#1305)
camelid Feb 17, 2022
68c7649
Edit glossary (#1302)
pierwill Feb 17, 2022
5483b27
Fix `Ty` link (#1308)
pierwill Feb 20, 2022
eefbde5
symbol-mangling-version has been stabilized
ehuss Feb 20, 2022
d335c9c
instrument-coverage has been stabilized.
ehuss Feb 20, 2022
e798dc4
Typo (#1313)
smoelius Feb 23, 2022
9e2cdee
Fix typo (#1315)
teobouvard Feb 24, 2022
24e474c
Add known-bug header. (#1311)
ehuss Feb 25, 2022
7d8eb87
cargo timings has been stabilized (#1319)
ehuss Feb 28, 2022
32f2a5b
Add architecture suggestion for Apple silicon (#1320)
jamescoleuk Mar 1, 2022
eb90c9c
Fix incorrectly escaped backtick
ChayimFriedman2 Mar 2, 2022
4b8d939
Add missing rustdoc tests explanations
GuillaumeGomez Mar 9, 2022
0e4b961
update winget install instructions to ensure proper packages are inst…
User1785604260 Mar 12, 2022
155126b
update section for type system constants (#1329)
lcnr Mar 22, 2022
127abaa
Add example how lints can be feature gated
xFrednet Apr 1, 2022
f5f6b4f
Update miri.md: correct a minor typo (#1334)
ya0guang Apr 5, 2022
664d3c7
r-a: Use `python3 x.py` instead of `./x.py` (#1335)
camelid Apr 9, 2022
fbda644
Update examples with 1.61.0-nightly (latest version) (#1330)
ujjawal4046 Apr 11, 2022
885d329
Consolidate crates.io convention section (#1326)
iwanders Apr 11, 2022
eeb5a83
method-lookup.md improvements (#1296)
mattheww Apr 11, 2022
d9bfa37
sessiondiagnostic: translation (#1333)
davidtwco Apr 14, 2022
e58b4c0
Minor type fix (#1337)
eholk Apr 14, 2022
aa31b10
Fix typo serious->series (#1336)
steffahn Apr 14, 2022
c190ae3
Send people doing *library* stabilizations over to the std-dev-guide …
scottmcm Apr 14, 2022
a8add66
Extend debugging llvm section (#1290)
pnkfelix Apr 14, 2022
043e60f
Fix a small typo (#1343)
printfn Apr 20, 2022
e827b0a
Update some date refs
JohnTitor Apr 15, 2022
9ec0190
Edit "What the compiler does to your code" (#1306)
pierwill May 2, 2022
acb1fcb
Document ErrorGuaranteed (#1316)
mark-i-m May 3, 2022
2de8cb5
correct type of SubstsRef (#1347)
aliemjay May 7, 2022
a9d0e35
Fix format (#1349)
ohno418 May 9, 2022
e4ce969
mention `WithOptConstParam` (#1346)
lcnr May 9, 2022
425fa20
Update date references on parallel-rustc (#1348)
JohnTitor May 9, 2022
0c02acd
Update overview.md (#1351)
ihaveint May 10, 2022
687f603
Update docs for deprecated attribute (#1338)
jhpratt May 12, 2022
77f7fa2
Fix configuration names for vscode/r-a (#1352)
WaffleLapkin May 12, 2022
b24d550
Add docs for logging of queries. (#1350)
ehuss May 12, 2022
06445e6
Edit the "Compiler Source Code" chapter (#1307)
pierwill May 16, 2022
b389adc
Replace a broken YouTube link (#1295)
JohnTitor May 16, 2022
0b2c9db
Update some links and docs (#1340)
JohnTitor May 16, 2022
12a2e08
make sentence more simple (#1353)
tshepang May 20, 2022
0cd9842
Add note about patching dependencies and warnings. (#1354)
ehuss May 21, 2022
2ba653e
Exclude `tomlee.co` from link-checking (#1356)
JohnTitor May 24, 2022
5e26873
Fix some wording on the "Incremental Compilation In Detail" page
JohnTitor May 24, 2022
554c00e
Cleanup rustdoc-internals
JohnTitor May 21, 2022
6692629
Triage some date references related to traits
JohnTitor May 28, 2022
a206009
Update rustc-driver related examples
JohnTitor May 1, 2022
4d43651
Clarify cargo fallback behavior for rustup link (#1273)
couchand Jun 6, 2022
72a3895
Bump regex from 1.4.3 to 1.5.5 in /ci/date-check (#1364)
dependabot[bot] Jun 6, 2022
4383648
improve rustc_interface examples a little (#1362)
tshepang Jun 6, 2022
6e4d643
Make build scripts and proc macros work with the suggested rust-analy…
Jun 7, 2022
bc81f99
add section on user types (#1359)
lcnr Jun 8, 2022
e83cd73
Remove nll compare mode. (#1366)
ehuss Jun 8, 2022
375a9f0
Remove mention of -Zborrowck=mir with Polonius. (#1367)
ehuss Jun 8, 2022
ee64179
later -> latter
Jun 12, 2022
56ec010
diagnostics: line wrapping/heading changes
davidtwco Jun 6, 2022
c4d5a69
diagnostics: add translation documentation
davidtwco Jun 6, 2022
cddd59f
Add an "is" and rearange "We next" to "Next, we" (#1369)
EdwinRy Jun 18, 2022
bda3e0b
Fix small `src/diagnostics.md` typo (#1370)
omertuc Jun 18, 2022
12a613e
make clear that other versions can work (#1373)
tshepang Jun 21, 2022
a3d2f90
small improves (#1371)
tshepang Jun 21, 2022
048d925
not obvious what Ex is, so rather get rid (#1372)
tshepang Jun 21, 2022
4505f70
humorust: Forbid pineapple on pizza (#1374)
Alcaro Jun 26, 2022
03fafb5
Few readability fixes
EdwinRy Jun 27, 2022
11b4065
diagnostics: structs with new slug syntax (#1377)
davidtwco Jun 28, 2022
f423a3a
leave formatOnSave to the user (#1380)
RalfJung Jul 1, 2022
a05e1fd
Fix path to hir_id_validator.rs
danobi Jul 2, 2022
d955bab
Add the config needed to get rust-analyzer working on src/bootstrap (…
jyn514 Jul 3, 2022
ef73d03
Change the old filename, "src/stage0.txt" to "src/stage0.json" (#1383)
ohno418 Jul 3, 2022
eb83839
Suggest a separate build directory for rust-analyzer (#1378)
jyn514 Jul 3, 2022
07efe00
Use `x.py check` instead of `cargo check` for build scripts (#1384)
jyn514 Jul 6, 2022
f1d10fb
Revert "Add the config needed to get rust-analyzer working on src/boo…
spastorino Jul 6, 2022
0855fc9
Git-ignore `pulls.json` (#1386)
JohnTitor Jul 7, 2022
8accea6
overview.md: Link to existing Macro Expansion and Name Resolution doc…
Enselic Jul 8, 2022
f92263e
Update the build instructions for the standard library
jyn514 Jul 11, 2022
4a96ed5
small fixes to ty chapter (#1390)
tshepang Jul 15, 2022
47e0444
remove outdated info on debugging
tshepang Jul 15, 2022
7a99011
update date reference on MIR inliner
tshepang Jul 14, 2022
0eb86d9
address review comment
tshepang Jul 14, 2022
2e754ba
Rename debugging_opts to unstable_opts, use link
5225225 Jul 16, 2022
8bbee4f
typo: monomorph docs
davidrusu Jul 16, 2022
56eb8b6
fix some typos (#1398)
tshepang Jul 16, 2022
ade9352
use relative links
tshepang Jul 16, 2022
e764363
add mdbook-mermaid
nikomatsakis Feb 7, 2022
53395b0
add draft chapter
nikomatsakis Feb 7, 2022
857ee49
sync with hackmd
hackmd-deploy Feb 7, 2022
5cc90f3
obey line length limit
tshepang Jul 17, 2022
1b62c12
obey line length limit (part 2)
tshepang Jul 17, 2022
1684423
obey line length limit (part 3)
tshepang Jul 17, 2022
dca7b1b
Remove a mention to Steve on r? example
JohnTitor Jul 18, 2022
2802da7
replace misleading name (#1401)
tshepang Jul 19, 2022
0c2f5c9
sync with hackmd version
tshepang Jul 17, 2022
6e1ac9d
renamed
tshepang Jul 17, 2022
2b87b31
remove stray markup
tshepang Jul 18, 2022
5c8febd
Fix link to clippy sync docs
fasterthanlime Jul 19, 2022
bac43d0
Link to rendered book directly
fasterthanlime Jul 19, 2022
d5201cd
Debuginfo tests now also support revisions.
luqmana Jul 20, 2022
bcc1166
rust-analyzer is now a subtree
fasterthanlime Jul 25, 2022
c7637de
Add documentation about Microsoft provided debuggers and CodeView/PDB…
ridwanabdillahi Jul 25, 2022
e5e5a9b
Document how to build a cross-compiler
bstrie Jul 22, 2022
30a4d2b
Add instructions to fix build errors in std after adding a new target
Urgau Jul 29, 2022
c0b491e
Fix the link to `Lazy<T>`
JohnTitor Jul 26, 2022
18fa8fb
Fix the link to `ProcMacro` trait
JohnTitor Jul 26, 2022
bbbd60d
Fix the link to `ResolverAstLowering`
JohnTitor Jul 26, 2022
637ebaa
Fix the link to clippy docs
JohnTitor Jul 26, 2022
7955bb3
Prefer relative links
JohnTitor Jul 26, 2022
ea7e58a
minor fixes
tshepang Jul 30, 2022
67af5ca
revamp doc-build chapter
tshepang Jul 19, 2022
6f97f45
Update src/building/compiler-documenting.md
tshepang Jul 22, 2022
d9596c6
summary of chapter
tshepang Jul 30, 2022
3389074
try address review comments
tshepang Jul 30, 2022
3678b50
accept review suggestion
tshepang Jul 31, 2022
04f3cf0
address review comment
tshepang Jul 31, 2022
2557089
make date-check more lightweight (#1394)
tshepang Aug 2, 2022
5c4b673
date-check: be more strict
tshepang Aug 2, 2022
e305a42
note is now too old to be relevant
tshepang Aug 7, 2022
6964f75
date-check: rustc_codegen_ssa is still alive
tshepang Aug 7, 2022
4b2f038
Add bootstrapping diagram
camelid Aug 9, 2022
c1c84d6
Add colors to diagram
camelid Aug 9, 2022
81a4d04
Add color for downloaded nodes
camelid Aug 9, 2022
df17432
Fix legend colors in dark mode
camelid Aug 9, 2022
1dee5f8
update date-check format on github issue (#1416)
tshepang Aug 9, 2022
f979af6
move references down to avoid clutter (#1420)
tshepang Aug 9, 2022
af80d31
add gdb tips for symbol-mangling-version
chenyukang Aug 10, 2022
4c39d33
Update src/compiler-debugging.md
jyn514 Aug 10, 2022
24de0fa
fix/improve compiler-debugging
tshepang Aug 10, 2022
452b5ab
date-check: crates-io
tshepang Aug 11, 2022
d3daa1f
Improve the "Diagnostic items" chapter (#1427)
tshepang Aug 13, 2022
04e1702
Update the date reference around Git submodule bug (#1430)
tshepang Aug 17, 2022
8ee1ff5
fix lifetime name (#1431)
tshepang Aug 17, 2022
47c8189
remove incorrect info (#1435)
tshepang Aug 17, 2022
2512667
Update slug style to use _ instead of - (#1426)
est31 Aug 17, 2022
9334d59
fix incorrect #[note] syntax
CleanCut Aug 18, 2022
0a80e53
more syntax fixes
CleanCut Aug 18, 2022
f3fe248
Add missing lifetime (#1439)
CleanCut Aug 19, 2022
0a61352
diagnostics: fix outdated use of string slugs (#1436)
davidtwco Aug 19, 2022
c2371da
Document changes introduced by kind-less SessionDiagnostics
Xiretza Aug 19, 2022
e81b583
fix quick-edit link (#1441)
tshepang Aug 22, 2022
18fc34b
do not offer option to run code (#1442)
tshepang Aug 22, 2022
1e7fe14
update thir output (#1445)
tshepang Aug 24, 2022
bedc610
make date-check more easy to use
tshepang Aug 14, 2022
b0a0a4f
address review comment
tshepang Aug 19, 2022
9c9882c
update parallel-rustc.md
SparrowLii Aug 15, 2022
a240e52
Correct some statements in parallel-rustc.md
SparrowLii Aug 16, 2022
1be023c
correct typo in parallel-rustc.md
SparrowLii Aug 16, 2022
d7832db
Update some statements
SparrowLii Aug 25, 2022
8ba0403
A few corrections
SparrowLii Aug 26, 2022
94a29d4
we got 3 (#1447)
tshepang Aug 26, 2022
20e571f
Updates LLVM prereqs since upgrade to C++17.
red1bluelost Aug 27, 2022
2bf1b9a
Updates text to refer to LLVM documentation.
red1bluelost Aug 27, 2022
daca468
typo
tshepang Aug 27, 2022
b5a632f
Refine the lintstore section (#1429)
tshepang Aug 27, 2022
2a9f8fb
Update the stabilization guide to refer to the new placeholder system
est31 Aug 23, 2022
c0c957c
Remove a dangling link on "The `#[test]` attribute"
JohnTitor Aug 29, 2022
04892c1
Fix the link to `Parser` struct
JohnTitor Aug 29, 2022
6b0a155
Update for removal of RLS (#1450)
ehuss Sep 2, 2022
8593238
Add reference for updating Windows PATH and fix typo
Samyak2 Aug 30, 2022
5be5475
Document multipart_suggestion derive on SessionSubdiagnostic
Xiretza Aug 24, 2022
a5363fb
Fix typo (#1459)
eholk Sep 9, 2022
5d8825e
Add symbol-addition to the how-to for new features (#1457)
ssbr Sep 11, 2022
f29e38c
"symbol names" => ABI
jyn514 Sep 10, 2022
c3232c4
Remove the diagram of all outputs generated by x.py
jyn514 Sep 10, 2022
6b3a5fb
Rewrite the section on passing flags to subcommands
jyn514 Sep 10, 2022
a605591
Say "bootstrap" instead of "rustbuild"; the latter is not explained a…
jyn514 Sep 10, 2022
290ecb9
fix typos and formatting
jyn514 Sep 12, 2022
f1609a3
Explain the new valtree system for type level constants. (#1097)
oli-obk Sep 13, 2022
b21b0bb
remove stray **
tshepang Sep 14, 2022
39612f9
Link from "implementing to new features" to mcp.md (#1465)
pnkfelix Sep 15, 2022
1f8cda6
Add a note about building `rust-analyzer-proc-macro-srv` (#1467)
WaffleLapkin Sep 19, 2022
f587d6e
Update stability guide to use CURRENT_RUSTC_VERSION (#1468)
SUPERCILEX Sep 19, 2022
f349ee1
Fix some typos
JohnTitor Sep 19, 2022
b8b984f
Update some actions versions
JohnTitor Sep 19, 2022
03752ab
Remove unmaintained action
JohnTitor Sep 19, 2022
27c2aa6
Update mdbook and its extensions versions
JohnTitor Sep 20, 2022
1c79085
UPDATE - Diagnostic docs to reflect renamed traits and macros in rust…
JhonnyBillM Sep 9, 2022
7743f0f
don't refer to the compile-time interpreter as "Miri" (#1471)
RalfJung Sep 26, 2022
ed11720
Update r-a config suggestions
Veykril Oct 1, 2022
1370793
Link to the correct page in "about this guide"
jyn514 Sep 3, 2022
de71812
Update about-this-guide.md
jyn514 Oct 2, 2022
882921a
fix typo and make paragraph consistent (#1474)
Joshument Oct 3, 2022
b8228e9
Rename typeck to hir_analysis (#1475)
mejrs Oct 4, 2022
d3ce60f
Update running tests with the new flags (#1476)
pietroalbini Oct 5, 2022
57a38ad
diagnostic structs: derive on enum (#1477)
davidtwco Oct 5, 2022
0932ad6
fix very minor punctuation typo
Joshument Oct 5, 2022
9a86c04
.gitattributes: Mark minified javascript as binary to filter greps
joshtriplett Oct 7, 2022
509ee50
Use llvm subdomain for compiler-explorer link
dkm Oct 8, 2022
7518c34
Update debugging.md
dkm Oct 8, 2022
e68dfb8
Add missing prerequisite for some Linux distros (#1481)
scarvalhojr Oct 11, 2022
77bfaff
add tool to "enforce" semantic line breaks
tshepang Oct 18, 2022
19d2632
do not overwrite unconditionally
tshepang Oct 18, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Describe drop elaboration (#1240)
  • Loading branch information
ecstatic-morse authored Nov 18, 2021
commit a2fc9635029c04e692474965a6606f8e286d539a
1 change: 1 addition & 0 deletions src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@
- [Opaque Types](./opaque-types-type-alias-impl-trait.md)
- [Pattern and Exhaustiveness Checking](./pat-exhaustive-checking.md)
- [MIR dataflow](./mir/dataflow.md)
- [Drop elaboration](./mir/drop-elaboration.md)
- [The borrow checker](./borrow_check.md)
- [Tracking moves and initialization](./borrow_check/moves_and_initialization.md)
- [Move paths](./borrow_check/moves_and_initialization/move_paths.md)
Expand Down
195 changes: 195 additions & 0 deletions src/mir/drop-elaboration.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,195 @@
# Drop elaboration

<!-- toc -->

## Dynamic drops

According to the [reference][reference-drop]:

> When an initialized variable or temporary goes out of scope, its destructor
> is run, or it is dropped. Assignment also runs the destructor of its
> left-hand operand, if it's initialized. If a variable has been partially
> initialized, only its initialized fields are dropped.

When building the MIR, the `Drop` and `DropAndReplace` terminators represent
places where drops may occur. However, in this phase, the presence of these
terminators does not guarantee that a destructor will run. That's because the
target of a drop may be uninitialized (usually because it has been moved from)
before the terminator is reached. In general, we cannot know at compile-time whether a
variable is initialized.

```rust
let mut y = vec![];

{
let x = vec![1, 2, 3];
if std::process::id() % 2 == 0 {
y = x; // conditionally move `x` into `y`
}
} // `x` goes out of scope here. Should it be dropped?
```

In these cases, we need to keep track of whether a variable is initialized
*dynamically*. The rules are laid out in detail in [RFC 320: Non-zeroing
dynamic drops][RFC 320].

## Drop obligations

From the RFC:

> When a local variable becomes initialized, it establishes a set of "drop
> obligations": a set of structural paths (e.g. a local `a`, or a path to a
> field `b.f.y`) that need to be dropped.
>
> The drop obligations for a local variable x of struct-type `T` are computed
> from analyzing the structure of `T`. If `T` itself implements `Drop`, then `x` is a
> drop obligation. If `T` does not implement `Drop`, then the set of drop
> obligations is the union of the drop obligations of the fields of `T`.

When a structural path is moved from (and thus becomes uninitialized), any drop
obligations for that path or its descendants (`path.f`, `path.f.g.h`, etc.) are
released. Types with `Drop` implementations do not permit moves from individual
fields, so there is no need to track initializedness through them.

When a local variable goes out of scope (`Drop`), or when a structural path is
overwritten via assignment (`DropAndReplace`), we check for any drop
obligations for that variable or path. Unless that obligation has been
released by this point, its associated `Drop` implementation will be called.
For `enum` types, only fields corresponding to the "active" variant need to be
dropped. When processing drop obligations for such types, we first check the
discriminant to determine the active variant. All drop obligations for variants
besides the active one are ignored.

Here are a few interesting types to help illustrate these rules:

```rust
struct NoDrop(u8); // No `Drop` impl. No fields with `Drop` impls.

struct NeedsDrop(Vec<u8>); // No `Drop` impl but has fields with `Drop` impls.

struct ThinVec(*const u8); // Custom `Drop` impl. Individual fields cannot be moved from.

impl Drop for ThinVec {
fn drop(&mut self) { /* ... */ }
}

enum MaybeDrop {
Yes(NeedsDrop),
No(NoDrop),
}
```

## Drop elaboration

One valid model for these rules is to keep a boolean flag (a "drop flag") for
every structural path that is used at any point in the function. This flag is
set when its path is initialized and is cleared when the path is moved from.
When a `Drop` occurs, we check the flags for every obligation associated with
the target of the `Drop` and call the associated `Drop` impl for those that are
still applicable.

This process—transforming the newly built MIR with its imprecise `Drop` and
`DropAndReplace` terminators into one with drop flags—is known as drop
elaboration. When a MIR statement causes a variable to become initialized (or
uninitialized), drop elaboration inserts code that sets (or clears) the drop
flag for that variable. It wraps `Drop` terminators in conditionals that check
the newly inserted drop flags.

Drop elaboration also splits `DropAndReplace` terminators into a `Drop` of the
target and a write of the newly dropped place. This is somewhat unrelated to what
we've discussed above.

Once this is complete, `Drop` terminators in the MIR correspond to a call to
the "drop glue" or "drop shim" for the type of the dropped place. The drop
glue for a type calls the `Drop` impl for that type (if one exists), and then
recursively calls the drop glue for all fields of that type.

## Drop elaboration in `rustc`

The approach described above is more expensive than necessary. One can imagine
a few optimizations:

- Only paths that are the target of a `Drop` (or have the target as a prefix)
need drop flags.
- Some variables are known to initialized (or uninitialized) when they are
dropped. These do not need drop flags.
- If a set of paths are only dropped or moved from via a shared prefix, those
paths can share a single drop flag.

A subset of these are implemented in `rustc`.

In the compiler, drop elaboration is split across several modules. The pass
itself is defined [here][drops-transform], but the [main logic][drops] is
defined elsewhere since it is also used to build [drop shims][drops-shim].

Drop elaboration designates each `Drop` in the newly built MIR as one of four
kinds:

- `Static`, the target is always initialized.
- `Dead`, the target is always **un**initialized.
- `Conditional`, the target is either wholly initialized or wholly
uninitialized. It is not partly initialized.
- `Open`, the target may be partly initialized.

For this, it uses a pair of dataflow analyses, `MaybeInitializedPlaces` and
`MaybeUninitializedPlaces`. If a place is in one but not the other, then the
initializedness of the target is known at compile-time (`Dead` or `Static`).
In this case, drop elaboration does not add a flag for the target. It simply
removes (`Dead`) or preserves (`Static`) the `Drop` terminator.

For `Conditional` drops, we know that the initializedness of the variable as a
whole is the same as the initializedness of its fields. Therefore, once we
generate a drop flag for the target of that drop, it's safe to call the drop
glue for that target.

### `Open` drops

`Open` drops are the most complex, since we need to break down a single `Drop`
terminator into several different ones, one for each field of the target whose
type has drop glue (`Ty::needs_drop`). We cannot call the drop glue for the
target itself because that requires all fields of the target to be initialized.
Remember, variables whose type has a custom `Drop` impl do not allow `Open`
drops because their fields cannot be moved from.

This is accomplished by recursively categorizing each field as `Dead`,
`Static`, `Conditional` or `Open`. Fields whose type does not have drop glue
are automatically `Dead` and need not be considered during the recursion. When
we reach a field whose kind is not `Open`, we handle it as we did above. If the
field is also `Open`, the recursion continues.

It's worth noting how we handle `Open` drops of enums. Inside drop elaboration,
each variant of the enum is treated like a field, with the invariant that only
one of those "variant fields" can be initialized at any given time. In the
general case, we do not know which variant is the active one, so we will have
to call the drop glue for the enum (which checks the discriminant) or check the
discriminant ourselves as part of an elaborated `Open` drop. However, in
certain cases (within a `match` arm, for example) we do know which variant of
an enum is active. This information is encoded in the `MaybeInitializedPlaces`
and `MaybeUninitializedPlaces` dataflow analyses by marking all places
corresponding to inactive variants as uninitialized.

### Cleanup paths

TODO: Discuss drop elaboration and unwinding.

## Aside: drop elaboration and const-eval

In Rust, functions that are eligible for evaluation at compile-time must be
marked explicitly using the `const` keyword. This includes implementations of
the `Drop` trait, which may or may not be `const`. Code that is eligible for
compile-time evaluation may only call `const` functions, so any calls to
non-const `Drop` implementations in such code must be forbidden.

A call to a `Drop` impl is encoded as a `Drop` terminator in the MIR. However,
as we discussed above, a `Drop` terminator in newly built MIR does not
necessarily result in a call to `Drop::drop`. The drop target may be
uninitialized at that point. This means that checking for non-const `Drop`s on
the newly built MIR can result in spurious errors. Instead, we wait until after
drop elaboration runs, which eliminates `Dead` drops (ones where the target is
known to be uninitialized) to run these checks.

[RFC 320]: https://rust-lang.github.io/rfcs/0320-nonzeroing-dynamic-drop.html
[reference-drop]: https://doc.rust-lang.org/reference/destructors.html
[drops]: https://github.com/rust-lang/rust/blob/master/compiler/rustc_mir_dataflow/src/elaborate_drops.rs
[drops-shim]: https://github.com/rust-lang/rust/blob/master/compiler/rustc_mir_transform/src/shim.rs
[drops-transform]: https://github.com/rust-lang/rust/blob/master/compiler/rustc_mir_dataflow/src/elaborate_drops.rs