]> git.proxmox.com Git - rustc.git/blame - CONTRIBUTING.md
New upstream version 1.43.0+dfsg1
[rustc.git] / CONTRIBUTING.md
CommitLineData
85aaf69f 1# Contributing to Rust
ea8adc8c 2[contributing-to-rust]: #contributing-to-rust
1a4d82fc 3
85aaf69f
SL
4Thank you for your interest in contributing to Rust! There are many ways to
5contribute, and we appreciate all of them. This document is a bit long, so here's
6links to the major sections:
1a4d82fc 7
85aaf69f
SL
8* [Feature Requests](#feature-requests)
9* [Bug Reports](#bug-reports)
7453a54e 10* [The Build System](#the-build-system)
85aaf69f
SL
11* [Pull Requests](#pull-requests)
12* [Writing Documentation](#writing-documentation)
13* [Issue Triage](#issue-triage)
14* [Out-of-tree Contributions](#out-of-tree-contributions)
e9174d1e 15* [Helpful Links and Information](#helpful-links-and-information)
1a4d82fc 16
85aaf69f 17If you have questions, please make a post on [internals.rust-lang.org][internals] or
e74abb32 18hop on the [Rust Discord server][rust-discord] or [Rust Zulip server][rust-zulip].
1a4d82fc 19
c34b1796 20As a reminder, all contributors are expected to follow our [Code of Conduct][coc].
1a4d82fc 21
9fa01778
XL
22The [rustc-guide] is your friend! It describes how the compiler works and how
23to contribute to it in more detail than this document.
24
25If this is your first time contributing, the [walkthrough] chapter of the guide
26can give you a good example of how a typical contribution would go.
27
e9174d1e 28[internals]: https://internals.rust-lang.org
532ac7d7
XL
29[rust-discord]: http://discord.gg/rust-lang
30[rust-zulip]: https://rust-lang.zulipchat.com
e9174d1e 31[coc]: https://www.rust-lang.org/conduct.html
532ac7d7 32[rustc-guide]: https://rust-lang.github.io/rustc-guide/
9fa01778 33[walkthrough]: https://rust-lang.github.io/rustc-guide/walkthrough.html
1a4d82fc 34
85aaf69f 35## Feature Requests
ea8adc8c 36[feature-requests]: #feature-requests
1a4d82fc 37
0531ce1d 38To request a change to the way the Rust language works, please head over
532ac7d7 39to the [RFCs repository](https://github.com/rust-lang/rfcs) and view the
0531ce1d
XL
40[README](https://github.com/rust-lang/rfcs/blob/master/README.md)
41for instructions.
1a4d82fc 42
85aaf69f 43## Bug Reports
ea8adc8c 44[bug-reports]: #bug-reports
1a4d82fc 45
85aaf69f
SL
46While bugs are unfortunate, they're a reality in software. We can't fix what we
47don't know about, so please report liberally. If you're not sure if something
48is a bug or not, feel free to file a bug anyway.
1a4d82fc 49
92a42be0 50**If you believe reporting your bug publicly represents a security risk to Rust users,
0731742a 51please follow our [instructions for reporting security vulnerabilities](https://www.rust-lang.org/policies/security)**.
92a42be0 52
74b04a01
XL
53If you're using the nightly channel, please check if the bug exists in the
54latest toolchain before filing your bug. It might be fixed already.
55
85aaf69f
SL
56If you have the chance, before reporting a bug, please [search existing
57issues](https://github.com/rust-lang/rust/search?q=&type=Issues&utf8=%E2%9C%93),
58as it's possible that someone else has already reported your error. This doesn't
59always work, and sometimes it's hard to know what to search for, so consider this
60extra credit. We won't mind if you accidentally file a duplicate report.
1a4d82fc 61
83c7162d 62Similarly, to help others who encountered the bug find your issue,
94b46f34 63consider filing an issue with a descriptive title, which contains information that might be unique to it.
83c7162d
XL
64This can be the language or compiler feature used, the conditions that trigger the bug,
65or part of the error message if there is any.
66An example could be: **"impossible case reached" on lifetime inference for impl Trait in return position**.
67
85aaf69f
SL
68Opening an issue is as easy as following [this
69link](https://github.com/rust-lang/rust/issues/new) and filling out the fields.
70Here's a template that you can use to file a bug, though it's not necessary to
71use it exactly:
1a4d82fc 72
85aaf69f
SL
73 <short summary of the bug>
74
75 I tried this code:
76
77 <code sample that causes the bug>
78
79 I expected to see this happen: <explanation>
80
81 Instead, this happened: <explanation>
82
83 ## Meta
84
85 `rustc --version --verbose`:
86
87 Backtrace:
88
89All three components are important: what you did, what you expected, what
90happened instead. Please include the output of `rustc --version --verbose`,
91which includes important information about what platform you're on, what
92version of Rust you're using, etc.
93
94Sometimes, a backtrace is helpful, and so including that is nice. To get
54a0048b
SL
95a backtrace, set the `RUST_BACKTRACE` environment variable to a value
96other than `0`. The easiest way
85aaf69f
SL
97to do this is to invoke `rustc` like this:
98
99```bash
100$ RUST_BACKTRACE=1 rustc ...
1a4d82fc
JJ
101```
102
7453a54e 103## The Build System
83c7162d 104
9fa01778
XL
105For info on how to configure and build the compiler, please see [this
106chapter][rustcguidebuild] of the rustc-guide. This chapter contains info for
107contributions to the compiler and the standard library. It also lists some
108really useful commands to the build system (`./x.py`), which could save you a
109lot of time.
476ff2be 110
60c5eb7d 111[rustcguidebuild]: https://rust-lang.github.io/rustc-guide/building/how-to-build-and-run.html
ff7c6d11 112
85aaf69f 113## Pull Requests
ea8adc8c 114[pull-requests]: #pull-requests
1a4d82fc 115
85aaf69f 116Pull requests are the primary mechanism we use to change Rust. GitHub itself
2c00a5a8 117has some [great documentation][about-pull-requests] on using the Pull Request feature.
3b2f2976
XL
118We use the "fork and pull" model [described here][development-models], where
119contributors push changes to their personal fork and create pull requests to
120bring those changes into the source repository.
1a4d82fc 121
2c00a5a8 122[about-pull-requests]: https://help.github.com/articles/about-pull-requests/
3b2f2976 123[development-models]: https://help.github.com/articles/about-collaborative-development-models/
85aaf69f
SL
124
125Please make pull requests against the `master` branch.
126
532ac7d7
XL
127Rust follows a no merge policy, meaning, when you encounter merge
128conflicts you are expected to always rebase instead of merge.
129E.g. always use rebase when bringing the latest changes from
130the master branch to your feature branch.
131Also, please make sure that fixup commits are squashed into other related
132commits with meaningful commit messages.
133
e74abb32
XL
134GitHub allows [closing issues using keywords][closing-keywords]. This feature
135should be used to keep the issue tracker tidy. However, it is generally preferred
136to put the "closes #123" text in the PR description rather than the issue commit;
137particularly during rebasing, citing the issue number in the commit can "spam"
138the issue in question.
139
140[closing-keywords]: https://help.github.com/en/articles/closing-issues-using-keywords
141
9e0c209e
SL
142Please make sure your pull request is in compliance with Rust's style
143guidelines by running
144
476ff2be 145 $ python x.py test src/tools/tidy
9e0c209e
SL
146
147Make this check before every pull request (and every new commit in a pull
9fa01778 148request); you can add [git hooks](https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks)
9e0c209e
SL
149before every push to make sure you never forget to make this check.
150
85aaf69f 151All pull requests are reviewed by another person. We have a bot,
532ac7d7 152[@rust-highfive][rust-highfive], that will automatically assign a random person to review your
62682a34 153request.
85aaf69f
SL
154
155If you want to request that a specific person reviews your pull request,
60c5eb7d 156you can add an `r?` to the pull request description. For example, [Steve][steveklabnik] usually reviews
85aaf69f
SL
157documentation changes. So if you were to make a documentation change, add
158
159 r? @steveklabnik
160
60c5eb7d
XL
161to the end of the pull request description, and [@rust-highfive][rust-highfive] will assign
162[@steveklabnik][steveklabnik] instead of a random person. This is entirely optional.
85aaf69f
SL
163
164After someone has reviewed your pull request, they will leave an annotation
165on the pull request with an `r+`. It will look something like this:
166
532ac7d7 167 @bors r+
85aaf69f 168
532ac7d7
XL
169This tells [@bors][bors], our lovable integration bot, that your pull request has
170been approved. The PR then enters the [merge queue][merge-queue], where [@bors][bors]
85aaf69f 171will run all the tests on every platform we support. If it all works out,
532ac7d7
XL
172[@bors][bors] will merge your code into `master` and close the pull request.
173
174Depending on the scale of the change, you may see a slightly different form of `r+`:
175
176 @bors r+ rollup
177
178The additional `rollup` tells [@bors][bors] that this change is eligible for to be
179"rolled up". Changes that are rolled up are tested and merged at the same time, to
180speed the process up. Typically only small changes that are expected not to conflict
181with one another are rolled up.
85aaf69f 182
532ac7d7
XL
183[rust-highfive]: https://github.com/rust-highfive
184[steveklabnik]: https://github.com/steveklabnik
185[bors]: https://github.com/bors
3b2f2976 186[merge-queue]: https://buildbot2.rust-lang.org/homu/queue/rust
85aaf69f 187
c1a9b12d 188Speaking of tests, Rust has a comprehensive test suite. More information about
b7449926 189it can be found [here][rctd].
c1a9b12d 190
ea8adc8c 191### External Dependencies
ea8adc8c
XL
192
193Currently building Rust will also build the following external projects:
194
9fa01778
XL
195* [clippy](https://github.com/rust-lang/rust-clippy)
196* [miri](https://github.com/rust-lang/miri)
197* [rustfmt](https://github.com/rust-lang/rustfmt)
198* [rls](https://github.com/rust-lang/rls/)
ea8adc8c 199
ff7c6d11
XL
200We allow breakage of these tools in the nightly channel. Maintainers of these
201projects will be notified of the breakages and should fix them as soon as
202possible.
ea8adc8c 203
ff7c6d11 204After the external is fixed, one could add the changes with
ea8adc8c 205
ff7c6d11 206```sh
ea8adc8c
XL
207git add path/to/submodule
208```
209
210outside the submodule.
211
ff7c6d11 212In order to prepare your tool-fixing PR, you can run the build locally by doing
abe05a73
XL
213`./x.py build src/tools/TOOL`. If you will be editing the sources
214there, you may wish to set `submodules = false` in the `config.toml`
215to prevent `x.py` from resetting to the original branch.
216
ff7c6d11
XL
217Breakage is not allowed in the beta and stable channels, and must be addressed
218before the PR is merged.
219
abe05a73 220#### Breaking Tools Built With The Compiler
abe05a73
XL
221
222Rust's build system builds a number of tools that make use of the
532ac7d7 223internals of the compiler. This includes
9fa01778
XL
224[Clippy](https://github.com/rust-lang/rust-clippy),
225[RLS](https://github.com/rust-lang/rls) and
226[rustfmt](https://github.com/rust-lang/rustfmt). If these tools
abe05a73
XL
227break because of your changes, you may run into a sort of "chicken and egg"
228problem. These tools rely on the latest compiler to be built so you can't update
229them to reflect your changes to the compiler until those changes are merged into
230the compiler. At the same time, you can't get your changes merged into the compiler
231because the rust-lang/rust build won't pass until those tools build and pass their
232tests.
233
234That means that, in the default state, you can't update the compiler without first
235fixing rustfmt, rls and the other tools that the compiler builds.
236
ff7c6d11
XL
237Luckily, a feature was [added to Rust's build](https://github.com/rust-lang/rust/issues/45861)
238to make all of this easy to handle. The idea is that we allow these tools to be "broken",
abe05a73
XL
239so that the rust-lang/rust build passes without trying to build them, then land the change
240in the compiler, wait for a nightly, and go update the tools that you broke. Once you're done
ff7c6d11
XL
241and the tools are working again, you go back in the compiler and update the tools
242so they can be distributed again.
abe05a73
XL
243
244This should avoid a bunch of synchronization dances and is also much easier on contributors as
245there's no need to block on rls/rustfmt/other tools changes going upstream.
246
247Here are those same steps in detail:
248
2491. (optional) First, if it doesn't exist already, create a `config.toml` by copying
250 `config.toml.example` in the root directory of the Rust repository.
251 Set `submodules = false` in the `[build]` section. This will prevent `x.py`
252 from resetting to the original branch after you make your changes. If you
416331ca 253 need to [update any submodules to their latest versions](#updating-submodules),
abe05a73
XL
254 see the section of this file about that for more information.
2552. (optional) Run `./x.py test src/tools/rustfmt` (substituting the submodule
256 that broke for `rustfmt`). Fix any errors in the submodule (and possibly others).
2573. (optional) Make commits for your changes and send them to upstream repositories as a PR.
2584. (optional) Maintainers of these submodules will **not** merge the PR. The PR can't be
259 merged because CI will be broken. You'll want to write a message on the PR referencing
260 your change, and how the PR should be merged once your change makes it into a nightly.
ff7c6d11
XL
2615. Wait for your PR to merge.
2626. Wait for a nightly
2637. (optional) Help land your PR on the upstream repository now that your changes are in nightly.
2648. (optional) Send a PR to rust-lang/rust updating the submodule.
abe05a73
XL
265
266#### Updating submodules
abe05a73
XL
267
268These instructions are specific to updating `rustfmt`, however they may apply
269to the other submodules as well. Please help by improving these instructions
ff7c6d11 270if you find any discrepancies or special cases that need to be addressed.
abe05a73
XL
271
272To update the `rustfmt` submodule, start by running the appropriate
273[`git submodule` command](https://git-scm.com/book/en/v2/Git-Tools-Submodules).
274For example, to update to the latest commit on the remote master branch,
275you may want to run:
276```
277git submodule update --remote src/tools/rustfmt
278```
279If you run `./x.py build` now, and you are lucky, it may just work. If you see
280an error message about patches that did not resolve to any crates, you will need
281to complete a few more steps which are outlined with their rationale below.
282
283*(This error may change in the future to include more information.)*
284```
9fa01778 285error: failed to resolve patches for `https://github.com/rust-lang/rustfmt`
abe05a73
XL
286
287Caused by:
9fa01778 288 patch for `rustfmt-nightly` in `https://github.com/rust-lang/rustfmt` did not resolve to any crates
abe05a73
XL
289failed to run: ~/rust/build/x86_64-unknown-linux-gnu/stage0/bin/cargo build --manifest-path ~/rust/src/bootstrap/Cargo.toml
290```
291
292If you haven't used the `[patch]`
293section of `Cargo.toml` before, there is [some relevant documentation about it
294in the cargo docs](http://doc.crates.io/manifest.html#the-patch-section). In
ff7c6d11 295addition to that, you should read the
abe05a73
XL
296[Overriding dependencies](http://doc.crates.io/specifying-dependencies.html#overriding-dependencies)
297section of the documentation as well.
298
299Specifically, the following [section in Overriding dependencies](http://doc.crates.io/specifying-dependencies.html#testing-a-bugfix) reveals what the problem is:
300
301> Next up we need to ensure that our lock file is updated to use this new version of uuid so our project uses the locally checked out copy instead of one from crates.io. The way [patch] works is that it'll load the dependency at ../path/to/uuid and then whenever crates.io is queried for versions of uuid it'll also return the local version.
ff7c6d11 302>
abe05a73
XL
303> This means that the version number of the local checkout is significant and will affect whether the patch is used. Our manifest declared uuid = "1.0" which means we'll only resolve to >= 1.0.0, < 2.0.0, and Cargo's greedy resolution algorithm also means that we'll resolve to the maximum version within that range. Typically this doesn't matter as the version of the git repository will already be greater or match the maximum version published on crates.io, but it's important to keep this in mind!
304
305This says that when we updated the submodule, the version number in our
306`src/tools/rustfmt/Cargo.toml` changed. The new version is different from
307the version in `Cargo.lock`, so the build can no longer continue.
308
309To resolve this, we need to update `Cargo.lock`. Luckily, cargo provides a
310command to do this easily.
311
abe05a73 312```
abe05a73
XL
313$ cargo update -p rustfmt-nightly
314```
315
a1dfa0c6 316This should change the version listed in `Cargo.lock` to the new version you updated
abe05a73 317the submodule to. Running `./x.py build` should work now.
ea8adc8c 318
85aaf69f
SL
319## Writing Documentation
320
321Documentation improvements are very welcome. The source of `doc.rust-lang.org`
322is located in `src/doc` in the tree, and standard API documentation is generated
532ac7d7
XL
323from the source code itself. Documentation pull requests function in the same way
324as other pull requests.
85aaf69f 325
cc61c64b 326To find documentation-related issues, sort by the [T-doc label][tdoc].
62682a34 327
cc61c64b
XL
328[tdoc]: https://github.com/rust-lang/rust/issues?q=is%3Aopen%20is%3Aissue%20label%3AT-doc
329
330You can find documentation style guidelines in [RFC 1574][rfc1574].
331
332[rfc1574]: https://github.com/rust-lang/rfcs/blob/master/text/1574-more-api-documentation-conventions.md#appendix-a-full-conventions-text
62682a34 333
8bb4bdeb 334In many cases, you don't need a full `./x.py doc`. You can use `rustdoc` directly
b039eaaf
SL
335to check small fixes. For example, `rustdoc src/doc/reference.md` will render
336reference to `doc/reference.html`. The CSS might be messed up, but you can
9e0c209e 337verify that the HTML is right.
b039eaaf 338
9fa01778
XL
339Additionally, contributions to the [rustc-guide] are always welcome. Contributions
340can be made directly at [the
341rust-lang/rustc-guide](https://github.com/rust-lang/rustc-guide) repo. The issue
342tracker in that repo is also a great way to find things that need doing. There
343are issues for beginners and advanced compiler devs alike!
344
85aaf69f
SL
345## Issue Triage
346
347Sometimes, an issue will stay open, even though the bug has been fixed. And
348sometimes, the original bug may go stale because something has changed in the
349meantime.
350
351It can be helpful to go through older bug reports and make sure that they are
352still valid. Load up an older issue, double check that it's still true, and
62682a34
SL
353leave a comment letting us know if it is or is not. The [least recently
354updated sort][lru] is good for finding issues like this.
355
356Contributors with sufficient permissions on the Rust repo can help by adding
357labels to triage issues:
358
359* Yellow, **A**-prefixed labels state which **area** of the project an issue
b039eaaf 360 relates to.
62682a34 361
9cc50fc6 362* Magenta, **B**-prefixed labels identify bugs which are **blockers**.
62682a34 363
ea8adc8c
XL
364* Dark blue, **beta-** labels track changes which need to be backported into
365 the beta branches.
366
367* Light purple, **C**-prefixed labels represent the **category** of an issue.
368
62682a34
SL
369* Green, **E**-prefixed labels explain the level of **experience** necessary
370 to fix the issue.
371
ea8adc8c 372* The dark blue **final-comment-period** label marks bugs that are using the
dfeec247 373 RFC signoff functionality of [rfcbot] and are currently in the final
ea8adc8c
XL
374 comment period.
375
62682a34
SL
376* Red, **I**-prefixed labels indicate the **importance** of the issue. The
377 [I-nominated][inom] label indicates that an issue has been nominated for
b039eaaf 378 prioritizing at the next triage meeting.
62682a34 379
ea8adc8c
XL
380* The purple **metabug** label marks lists of bugs collected by other
381 categories.
382
383* Purple gray, **O**-prefixed labels are the **operating system** or platform
384 that this issue is specific to.
385
62682a34
SL
386* Orange, **P**-prefixed labels indicate a bug's **priority**. These labels
387 are only assigned during triage meetings, and replace the [I-nominated][inom]
b039eaaf 388 label.
62682a34 389
ea8adc8c 390* The gray **proposed-final-comment-period** label marks bugs that are using
dfeec247 391 the RFC signoff functionality of [rfcbot] and are currently awaiting
ea8adc8c 392 signoff of all team members in order to enter the final comment period.
62682a34 393
ea8adc8c
XL
394* Pink, **regression**-prefixed labels track regressions from stable to the
395 release channels.
b039eaaf 396
ea8adc8c
XL
397* The light orange **relnotes** label marks issues that should be documented in
398 the release notes of the next release.
399
400* Gray, **S**-prefixed labels are used for tracking the **status** of pull
401 requests.
402
403* Blue, **T**-prefixed bugs denote which **team** the issue belongs to.
62682a34 404
b039eaaf 405If you're looking for somewhere to start, check out the [E-easy][eeasy] tag.
85aaf69f 406
62682a34
SL
407[inom]: https://github.com/rust-lang/rust/issues?q=is%3Aopen+is%3Aissue+label%3AI-nominated
408[eeasy]: https://github.com/rust-lang/rust/issues?q=is%3Aopen+is%3Aissue+label%3AE-easy
85aaf69f 409[lru]: https://github.com/rust-lang/rust/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-asc
0531ce1d 410[rfcbot]: https://github.com/anp/rfcbot-rs/
85aaf69f
SL
411
412## Out-of-tree Contributions
413
414There are a number of other ways to contribute to Rust that don't deal with
415this repository.
416
e74abb32 417Answer questions in the _Get Help!_ channels from the [Rust Discord server][rust-discord], on [users.rust-lang.org][users],
85aaf69f
SL
418or on [StackOverflow][so].
419
420Participate in the [RFC process](https://github.com/rust-lang/rfcs).
421
422Find a [requested community library][community-library], build it, and publish
423it to [Crates.io](http://crates.io). Easier said than done, but very, very
424valuable!
1a4d82fc 425
e74abb32 426[rust-discord]: https://discord.gg/rust-lang
e9174d1e 427[users]: https://users.rust-lang.org/
85aaf69f
SL
428[so]: http://stackoverflow.com/questions/tagged/rust
429[community-library]: https://github.com/rust-lang/rfcs/labels/A-community-library
e9174d1e
SL
430
431## Helpful Links and Information
432
433For people new to Rust, and just starting to contribute, or even for
434more seasoned developers, some useful places to look for information
435are:
436
9fa01778 437* The [rustc guide] contains information about how various parts of the compiler work and how to contribute to the compiler
ea8adc8c 438* [Rust Forge][rustforge] contains additional documentation, including write-ups of how to achieve common tasks
e9174d1e
SL
439* The [Rust Internals forum][rif], a place to ask questions and
440 discuss Rust's internals
441* The [generated documentation for rust's compiler][gdfrustc]
b039eaaf 442* The [rust reference][rr], even though it doesn't specifically talk about Rust's internals, it's a great resource nonetheless
e9174d1e
SL
443* Although out of date, [Tom Lee's great blog article][tlgba] is very helpful
444* [rustaceans.org][ro] is helpful, but mostly dedicated to IRC
445* The [Rust Compiler Testing Docs][rctd]
532ac7d7
XL
446* For [@bors][bors], [this cheat sheet][cheatsheet] is helpful
447(though you'll need to replace `@homu` with `@bors` in any commands)
b039eaaf 448* **Google!** ([search only in Rust Documentation][gsearchdocs] to find types, traits, etc. quickly)
e9174d1e
SL
449* Don't be afraid to ask! The Rust community is friendly and helpful.
450
a1dfa0c6 451[rustc guide]: https://rust-lang.github.io/rustc-guide/about-this-guide.html
0bf4aa26 452[gdfrustc]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc/
9cc50fc6 453[gsearchdocs]: https://www.google.com/search?q=site:doc.rust-lang.org+your+query+here
e9174d1e
SL
454[rif]: http://internals.rust-lang.org
455[rr]: https://doc.rust-lang.org/book/README.html
ea8adc8c 456[rustforge]: https://forge.rust-lang.org/
a7813a04 457[tlgba]: http://tomlee.co/2014/04/a-more-detailed-tour-of-the-rust-compiler/
e9174d1e 458[ro]: http://www.rustaceans.org/
a1dfa0c6 459[rctd]: https://rust-lang.github.io/rustc-guide/tests/intro.html
3b2f2976 460[cheatsheet]: https://buildbot2.rust-lang.org/homu/