Skip to content

Commit 4954a26

Browse files
committed
Auto merge of #155655 - JonathanBrouwer:rollup-KFUw3UR, r=JonathanBrouwer
Rollup of 10 pull requests Successful merges: - rust-lang/rust#154794 (Add on_unmatch_args) - rust-lang/rust#155133 (Document precision considerations of `Duration`-float methods) - rust-lang/rust#154283 (Remove `nodes_in_current_session` field and related assertions) - rust-lang/rust#155374 (rustdoc: fix a few spots where emit isn't respected) - rust-lang/rust#155587 (Immediately feed visibility on DefId creation) - rust-lang/rust#155622 (c-variadic: `va_arg` fixes ) - rust-lang/rust#155629 (rustc_public: Add `constness` & `asyncness` in `FnDef`) - rust-lang/rust#155632 (Some metadata cleanups) - rust-lang/rust#155639 (BinOpAssign always returns unit) - rust-lang/rust#155647 (rustc-dev-guide subtree update)
2 parents 6dc7e37 + 5c5ddc4 commit 4954a26

14 files changed

Lines changed: 315 additions & 204 deletions

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/effects.md

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
## The `HostEffect` predicate
44

5-
[`HostEffectPredicate`]s are a kind of predicate from `~const Tr` or `const Tr` bounds.
5+
[`HostEffectPredicate`]s are a kind of predicate from `[const] Tr` or `const Tr` bounds.
66
It has a trait reference, and a `constness` which could be `Maybe` or
77
`Const` depending on the bound.
8-
Because `~const Tr`, or rather `Maybe` bounds
8+
Because `[const] Tr`, or rather `Maybe` bounds
99
apply differently based on whichever contexts they are in, they have different
1010
behavior than normal bounds.
1111
Where normal trait bounds on a function such as
1212
`T: Tr` are collected within the [`predicates_of`] query to be proven when a
1313
function is called and to be assumed within the function, bounds such as
14-
`T: ~const Tr` will behave as a normal trait bound and add `T: Tr` to the result
14+
`T: [const] Tr` will behave as a normal trait bound and add `T: Tr` to the result
1515
from `predicates_of`, but also adds a `HostEffectPredicate` to the [`const_conditions`] query.
1616

1717
On the other hand, `T: const Tr` bounds do not change meaning across contexts,
@@ -37,7 +37,7 @@ In a similar vein,
3737
an item *in const contexts*. If we adjust the example above to use `const` trait bounds:
3838

3939
```rust
40-
const fn foo<T>() where T: ~const Default {}
40+
const fn foo<T>() where T: [const] Default {}
4141
```
4242

4343
Then `foo` would get a `HostEffect(T: Default, maybe)` in the `const_conditions`
@@ -55,7 +55,7 @@ Note that we don't check
5555
if the function is only referred to but not called, as the following code needs to compile:
5656

5757
```rust
58-
const fn hi<T: ~const Default>() -> T {
58+
const fn hi<T: [const] Default>() -> T {
5959
T::default()
6060
}
6161
const X: fn() -> u32 = hi::<u32>;
@@ -69,7 +69,7 @@ Here's an example:
6969

7070
```rust
7171
const trait Bar {}
72-
const trait Foo: ~const Bar {}
72+
const trait Foo: [const] Bar {}
7373
// `const_conditions` contains `HostEffect(Self: Bar, maybe)`
7474

7575
impl const Bar for () {}
@@ -86,13 +86,13 @@ We do the same for `const_conditions`:
8686

8787
```rust
8888
const trait Foo {
89-
fn hi<T: ~const Default>();
89+
fn hi<T: [const] Default>();
9090
}
9191

92-
impl<T: ~const Clone> Foo for Vec<T> {
93-
fn hi<T: ~const PartialEq>();
94-
// ^ we can't prove `T: ~const PartialEq` given `T: ~const Clone` and
95-
// `T: ~const Default`, therefore we know that the method on the impl
92+
impl<T: [const] Clone> Foo for Vec<T> {
93+
fn hi<T: [const] PartialEq>();
94+
// ^ we can't prove `T: [const] PartialEq` given `T: [const] Clone` and
95+
// `T: [const] Default`, therefore we know that the method on the impl
9696
// is stricter than the method on the trait.
9797
}
9898
```
@@ -117,11 +117,11 @@ Bounds on associated types, opaque types, and supertraits such as the following
117117
have their bounds represented differently:
118118

119119
```rust
120-
trait Foo: ~const PartialEq {
121-
type X: ~const PartialEq;
120+
trait Foo: [const] PartialEq {
121+
type X: [const] PartialEq;
122122
}
123123

124-
fn foo() -> impl ~const PartialEq {
124+
fn foo() -> impl [const] PartialEq {
125125
// ^ unimplemented syntax
126126
}
127127
```

src/git.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,8 +385,8 @@ the history becomes easier to work with.
385385

386386
The easiest way to squash your commits in a PR on the `rust-lang/rust` repository is to use the `@bors squash` command in a comment on the PR.
387387
By default, [bors] combines all commit messages of the PR into the squashed commit message.
388-
To customize the commit message, use `@bors squash msg=<commit message>`.
389-
388+
To customize the commit message, use `@bors squash msg="<commit message>"`.
389+
For example, `@bors squash msg="Improve diagnostics for missing lifetime parameter"`.
390390

391391
If you want to squash commits using local git operations, read on below.
392392

0 commit comments

Comments
 (0)