Skip to content

Commit 05c75ae

Browse files
authored
Merge branch 'master' into master
2 parents d39b953 + 4d43a3b commit 05c75ae

File tree

138 files changed

+4671
-2147
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

138 files changed

+4671
-2147
lines changed

.editorconfig

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ root = true
33
[src/*]
44
end_of_line = lf
55
insert_final_newline = true
6+
max_line_length = 100
67

78
[ci/*.sh]
89
indent_style = space

.github/workflows/ci.yml

+4-3
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,11 @@ jobs:
1616
env:
1717
MDBOOK_VERSION: 0.4.21
1818
MDBOOK_LINKCHECK_VERSION: 0.7.6
19-
MDBOOK_MERMAID_VERSION: 0.11.2
20-
MDBOOK_TOC_VERSION: 0.9.0
19+
MDBOOK_MERMAID_VERSION: 0.12.6
20+
MDBOOK_TOC_VERSION: 0.11.2
2121
DEPLOY_DIR: book/html
2222
BASE_SHA: ${{ github.event.pull_request.base.sha }}
23+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2324
steps:
2425
- uses: actions/checkout@v3
2526
with:
@@ -45,7 +46,7 @@ jobs:
4546
if: github.event_name != 'push'
4647
run: |
4748
shopt -s globstar
48-
MAX_LINE_LENGTH=100 bash ci/check_line_lengths.sh src/**/*.md
49+
MAX_LINE_LENGTH=100 bash ci/lengthcheck.sh src/**/*.md
4950
5051
- name: Install latest nightly Rust toolchain
5152
if: steps.mdbook-cache.outputs.cache-hit != 'true'

CITATION.cff

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
cff-version: 1.2.0
2+
message: If you use this guide, please cite it using these metadata.
3+
title: Rust Compiler Development Guide (rustc-dev-guide)
4+
abstract: A guide to developing the Rust compiler (rustc)
5+
authors:
6+
- name: "The Rust Project Developers"
7+
date-released: "2018-01-16"
8+
license: "MIT OR Apache-2.0"
9+
repository-code: "https://github.com/rust-lang/rustc-dev-guide"

README.md

+7-7
Original file line numberDiff line numberDiff line change
@@ -43,16 +43,16 @@ rustdocs][rustdocs].
4343
To build a local static HTML site, install [`mdbook`](https://github.com/rust-lang/mdBook) with:
4444

4545
```
46-
> cargo install mdbook mdbook-linkcheck mdbook-toc
46+
> cargo install mdbook mdbook-linkcheck mdbook-toc mdbook-mermaid
4747
```
4848

4949
and execute the following command in the root of the repository:
5050

5151
```
52-
> mdbook build
52+
> mdbook build --open
5353
```
5454

55-
The build files are found in the `book` directory.
55+
The build files are found in the `book/html` directory.
5656

5757
### Link Validations
5858

@@ -67,20 +67,20 @@ including the `<!-- toc -->` marker at the place where you want the TOC.
6767
### Pre-commit script
6868

6969
We also test that line lengths are less than 100 columns. To test this locally,
70-
you can run `ci/check_line_lengths.sh`.
70+
you can run `ci/lengthcheck.sh`.
7171

7272
You can also set this to run automatically.
7373

7474
On Linux:
7575

7676
```bash
77-
ln -s ../../ci/check_line_lengths.sh .git/hooks/pre-commit
77+
ln -s ../../ci/lengthcheck.sh .git/hooks/pre-commit
7878
```
7979

8080
On Windows:
8181

8282
```powershell
83-
New-Item -Path .git/hooks/pre-commit -ItemType HardLink -Value <absolute_path/to/check_line_lengths.sh>
83+
New-Item -Path .git/hooks/pre-commit -ItemType HardLink -Value $(Resolve-Path ci/lengthcheck.sh)
8484
```
8585

8686
## How to fix toolstate failures
@@ -118,7 +118,7 @@ git submodule update --remote src/doc/rustc-dev-guide
118118
git add -u
119119
git commit -m "Update rustc-dev-guide"
120120
# Note that you can use -i, which is short for --incremental, in the following command
121-
./x.py test --incremental src/doc/rustc-dev-guide # This is optional and should succeed anyway
121+
./x test --incremental src/doc/rustc-dev-guide # This is optional and should succeed anyway
122122
# Open a PR in rust-lang/rust
123123
```
124124

book.toml

+8-4
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[book]
2-
title = "Guide to Rustc Development"
3-
author = "Rustc developers"
4-
description = "A guide to developing rustc"
2+
title = "Rust Compiler Development Guide"
3+
author = "The Rust Project Developers"
4+
description = "A guide to developing the Rust compiler (rustc)"
55

66
[build]
77
create-missing = false
@@ -18,6 +18,9 @@ git-repository-url = "https://github.com/rust-lang/rustc-dev-guide"
1818
edit-url-template = "https://github.com/rust-lang/rustc-dev-guide/edit/master/{path}"
1919
additional-js = ["mermaid.min.js", "mermaid-init.js"]
2020

21+
[output.html.search]
22+
use-boolean-and = true
23+
2124
[output.html.fold]
2225
enable = true
2326
level = 0
@@ -42,5 +45,6 @@ warning-policy = "error"
4245

4346
[output.html.redirect]
4447
"/compiletest.html" = "tests/compiletest.html"
45-
"/diagnostics/sessiondiagnostic.html" = "diagnostics/diagnostic-structs.html"
48+
"/diagnostics/sessiondiagnostic.html" = "diagnostic-structs.html"
49+
"/diagnostics/diagnostic-codes.html" = "error-codes.html"
4650
"/miri.html" = "const-eval/interpret.html"

ci/date-check/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ fn main() {
170170

171171
for (path, dates) in dates_by_file {
172172
println!(
173-
"- [ ] {}",
173+
"- {}",
174174
path.strip_prefix(&root_dir_path).unwrap_or(&path).display(),
175175
);
176176
for (line, date) in dates {

ci/check_line_lengths.sh ci/lengthcheck.sh

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
#!/usr/bin/env bash
22

3+
# Check files for lines that are too long.
4+
35
if [ "$1" == "--help" ]; then
46
echo 'Usage:' "[MAX_LINE_LENGTH=n] $0 [file ...]"
57
exit 1
@@ -10,8 +12,7 @@ if [ "$MAX_LINE_LENGTH" == "" ]; then
1012
fi
1113

1214
if [ "$1" == "" ]; then
13-
shopt -s globstar
14-
files=( src/**/*.md )
15+
files=( src/*.md src/*/*.md src/*/*/*.md )
1516
else
1617
files=( "$@" )
1718
fi
@@ -22,7 +23,6 @@ echo "Offending files and lines:"
2223
(( bad_lines = 0 ))
2324
(( inside_block = 0 ))
2425
for file in "${files[@]}"; do
25-
echo "$file"
2626
(( line_no = 0 ))
2727
while IFS="" read -r line || [[ -n "$line" ]] ; do
2828
(( line_no++ ))
@@ -34,7 +34,7 @@ for file in "${files[@]}"; do
3434
&& ! [[ "$line" =~ " | "|"-|-"|"://"|"]:"|\[\^[^\ ]+\]: ]] \
3535
&& (( "${#line}" > $MAX_LINE_LENGTH )) ; then
3636
(( bad_lines++ ))
37-
echo -e "\t$line_no : $line"
37+
echo -e "\t$file:$line_no : $line"
3838
fi
3939
done < "$file"
4040
done

ci/linkcheck.sh

+13-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,16 @@
33
set -e
44
set -o pipefail
55

6+
set_github_token() {
7+
jq '.config.output.linkcheck."http-headers"."github\\.com" = ["Authorization: Bearer $GITHUB_TOKEN"]'
8+
}
9+
610
# https://docs.github.com/en/actions/reference/environment-variables
711
if [ "$GITHUB_EVENT_NAME" = "schedule" ] ; then # running in scheduled job
812
FLAGS=""
13+
USE_TOKEN=1
914

1015
echo "Doing full link check."
11-
set -x
1216
elif [ "$GITHUB_EVENT_NAME" = "pull_request" ] ; then # running in PR CI build
1317
if [ -z "$BASE_SHA" ]; then
1418
echo "error: unexpected state: BASE_SHA must be non-empty in CI"
@@ -17,9 +21,9 @@ elif [ "$GITHUB_EVENT_NAME" = "pull_request" ] ; then # running in PR CI build
1721

1822
CHANGED_FILES=$(git diff --name-only $BASE_SHA... | tr '\n' ' ')
1923
FLAGS="--no-cache -f $CHANGED_FILES"
24+
USE_TOKEN=1
2025

2126
echo "Checking files changed since $BASE_SHA: $CHANGED_FILES"
22-
set -x
2327
else # running locally
2428
COMMIT_RANGE=master...
2529
CHANGED_FILES=$(git diff --name-only $COMMIT_RANGE | tr '\n' ' ')
@@ -28,4 +32,10 @@ else # running locally
2832
echo "Checking files changed in $COMMIT_RANGE: $CHANGED_FILES"
2933
fi
3034

31-
exec mdbook-linkcheck $FLAGS
35+
echo "exec mdbook-linkcheck $FLAGS"
36+
if [ "$USE_TOKEN" = 1 ]; then
37+
config=$(set_github_token)
38+
exec mdbook-linkcheck $FLAGS <<<"$config"
39+
else
40+
exec mdbook-linkcheck $FLAGS
41+
fi

examples/README

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
For each example to compile, you will need to first run the following:
2+
3+
rustup component add rustc-dev llvm-tools
4+
5+
To create an executable:
6+
7+
rustc rustc-driver-example.rs
8+
9+
To run an executable:
10+
11+
rustup run nightly ./rustc-driver-example

examples/rustc-driver-example.rs

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
#![feature(rustc_private)]
22

3-
// NOTE: For the example to compile, you will need to first run the following:
4-
// rustup component add rustc-dev llvm-tools-preview
5-
6-
// version: 1.62.0-nightly (7c4b47696 2022-04-30)
7-
3+
extern crate rustc_driver;
84
extern crate rustc_error_codes;
95
extern crate rustc_errors;
106
extern crate rustc_hash;
@@ -46,11 +42,10 @@ fn main() {
4642
"#
4743
.into(),
4844
},
49-
input_path: None, // Option<PathBuf>
5045
output_dir: None, // Option<PathBuf>
5146
output_file: None, // Option<PathBuf>
5247
file_loader: None, // Option<Box<dyn FileLoader + Send + Sync>>
53-
diagnostic_output: rustc_session::DiagnosticOutput::Default,
48+
locale_resources: rustc_driver::DEFAULT_LOCALE_RESOURCES,
5449
lint_caps: FxHashMap::default(), // FxHashMap<lint::LintId, lint::Level>
5550
// This is a callback from the driver that is called when [`ParseSess`] is created.
5651
parse_sess_created: None, //Option<Box<dyn FnOnce(&mut ParseSess) + Send>>
@@ -68,21 +63,23 @@ fn main() {
6863
// Registry of diagnostics codes.
6964
registry: registry::Registry::new(&rustc_error_codes::DIAGNOSTICS),
7065
make_codegen_backend: None,
66+
expanded_args: Vec::new(),
67+
ice_file: None,
7168
};
7269
rustc_interface::run_compiler(config, |compiler| {
7370
compiler.enter(|queries| {
7471
// Parse the program and print the syntax tree.
75-
let parse = queries.parse().unwrap().take();
72+
let parse = queries.parse().unwrap().get_mut().clone();
7673
println!("{parse:?}");
7774
// Analyze the program and inspect the types of definitions.
78-
queries.global_ctxt().unwrap().take().enter(|tcx| {
75+
queries.global_ctxt().unwrap().enter(|tcx| {
7976
for id in tcx.hir().items() {
8077
let hir = tcx.hir();
8178
let item = hir.item(id);
8279
match item.kind {
8380
rustc_hir::ItemKind::Static(_, _, _) | rustc_hir::ItemKind::Fn(_, _, _) => {
8481
let name = item.ident;
85-
let ty = tcx.type_of(hir.local_def_id(item.hir_id()));
82+
let ty = tcx.type_of(item.hir_id().owner.def_id);
8683
println!("{name:?}:\t{ty:?}")
8784
}
8885
_ => (),

examples/rustc-driver-getting-diagnostics.rs

+5-11
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
#![feature(rustc_private)]
22

3-
// NOTE: For the example to compile, you will need to first run the following:
4-
// rustup component add rustc-dev llvm-tools-preview
5-
6-
// version: 1.62.0-nightly (7c4b47696 2022-04-30)
7-
3+
extern crate rustc_driver;
84
extern crate rustc_error_codes;
95
extern crate rustc_errors;
106
extern crate rustc_hash;
@@ -65,26 +61,24 @@ fn main() {
6561
"
6662
.into(),
6763
},
68-
// Redirect the diagnostic output of the compiler to a buffer.
69-
diagnostic_output: rustc_session::DiagnosticOutput::Raw(Box::from(DiagnosticSink(
70-
buffer.clone(),
71-
))),
7264
crate_cfg: rustc_hash::FxHashSet::default(),
7365
crate_check_cfg: CheckCfg::default(),
74-
input_path: None,
7566
output_dir: None,
7667
output_file: None,
7768
file_loader: None,
69+
locale_resources: rustc_driver::DEFAULT_LOCALE_RESOURCES,
7870
lint_caps: rustc_hash::FxHashMap::default(),
7971
parse_sess_created: None,
8072
register_lints: None,
8173
override_queries: None,
8274
registry: registry::Registry::new(&rustc_error_codes::DIAGNOSTICS),
8375
make_codegen_backend: None,
76+
expanded_args: Vec::new(),
77+
ice_file: None,
8478
};
8579
rustc_interface::run_compiler(config, |compiler| {
8680
compiler.enter(|queries| {
87-
queries.global_ctxt().unwrap().take().enter(|tcx| {
81+
queries.global_ctxt().unwrap().enter(|tcx| {
8882
// Run the analysis phase on the local crate to trigger the type error.
8983
let _ = tcx.analysis(());
9084
});

examples/rustc-driver-interacting-with-the-ast.rs

+7-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
#![feature(rustc_private)]
22

3-
// NOTE: For the example to compile, you will need to first run the following:
4-
// rustup component add rustc-dev llvm-tools-preview
5-
6-
// version: 1.62.0-nightly (7c4b47696 2022-04-30)
7-
83
extern crate rustc_ast_pretty;
4+
extern crate rustc_driver;
95
extern crate rustc_error_codes;
106
extern crate rustc_errors;
117
extern crate rustc_hash;
@@ -43,30 +39,30 @@ fn main() {
4339
"#
4440
.to_string(),
4541
},
46-
diagnostic_output: rustc_session::DiagnosticOutput::Default,
4742
crate_cfg: rustc_hash::FxHashSet::default(),
4843
crate_check_cfg: CheckCfg::default(),
49-
input_path: None,
5044
output_dir: None,
5145
output_file: None,
5246
file_loader: None,
47+
locale_resources: rustc_driver::DEFAULT_LOCALE_RESOURCES,
5348
lint_caps: rustc_hash::FxHashMap::default(),
5449
parse_sess_created: None,
5550
register_lints: None,
5651
override_queries: None,
5752
make_codegen_backend: None,
5853
registry: registry::Registry::new(&rustc_error_codes::DIAGNOSTICS),
54+
expanded_args: Vec::new(),
55+
ice_file: None,
5956
};
6057
rustc_interface::run_compiler(config, |compiler| {
6158
compiler.enter(|queries| {
6259
// TODO: add this to -Z unpretty
63-
let ast_krate = queries.parse().unwrap().take();
60+
let ast_krate = queries.parse().unwrap().get_mut().clone();
6461
for item in ast_krate.items {
6562
println!("{}", item_to_string(&item));
6663
}
67-
6864
// Analyze the crate and inspect the types under the cursor.
69-
queries.global_ctxt().unwrap().take().enter(|tcx| {
65+
queries.global_ctxt().unwrap().enter(|tcx| {
7066
// Every compilation contains a single crate.
7167
let hir_krate = tcx.hir();
7268
// Iterate over the top-level items in the crate, looking for the main function.
@@ -79,7 +75,7 @@ fn main() {
7975
if let rustc_hir::StmtKind::Local(local) = block.stmts[0].kind {
8076
if let Some(expr) = local.init {
8177
let hir_id = expr.hir_id; // hir_id identifies the string "Hello, world!"
82-
let def_id = tcx.hir().local_def_id(item.hir_id()); // def_id identifies the main function
78+
let def_id = item.hir_id().owner.def_id; // def_id identifies the main function
8379
let ty = tcx.typeck(def_id).node_type(hir_id);
8480
println!("{expr:#?}: {ty:?}");
8581
}

0 commit comments

Comments
 (0)