Skip to content

Commit 08ec2a0

Browse files
committed
Auto merge of #150068 - JonathanBrouwer:rollup-45j7puz, r=JonathanBrouwer
Rollup of 11 pull requests Successful merges: - rust-lang/rust#147939 (Make `const BorrowMut` require `const Borrow` and make `const Fn` require `const FnMut`) - rust-lang/rust#149734 (Mirror GCC 9.5.0) - rust-lang/rust#149767 (Tidying up tests/ui/issues 33 tests [4/N]) - rust-lang/rust#149804 (chore: fix some minor issues in the comments) - rust-lang/rust#149967 (custom `VaList` layout for Hexagon) - rust-lang/rust#150025 (dont create unnecessary `DefId`s under mgca) - rust-lang/rust#150032 (Use annotate-snippet as default emitter on stable) - rust-lang/rust#150033 (Add try_as_dyn and try_as_dyn_mut) - rust-lang/rust#150042 (rustc-dev-guide subtree update) - rust-lang/rust#150063 (Remove deny of manual-let-else) - rust-lang/rust#150064 (std: io: error: Add comment for UEFI unpacked repr use) Failed merges: - rust-lang/rust#150044 (Avoid unhelpful suggestion when crate name is invalid) r? `@ghost` `@rustbot` modify labels: rollup
2 parents e675d6d + 946c18e commit 08ec2a0

37 files changed

+2198
-277
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
pull_request:
88
schedule:
99
# Run multiple times a day as the successfull cached links are not checked every time.
10-
- cron: '0 */8 * * *'
10+
- cron: "0 */8 * * *"
1111

1212
jobs:
1313
ci:
@@ -83,16 +83,6 @@ jobs:
8383
git commit -m "Deploy ${GITHUB_SHA} to gh-pages"
8484
git push --quiet -f "https://x-token:${{ secrets.GITHUB_TOKEN }}@github.com/${GITHUB_REPOSITORY}" HEAD:gh-pages
8585
86-
- name: Cache sembr build
87-
uses: actions/cache@v4
88-
with:
89-
path: |
90-
~/.cargo/registry/index/
91-
~/.cargo/registry/cache/
92-
~/.cargo/git/db/
93-
ci/sembr/target/
94-
key: sembr-${{ hashFiles('ci/sembr/Cargo.lock') }}
95-
9686
- name: Check if files comply with semantic line breaks
9787
continue-on-error: true
9888
run: |

