Skip to content

Commit b069693

Browse files
author
The rustc-josh-sync Cronjob Bot
committed
Merge ref '68ffae46b581' from rust-lang/rust
Pull recent changes from https://github.com/rust-lang/rust via Josh. Upstream ref: rust-lang/rust@68ffae4 Filtered ref: rust-lang/compiler-builtins@7602939 Upstream diff: rust-lang/rust@d0442e2...68ffae4 This merge was created using https://github.com/rust-lang/josh-sync.
2 parents 4394bd8 + f02630d commit b069693

19 files changed

Lines changed: 399 additions & 273 deletions

examples/rustc-interface-example.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ fn main() {
5050
make_codegen_backend: None,
5151
expanded_args: Vec::new(),
5252
ice_file: None,
53-
hash_untracked_state: None,
53+
track_state: None,
5454
using_internal_features: &rustc_driver::USING_INTERNAL_FEATURES,
5555
};
5656
rustc_interface::run_compiler(config, |compiler| {
@@ -72,4 +72,4 @@ fn main() {
7272
}
7373
});
7474
});
75-
}
75+
}

examples/rustc-interface-getting-diagnostics.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ fn main() {
7878
make_codegen_backend: None,
7979
expanded_args: Vec::new(),
8080
ice_file: None,
81-
hash_untracked_state: None,
81+
track_state: None,
8282
using_internal_features: &rustc_driver::USING_INTERNAL_FEATURES,
8383
};
8484
rustc_interface::run_compiler(config, |compiler| {
@@ -97,4 +97,4 @@ fn main() {
9797
buffer.lock().unwrap().iter().for_each(|diagnostic| {
9898
println!("{diagnostic:#?}");
9999
});
100-
}
100+
}

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
30d0309fa821f7a0984a9629e0d227ca3c0d2eda
1+
cf1817bc6ecd2d14ca492247c804bad31948dd56

src/about-this-guide.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ You might also find the following sites useful:
9898
[gsearchdocs]: https://www.google.com/search?q=site:doc.rust-lang.org+your+query+here
9999
[stddocs]: https://doc.rust-lang.org/std
100100
[rif]: http://internals.rust-lang.org
101-
[rr]: https://doc.rust-lang.org/book/
101+
[rr]: https://doc.rust-lang.org/reference/
102102
[rustforge]: https://forge.rust-lang.org/
103103
[tlgba]: https://tomlee.co/2014/04/a-more-detailed-tour-of-the-rust-compiler/
104104
[ro]: https://www.rustaceans.org/

src/building/suggested.md

Lines changed: 62 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -144,77 +144,82 @@ If running `./x check` on save is inconvenient, in VS Code you can use a [Build
144144

145145
### Neovim
146146

147-
For Neovim users, there are a few options.
148-
The easiest way is by using [neoconf.nvim](https://github.com/folke/neoconf.nvim/),
149-
which allows for project-local configuration files with the native LSP.
150-
The steps for how to use it are below.
151-
Note that they require rust-analyzer to already be configured with Neovim.
152-
Steps for this can be [found here](https://rust-analyzer.github.io/manual.html#nvim-lsp).
147+
For Neovim users, there are a few options:
148+
149+
1. The easiest way is using [neoconf.nvim][neoconf.nvim] but it uses the
150+
deprecated `require('lspconfig')` API which displays a warning on neovim 0.11+.
151+
2. Using `coc.nvim` is another option but it requires node.js to be installed.
152+
3. Using a custom script to load rust-analyzer settings.
153+
154+
#### neoconf.nvim
155+
156+
[neoconf.nvim][neoconf.nvim] allows for project-local configuration
157+
files with the native LSP. The steps for how to use it are below. Note that they require
158+
rust-analyzer to already be configured with Neovim. Steps for this can be
159+
[found here][r-a nvim lsp].
153160

154161
1. First install the plugin.
155162
This can be done by following the steps in the README.
156163
2. Run `./x setup editor`, and select `vscode` to create a `.vscode/settings.json` file.
157164
`neoconf` is able to read and update
158165
rust-analyzer settings automatically when the project is opened when this file is detected.
159166

167+
#### coc.nvim
168+
160169
If you're using `coc.nvim`, you can run `./x setup editor` and select `vim` to
161170
create a `.vim/coc-settings.json`.
162171
The settings can be edited with `:CocLocalConfig`.
163172
The recommended settings live at [`src/etc/rust_analyzer_settings.json`].
164173

165-
Another way is without a plugin, and creating your own logic in your configuration.
166-
The following code will work for any checkout of rust-lang/rust (newer than February 2025):
174+
#### Custom LSP settings
175+
176+
If you're running neovim 0.11+, you can configure rust-analyzer with just
177+
[nvim-lspconfig](https://github.com/neovim/nvim-lspconfig) and a custom script.
178+
179+
1. Make sure [rust-analyzer LSP][r-a nvim lsp] is set up
180+
2. Create `$HOME/.config/nvim/after/plugged/rust_analyzer.lua` with the following content:
167181

168182
```lua
169-
local function expand_config_variables(option)
170-
local var_placeholders = {
171-
['${workspaceFolder}'] = function(_)
172-
return vim.lsp.buf.list_workspace_folders()[1]
173-
end,
174-
}
175-
176-
if type(option) == "table" then
177-
local mt = getmetatable(option)
178-
local result = {}
179-
for k, v in pairs(option) do
180-
result[expand_config_variables(k)] = expand_config_variables(v)
183+
-- Capture the default functions from nvim-lspconfig/lsp/rust_analyzer.lua before overriding it.
184+
-- This file is in after/plugin to guarantee nvim-lspconfig has been initialised already.
185+
local default_root_dir = vim.lsp.config["rust_analyzer"].root_dir
186+
local default_before_init = vim.lsp.config["rust_analyzer"].before_init
187+
188+
vim.lsp.config("rust_analyzer", {
189+
cmd = { "rust-analyzer" },
190+
filetypes = { "rust" },
191+
-- To support rust-lang/rust, we need to detect when we're in the rust repo and use the git root
192+
-- instead of cargo project root.
193+
root_dir = function(bufnr, on_dir)
194+
local git_root = vim.fs.root(bufnr, { ".git" })
195+
if git_root then
196+
if vim.uv.fs_stat(vim.fs.joinpath(git_root, "src/etc/rust_analyzer_zed.json")) then
197+
on_dir(git_root)
198+
return
199+
end
181200
end
182-
return setmetatable(result, mt)
183-
end
184-
if type(option) ~= "string" then
185-
return option
186-
end
187-
local ret = option
188-
for key, fn in pairs(var_placeholders) do
189-
ret = ret:gsub(key, fn)
190-
end
191-
return ret
192-
end
193-
lspconfig.rust_analyzer.setup {
194-
root_dir = function()
195-
local default = lspconfig.rust_analyzer.config_def.default_config.root_dir()
196-
-- the default root detection uses the cargo workspace root.
197-
-- but for rust-lang/rust, the standard library is in its own workspace.
198-
-- use the git root instead.
199-
local compiler_config = vim.fs.joinpath(default, "../src/bootstrap/defaults/config.compiler.toml")
200-
if vim.fs.basename(default) == "library" and vim.uv.fs_stat(compiler_config) then
201-
return vim.fs.dirname(default)
202-
end
203-
return default
201+
-- For anything that doesn't match rust-lang/rust, fallback to default root_dir
202+
default_root_dir(bufnr, on_dir)
204203
end,
205-
on_init = function(client)
206-
local path = client.workspace_folders[1].name
207-
local config = vim.fs.joinpath(path, "src/etc/rust_analyzer_zed.json")
208-
if vim.uv.fs_stat(config) then
209-
-- load rust-lang/rust settings
210-
local file = io.open(config)
211-
local json = vim.json.decode(file:read("*a"))
212-
client.config.settings["rust-analyzer"] = expand_config_variables(json.lsp["rust-analyzer"].initialization_options)
213-
client.notify("workspace/didChangeConfiguration", { settings = client.config.settings })
204+
before_init = function(init_params, config)
205+
-- When inside rust-lang/rust, we need to use the special rust-analyzer settings.
206+
local settings = vim.fs.joinpath(config.root_dir, "src/etc/rust_analyzer_zed.json")
207+
if vim.uv.fs_stat(settings) then
208+
local file = io.open(settings)
209+
-- nvim 0.12+ supports comments otherwise you'll need content:gsub("//[^\n]*", "").
210+
local json = vim.json.decode(file:read("*a"), { skip_comments = true })
211+
file:close()
212+
config.settings["rust-analyzer"] = vim.tbl_deep_extend(
213+
"force", -- Overwrite with the special settings when there is a conflict.
214+
config.settings["rust-analyzer"] or {},
215+
json.lsp["rust-analyzer"].initialization_options
216+
)
214217
end
215-
return true
216-
end
217-
}
218+
default_before_init(init_params, config)
219+
end,
220+
})
221+
222+
vim.lsp.enable("rust_analyzer")
218223
```
219224

220225
If you would like to use the build task that is described above, you may either
@@ -223,6 +228,9 @@ make your own command in your config, or you can install a plugin such as
223228
files](https://github.com/stevearc/overseer.nvim/blob/master/doc/guides.md#vs-code-tasks),
224229
and follow the same instructions as above.
225230

231+
[neoconf.nvim]: https://github.com/folke/neoconf.nvim/
232+
[r-a nvim lsp]: https://rust-analyzer.github.io/book/other_editors.html#nvim-lsp
233+
226234
### Emacs
227235

228236
Emacs provides support for rust-analyzer with project-local configuration

src/coherence.md

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@ Coherence checking is what detects both of trait impls and inherent impls overla
88
Overlapping trait impls always produce an error,
99
while overlapping inherent impls result in an error only if they have methods with the same name.
1010

11-
Checking for overlaps is split in two parts. First there's the [overlap check(s)](#overlap-checks),
11+
Checking for overlaps is split in two parts.
12+
First there's the [overlap check(s)](#overlap-checks),
1213
which finds overlaps between traits and inherent implementations that the compiler currently knows about.
1314

1415
However, Coherence also results in an error if any other impls **could** exist,
15-
even if they are currently unknown.
16+
even if they are currently unknown.
1617
This affects impls which may get added to upstream crates in a backwards compatible way,
17-
and impls from downstream crates.
18+
and impls from downstream crates.
1819
This is called the Orphan check.
1920

2021
## Overlap checks
@@ -25,7 +26,7 @@ Overlap checks always consider pairs of implementations, comparing them to each
2526

2627
Overlap checking for inherent impl blocks is done through `fn check_item` (in coherence/inherent_impls_overlap.rs),
2728
where you can very clearly see that (at least for small `n`), the check really performs `n^2`
28-
comparisons between impls.
29+
comparisons between impls.
2930

3031
In the case of traits, this check is currently done as part of building the [specialization graph](traits/specialization.md),
3132
to handle specializing impls overlapping with their parent, but this may change in the future.
@@ -37,7 +38,7 @@ Overlapping is sometimes partially allowed:
3738
1. for marker traits
3839
2. under [specialization](traits/specialization.md)
3940

40-
but normally isn't.
41+
It normally isn't.
4142

4243
The overlap check has various modes (see [`OverlapMode`]).
4344
Importantly, there's the explicit negative impl check, and the implicit negative impl check.
@@ -47,9 +48,9 @@ Both try to prove that an overlap is definitely impossible.
4748

4849
### The explicit negative impl check
4950

50-
This check is done in [`impl_intersection_has_negative_obligation`].
51+
This check is done in [`impl_intersection_has_negative_obligation`].
5152

52-
This check tries to find a negative trait implementation.
53+
This check tries to find a negative trait implementation.
5354
For example:
5455

5556
```rust
@@ -64,7 +65,7 @@ In this example, we'd get:
6465
`MyCustomErrorType: From<&str>` and `MyCustomErrorType: From<?E>`, giving `?E = &str`.
6566

6667
And thus, these two implementations would overlap.
67-
However, libstd provides `&str: !Error`, and therefore guarantees that there
68+
However, libstd provides `&str: !Error`, and therefore guarantees that there
6869
will never be a positive implementation of `&str: Error`, and thus there is no overlap.
6970

7071
Note that for this kind of negative impl check, we must have explicit negative implementations provided.
@@ -77,18 +78,17 @@ This is not currently stable.
7778
This check is done in [`impl_intersection_has_impossible_obligation`],
7879
and does not rely on negative trait implementations and is stable.
7980

80-
Let's say there's a
81+
Let's say there's a
8182
```rust
8283
impl From<MyLocalType> for Box<dyn Error> {} // in your own crate
8384
impl<E> From<E> for Box<dyn Error> where E: Error {} // in std
8485
```
8586

86-
This would give: `Box<dyn Error>: From<MyLocalType>`, and `Box<dyn Error>: From<?E>`,
87+
This would give: `Box<dyn Error>: From<MyLocalType>`, and `Box<dyn Error>: From<?E>`,
8788
giving `?E = MyLocalType`.
8889

8990
In your crate there's no `MyLocalType: Error`, downstream crates cannot implement `Error` (a remote trait) for `MyLocalType` (a remote type).
9091
Therefore, these two impls do not overlap.
9192
Importantly, this works even if there isn't a `impl !Error for MyLocalType`.
9293

9394
[`impl_intersection_has_impossible_obligation`]: https://doc.rust-lang.org/beta/nightly-rustc/rustc_trait_selection/traits/coherence/fn.impl_intersection_has_impossible_obligation.html
94-

src/compiler-debugging.md

Lines changed: 42 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -273,18 +273,18 @@ Here are some notable ones:
273273

274274
| Attribute | Description |
275275
|----------------|-------------|
276-
| `rustc_def_path` | Dumps the [`def_path_str`] of an item. |
277276
| `rustc_dump_def_parents` | Dumps the chain of `DefId` parents of certain definitions. |
277+
| `rustc_dump_def_path` | Dumps the [`def_path_str`] of an item. |
278+
| `rustc_dump_hidden_type_of_opaques` | Dumps the [hidden type of each opaque types][opaq] in the crate. |
278279
| `rustc_dump_inferred_outlives` | Dumps implied bounds of an item. More precisely, the [`inferred_outlives_of`] an item. |
279280
| `rustc_dump_item_bounds` | Dumps the [`item_bounds`] of an item. |
281+
| `rustc_dump_layout` | [See this section](#debugging-type-layouts). |
280282
| `rustc_dump_object_lifetime_defaults` | Dumps the [object lifetime defaults] of an item. |
281283
| `rustc_dump_predicates` | Dumps the [`predicates_of`] an item. |
284+
| `rustc_dump_symbol_name` | Dumps the mangled & demangled [`symbol_name`] of an item. |
282285
| `rustc_dump_variances` | Dumps the [variances] of an item. |
283286
| `rustc_dump_vtable` | Dumps the vtable layout of an impl, or a type alias of a dyn type. |
284-
| `rustc_hidden_type_of_opaques` | Dumps the [hidden type of each opaque types][opaq] in the crate. |
285-
| `rustc_layout` | [See this section](#debugging-type-layouts). |
286287
| `rustc_regions` | Dumps NLL closure region requirements. |
287-
| `rustc_symbol_name` | Dumps the mangled & demangled [`symbol_name`] of an item. |
288288

289289
Right below you can find elaborate explainers on a selected few.
290290

@@ -316,54 +316,55 @@ $ firefox maybe_init_suffix.pdf # Or your favorite pdf viewer
316316

317317
### Debugging type layouts
318318

319-
The internal attribute `#[rustc_layout]` can be used to dump the [`Layout`] of
320-
the type it is attached to.
319+
The internal attribute `#[rustc_dump_layout(...)]` can be used to dump the
320+
[`Layout`] of the type it is attached to.
321321
For example:
322322

323323
```rust
324324
#![feature(rustc_attrs)]
325325

326-
#[rustc_layout(debug)]
326+
#[rustc_dump_layout(debug)]
327327
type T<'a> = &'a u32;
328328
```
329329

330330
Will emit the following:
331331

332332
```text
333-
error: layout_of(&'a u32) = Layout {
334-
fields: Primitive,
335-
variants: Single {
336-
index: 0,
337-
},
338-
abi: Scalar(
339-
Scalar {
340-
value: Pointer,
341-
valid_range: 1..=18446744073709551615,
342-
},
343-
),
344-
largest_niche: Some(
345-
Niche {
346-
offset: Size {
347-
raw: 0,
348-
},
349-
scalar: Scalar {
350-
value: Pointer,
351-
valid_range: 1..=18446744073709551615,
352-
},
353-
},
354-
),
355-
align: AbiAndPrefAlign {
356-
abi: Align {
357-
pow2: 3,
358-
},
359-
pref: Align {
360-
pow2: 3,
361-
},
362-
},
363-
size: Size {
364-
raw: 8,
365-
},
366-
}
333+
error: layout_of(&u32) = Layout {
334+
size: Size(8 bytes),
335+
align: AbiAlign {
336+
abi: Align(8 bytes),
337+
},
338+
backend_repr: Scalar(
339+
Initialized {
340+
value: Pointer(
341+
AddressSpace(
342+
0,
343+
),
344+
),
345+
valid_range: 1..=18446744073709551615,
346+
},
347+
),
348+
fields: Primitive,
349+
largest_niche: Some(
350+
Niche {
351+
offset: Size(0 bytes),
352+
value: Pointer(
353+
AddressSpace(
354+
0,
355+
),
356+
),
357+
valid_range: 1..=18446744073709551615,
358+
},
359+
),
360+
uninhabited: false,
361+
variants: Single {
362+
index: 0,
363+
},
364+
max_repr_align: None,
365+
unadjusted_abi_align: Align(8 bytes),
366+
randomization_seed: 281492156579847,
367+
}
367368
--> src/lib.rs:4:1
368369
|
369370
4 | type T<'a> = &'a u32;

0 commit comments

Comments
 (0)