README.md

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
[![CI](https://github.com/rust-lang/rustc-dev-guide/actions/workflows/ci.yml/badge.svg)](https://github.com/rust-lang/rustc-dev-guide/actions/workflows/ci.yml)
22

3-
4-
This is a collaborative effort to build a guide that explains how rustc
5-
works. The aim of the guide is to help new contributors get oriented
6-
to rustc, as well as to help more experienced folks in figuring out
3+
This is a collaborative effort to build a guide that explains how rustc works.
4+
The aim of the guide is to help new contributors get oriented to rustc,
5+
as well as to help more experienced folks in figuring out
76
some new part of the compiler that they haven't worked on before.
87

9-
[You can read the latest version of the guide here.](https://rustc-dev-guide.rust-lang.org/)
8+
You may also find the [rustc API docs] useful.
109

11-
You may also find the rustdocs [for the compiler itself][rustdocs] useful.
1210
Note that these are not intended as a guide; it's recommended that you search
1311
for the docs you're looking for instead of reading them top to bottom.
1412

15-
[rustdocs]: https://doc.rust-lang.org/nightly/nightly-rustc
16-
1713
For documentation on developing the standard library, see
1814
[`std-dev-guide`](https://std-dev-guide.rust-lang.org/).
1915

2016
### Contributing to the guide
2117

2218
The guide is useful today, but it has a lot of work still to go.
2319

24-
If you'd like to help improve the guide, we'd love to have you! You can find
25-
plenty of issues on the [issue
26-
tracker](https://github.com/rust-lang/rustc-dev-guide/issues). Just post a
27-
comment on the issue you would like to work on to make sure that we don't
28-
accidentally duplicate work. If you think something is missing, please open an
29-
issue about it!
20+
If you'd like to help improve the guide, we'd love to have you!
21+
You can find plenty of issues on the [issue
22+
tracker](https://github.com/rust-lang/rustc-dev-guide/issues).
23+
Just post a comment on the issue you would like to work on to make sure that we don't
24+
accidentally duplicate work.
25+
If you think something is missing, please open an issue about it!
3026

3127
**In general, if you don't know how the compiler works, that is not a
3228
problem!** In that case, what we will do is to schedule a bit of time
3329
for you to talk with someone who **does** know the code, or who wants
34-
to pair with you and figure it out. Then you can work on writing up
35-
what you learned.
30+
to pair with you and figure it out.
31+
Then you can work on writing up what you learned.
3632

3733
In general, when writing about a particular part of the compiler's code, we
38-
recommend that you link to the relevant parts of the [rustc
39-
rustdocs][rustdocs].
34+
recommend that you link to the relevant parts of the [rustc API docs].
35+
36+
The guide has a much lower bar for what it takes for a PR to be merged.
37+
Check out the forge documentation for [our policy][forge_policy].
38+
39+
[forge_policy]: https://forge.rust-lang.org/rustc-dev-guide/index.html#review-policy
4040

4141
### Build Instructions
4242

@@ -56,9 +56,9 @@ The build files are found in the `book/html` directory.
5656

5757
### Link Validations
5858

59-
We use `mdbook-linkcheck2` to validate URLs included in our documentation. Link
60-
checking is **not** run by default locally, though it is in CI. To enable it
61-
locally, set the environment variable `ENABLE_LINKCHECK=1` like in the
59+
We use `mdbook-linkcheck2` to validate URLs included in our documentation.
60+
Link checking is **not** run by default locally, though it is in CI.
61+
To enable it locally, set the environment variable `ENABLE_LINKCHECK=1` like in the
6262
following example.
6363

6464
```
@@ -67,6 +67,9 @@ ENABLE_LINKCHECK=1 mdbook serve
6767

6868
## Synchronizing josh subtree with rustc
6969

70-
This repository is linked to `rust-lang/rust` as a [josh](https://josh-project.github.io/josh/intro.html) subtree. You can use the [rustc-josh-sync](https://github.com/rust-lang/josh-sync) tool to perform synchronization.
70+
This repository is linked to `rust-lang/rust` as a [josh](https://josh-project.github.io/josh/intro.html) subtree.
71+
You can use the [rustc-josh-sync](https://github.com/rust-lang/josh-sync) tool to perform synchronization.
7172

7273
You can find a guide on how to perform the synchronization [here](./src/external-repos.md#synchronizing-a-josh-subtree).
74+
75+
[rustc API docs]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_middle

ci/sembr/src/main.rs

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ fn lengthen_lines(content: &str, limit: usize) -> String {
177177
let Some(next_line) = content.get(n + 1) else {
178178
continue;
179179
};
180+
if next_line.trim_start().starts_with("```") {
181+
continue;
182+
}
180183
if ignore(next_line, in_code_block)
181184
|| REGEX_LIST_ENTRY.is_match(next_line)
182185
|| REGEX_IGNORE_END.is_match(line)
@@ -255,6 +258,12 @@ preserve next line
255258
256259
preserve next line
257260
* three
261+
262+
do not mess with code block chars
263+
```
264+
leave the
265+
text alone
266+
```
258267
";
259268
let expected = "\
260269
do not split short sentences
@@ -269,6 +278,12 @@ preserve next line
269278
270279
preserve next line
271280
* three
281+
282+
do not mess with code block chars
283+
```
284+
leave the
285+
text alone
286+
```
272287
";
273288
assert_eq!(expected, lengthen_lines(original, 50));
274289
}
@@ -294,40 +309,6 @@ fn test_prettify_ignore_link_targets() {
294309
assert_eq!(original, lengthen_lines(original, 100));
295310
}
296311

297-
#[test]
298-
fn test_sembr_then_prettify() {
299-
let original = "
300-
hi there. do
301-
not split
302-
short sentences.
303-
hi again.
304-
";
305-
let expected = "
306-
hi there.
307-
do
308-
not split
309-
short sentences.
310-
hi again.
311-
";
312-
let processed = comply(original);
313-
assert_eq!(expected, processed);
314-
let expected = "
315-
hi there.
316-
do not split
317-
short sentences.
318-
hi again.
319-
";
320-
let processed = lengthen_lines(&processed, 50);
321-
assert_eq!(expected, processed);
322-
let expected = "
323-
hi there.
324-
do not split short sentences.
325-
hi again.
326-
";
327-
let processed = lengthen_lines(&processed, 50);
328-
assert_eq!(expected, processed);
329-
}
330-
331312
#[test]
332313
fn test_sembr_question_mark() {
333314
let original = "

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
dfe1b8c97bcde283102f706d5dcdc3649e5e12e3
1+
cec70080fd441d16e9fb08a0d1d1a04c72d1ed25

src/SUMMARY.md

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
- [ARM](notification-groups/arm.md)
6767
- [Emscripten](notification-groups/emscripten.md)
6868
- [Fuchsia](notification-groups/fuchsia.md)
69+
- [LoongArch](notification-groups/loongarch.md)
6970
- [RISC-V](notification-groups/risc-v.md)
7071
- [Rust for Linux](notification-groups/rust-for-linux.md)
7172
- [WASI](notification-groups/wasi.md)
@@ -126,8 +127,8 @@
126127
- [Lang Items](./lang-items.md)
127128
- [The HIR (High-level IR)](./hir.md)
128129
- [Lowering AST to HIR](./hir/lowering.md)
129-
- [Ambig/Unambig Types and Consts](./hir/ambig-unambig-ty-and-consts.md)
130130
- [Debugging](./hir/debugging.md)
131+
- [Ambig/Unambig Types and Consts](./ambig-unambig-ty-and-consts.md)
131132
- [The THIR (Typed High-level IR)](./thir.md)
132133
- [The MIR (Mid-level IR)](./mir/index.md)
133134
- [MIR construction](./mir/construction.md)
@@ -185,12 +186,14 @@
185186
- [Proof trees](./solve/proof-trees.md)
186187
- [Opaque types](./solve/opaque-types.md)
187188
- [Significant changes and quirks](./solve/significant-changes.md)
189+
- [Sharing the trait solver with rust-analyzer](./solve/sharing-crates-with-rust-analyzer.md)
188190
- [`Unsize` and `CoerceUnsized` traits](./traits/unsize.md)
189191
- [Variance](./variance.md)
190192
- [Coherence checking](./coherence.md)
191193
- [HIR Type checking](./hir-typeck/summary.md)
192194
- [Coercions](./hir-typeck/coercions.md)
193195
- [Method lookup](./hir-typeck/method-lookup.md)
196+
- [Const Generics](./const-generics.md)
194197
- [Opaque types](./opaque-types-type-alias-impl-trait.md)
195198
- [Inference details](./opaque-types-impl-trait-inference.md)
196199
- [Return Position Impl Trait In Trait](./return-position-impl-trait-in-trait.md)
@@ -230,11 +233,22 @@
230233
- [Debugging LLVM](./backend/debugging.md)
231234
- [Backend Agnostic Codegen](./backend/backend-agnostic.md)
232235
- [Implicit caller location](./backend/implicit-caller-location.md)
236+
- [Debug Info](./debuginfo/intro.md)
237+
- [Rust Codegen](./debuginfo/rust-codegen.md)
238+
- [LLVM Codegen](./debuginfo/llvm-codegen.md)
239+
- [Debugger Internals](./debuginfo/debugger-internals.md)
240+
- [LLDB Internals](./debuginfo/lldb-internals.md)
241+
- [GDB Internals](./debuginfo/gdb-internals.md)
242+
- [Debugger Visualizers](./debuginfo/debugger-visualizers.md)
243+
- [LLDB - Python Providers](./debuginfo/lldb-visualizers.md)
244+
- [GDB - Python Providers](./debuginfo/gdb-visualizers.md)
245+
- [CDB - Natvis](./debuginfo/natvis-visualizers.md)
246+
- [Testing](./debuginfo/testing.md)
247+
- [(Lecture Notes) Debugging support in the Rust compiler](./debugging-support-in-rustc.md)
233248
- [Libraries and metadata](./backend/libs-and-metadata.md)
234249
- [Profile-guided optimization](./profile-guided-optimization.md)
235250
- [LLVM source-based code coverage](./llvm-coverage-instrumentation.md)
236251
- [Sanitizers support](./sanitizers.md)
237-
- [Debugging support in the Rust compiler](./debugging-support-in-rustc.md)
238252

239253
---
240254

src/about-this-guide.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,21 +58,24 @@ please see the corresponding [subsection on writing documentation in this guide]
5858

5959
[subsection on writing documentation in this guide]: contributing.md#contributing-to-rustc-dev-guide
6060

61-
> “‘All conditioned things are impermanent’ —
61+
> “‘All conditioned things are impermanent’ —
6262
> when one sees this with wisdom, one turns away from suffering.”
6363
> _The Dhammapada, verse 277_
6464
6565
## Other places to find information
6666

67+
This guide, the one you are currently reading,
68+
contains information about how various parts of the compiler work,
69+
and how to contribute to the compiler.
70+
6771
You might also find the following sites useful:
6872

69-
- This guide contains information about how various parts of the
70-
compiler work and how to contribute to the compiler.
7173
- [rustc API docs] -- rustdoc documentation for the compiler, devtools, and internal tools
7274
- [Forge] -- contains documentation about Rust infrastructure, team procedures, and more
7375
- [compiler-team] -- the home-base for the Rust compiler team, with description
7476
of the team procedures, active working groups, and the team calendar.
7577
- [std-dev-guide] -- a similar guide for developing the standard library.
78+
- [rust-analyzer book] -- documentation for the rust-analyzer.
7679
- [The t-compiler Zulip][z]
7780
- The [Rust Internals forum][rif], a place to ask questions and
7881
discuss Rust's internals
@@ -110,4 +113,5 @@ You might also find the following sites useful:
110113
[Forge]: https://forge.rust-lang.org/
111114
[compiler-team]: https://github.com/rust-lang/compiler-team/
112115
[std-dev-guide]: https://std-dev-guide.rust-lang.org/
116+
[rust-analyzer book]: https://rust-analyzer.github.io/book/
113117
[z]: https://rust-lang.zulipchat.com/#narrow/stream/131828-t-compiler

src/ambig-unambig-ty-and-consts.md

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
# Ambig/Unambig Types and Consts
2+
3+
Types and Consts args in the AST/HIR can be in two kinds of positions ambiguous (ambig) or unambiguous (unambig). Ambig positions are where
4+
it would be valid to parse either a type or a const, unambig positions are where only one kind would be valid to
5+
parse.
6+
7+
```rust
8+
fn func<T, const N: usize>(arg: T) {
9+
// ^ Unambig type position
10+
let a: _ = arg;
11+
// ^ Unambig type position
12+
13+
func::<T, N>(arg);
14+
// ^ ^
15+
// ^^^^ Ambig position
16+
17+
let _: [u8; 10];
18+
// ^^ ^^ Unambig const position
19+
// ^^ Unambig type position
20+
}
21+
22+
```
23+
24+
Most types/consts in ambig positions are able to be disambiguated as either a type or const during parsing. The only exceptions to this are paths and inferred generic arguments.
25+
26+
## Paths
27+
28+
```rust
29+
struct Foo<const N: usize>;
30+
31+
fn foo<const N: usize>(_: Foo<N>) {}
32+
```
33+
34+
At parse time we parse all unbraced generic arguments as *types* (ie they wind up as [`ast::GenericArg::Ty`]). In the above example this means we would parse the generic argument to `Foo` as an `ast::GenericArg::Ty` wrapping a [`ast::Ty::Path(N)`].
35+
36+
Then during name resolution:
37+
- When encountering a single segment path with no generic arguments in generic argument position, we will first try to resolve it in the type namespace and if that fails we then attempt to resolve in the value namespace.
38+
- All other kinds of paths we only try to resolve in the type namespace
39+
40+
See [`LateResolutionVisitor::visit_generic_arg`] for where this is implemented.
41+
42+
Finally during AST lowering when we attempt to lower a type argument, we first check if it is a `Ty::Path` and if it resolved to something in the value namespace. If it did then we create an *anon const* and lower to a const argument instead of a type argument.
43+
44+
See [`LoweringContext::lower_generic_arg`] for where this is implemented.
45+
46+
Note that the ambiguity for paths is not propgated into the HIR; there's no `hir::GenericArg::Path` which is turned into either a `Ty` or `Const` during HIR ty lowering (though we could do such a thing).
47+
48+
## Inferred arguments (`_`)
49+
50+
```rust
51+
struct Foo<const N: usize>;
52+
53+
fn foo() {
54+
let _unused: Foo<_>;
55+
}
56+
```
57+
58+
The only generic arguments which remain ambiguous after lowering are inferred generic arguments (`_`) in path segments. In the above example it is not clear at parse time whether the `_` argument to `Foo` is an inferred type argument, or an inferred const argument.
59+
60+
In ambig AST positions, inferred argumentsd are parsed as an [`ast::GenericArg::Ty`] wrapping a [`ast::Ty::Infer`]. Then during AST lowering when lowering an `ast::GenericArg::Ty` we check if it is an inferred type and if so lower to a [`hir::GenericArg::Infer`].
61+
62+
In unambig AST positions, inferred arguments are parsed as either `ast::Ty::Infer` or [`ast::AnonConst`]. The `AnonConst` case is quite strange, we use [`ast::ExprKind::Underscore`] to represent the "body" of the "anon const" although in reality we do not actually lower this to an anon const in the HIR.
63+
64+
It may be worth seeing if we can refactor the AST to have `ast::GenericArg::Infer` and then get rid of this overloaded meaning of `AnonConst`, as well as the reuse of `ast::Ty::Infer` in ambig positions.
65+
66+
In unambig AST positions, during AST lowering we lower inferred arguments to [`hir::TyKind::Infer`][ty_infer] or [`hir::ConstArgKind::Infer`][const_infer] depending on whether it is a type or const position respectively.
67+
In ambig AST positions, during AST lowering we lower inferred arguments to [`hir::GenericArg::Infer`][generic_arg_infer]. See [`LoweringContext::lower_generic_arg`] for where this is implemented.
68+
69+
A naive implementation of this would result in there being potentially 5 places where you might think an inferred type/const could be found in the HIR from looking at the structure of the HIR:
70+
1. In unambig type position as a `TyKind::Infer`
71+
2. In unambig const arg position as a `ConstArgKind::Infer`
72+
3. In an ambig position as a [`GenericArg::Type(TyKind::Infer)`][generic_arg_ty]
73+
4. In an ambig position as a [`GenericArg::Const(ConstArgKind::Infer)`][generic_arg_const]
74+
5. In an ambig position as a `GenericArg::Infer`
75+
76+
Note that places 3 and 4 would never actually be possible to encounter as we always lower to `GenericArg::Infer` in generic arg position.
77+
78+
This has a few failure modes:
79+
- People may write visitors which check for `GenericArg::Infer` but forget to check for `hir::TyKind/ConstArgKind::Infer`, only handling infers in ambig positions by accident.
80+
- People may write visitors which check for `TyKind/ConstArgKind::Infer` but forget to check for `GenericArg::Infer`, only handling infers in unambig positions by accident.
81+
- People may write visitors which check for `GenericArg::Type/Const(TyKind/ConstArgKind::Infer)` and `GenericArg::Infer`, not realising that we never represent inferred types/consts in ambig positions as a `GenericArg::Type/Const`.
82+
- People may write visitors which check for *only* `TyKind::Infer` and not `ConstArgKind::Infer` forgetting that there are also inferred const arguments (and vice versa).
83+
84+
To make writing HIR visitors less error prone when caring about inferred types/consts we have a relatively complex system:
85+
86+
1. We have different types in the compiler for when a type or const is in an unambig or ambig position, `Ty<AmbigArg>` and `Ty<()>`. [`AmbigArg`][ambig_arg] is an uninhabited type which we use in the `Infer` variant of `TyKind` and `ConstArgKind` to selectively "disable" it if we are in an ambig position.
87+
88+
2. The [`visit_ty`][visit_ty] and [`visit_const_arg`][visit_const_arg] methods on HIR visitors only accept the ambig position versions of types/consts. Unambig types/consts are implicitly converted to ambig types/consts during the visiting process, with the `Infer` variant handled by a dedicated [`visit_infer`][visit_infer] method.
89+
90+
This has a number of benefits:
91+
- It's clear that `GenericArg::Type/Const` cannot represent inferred type/const arguments
92+
- Implementors of `visit_ty` and `visit_const_arg` will never encounter inferred types/consts making it impossible to write a visitor that seems to work right but handles edge cases wrong
93+
- The `visit_infer` method handles *all* cases of inferred type/consts in the HIR making it easy for visitors to handle inferred type/consts in one dedicated place and not forget cases
94+
95+
[ty_infer]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir/enum.TyKind.html#variant.Infer
96+
[const_infer]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir/enum.ConstArgKind.html#variant.Infer
97+
[generic_arg_ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir/enum.GenericArg.html#variant.Type
98+
[generic_arg_const]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir/enum.GenericArg.html#variant.Const
99+
[generic_arg_infer]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir/enum.GenericArg.html#variant.Infer
100+
[ambig_arg]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir/enum.AmbigArg.html
101+
[visit_ty]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/intravisit/trait.Visitor.html#method.visit_ty
102+
[visit_const_arg]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/intravisit/trait.Visitor.html#method.visit_const_arg
103+
[visit_infer]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/intravisit/trait.Visitor.html#method.visit_infer
104+
[`LateResolutionVisitor::visit_generic_arg`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_resolve/late/struct.LateResolutionVisitor.html#method.visit_generic_arg
105+
[`LoweringContext::lower_generic_arg`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast_lowering/struct.LoweringContext.html#method.lower_generic_arg
106+
[`ast::GenericArg::Ty`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/ast/enum.GenericArg.html#variant.Type
107+
[`ast::Ty::Infer`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/ast/enum.TyKind.html#variant.Infer
108+
[`ast::AnonConst`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/ast/struct.AnonConst.html
109+
[`hir::GenericArg::Infer`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/hir/enum.GenericArg.html#variant.Infer
110+
[`ast::ExprKind::Underscore`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/ast/enum.ExprKind.html#variant.Underscore
111+
[`ast::Ty::Path(N)`]: https://doc.rust-lang.org/nightly/nightly-rustc/rustc_ast/ast/enum.TyKind.html#variant.Path

0 commit comments

Comments
 (0)