Implement opt-in debugger discovery for GDB and LLDB in bootstrap
GDB and LLDB is no longer automatically auto-discovered, you can opt into the previous behavior using `build.gdb/lldb = "discover"`.
Note: this means that unless you opt into using a specific debugger, you won't run any `debuginfo` tests by default (except for `cdb`, which is still automatically detected).
r? @jieyouxu
Make some parser structured suggestions verbose and tweak their wording
Replace most of the `.span_suggestion(` in `rustc_parse` with `.span_suggestion_verbose(`, as they are more readabale, if more verbose. Verbose suggestions also tend to highlight off-by-one `Span` errors better.
Tweak some of the touched diagnostics to bring them more in-line with our house style.
CC https://github.com/rust-lang/rust/issues/141973
str: add ASCII fast path to word_to_titlecase
The word_to_titlecase function had a FIXME comment since a long time asking to add a fast path for ASCII text.
Before this change, even simple English text like "hello world" was going through slow Unicode lookup tables. That was unnecessary.
This fixes it by using the same trick that to_lowercase already uses — plain English letters are now handled much faster, and only Greek/Chinese/etc still use the Unicode tables.
No behavior changes, just faster for normal English text.
ci: Enable autodiff tests on x86_64 linux
## Summary
Enable autodiff tests on x86_64 linux
For now, this is an `optional-*` Merge CI only job, and is not enabled in PR CI.
r? @ZuseZ4
constify `vec![1, 2, 3]` macro
Tracking issues:
`const_heap`: https://github.com/rust-lang/rust/issues/79597
makes all the parts needed for non-empty `vec![]` macros const:
`alloc::boxed::box_assume_init_into_vec_unsafe`
`alloc::boxed::Box::assume_init`
`alloc::boxed::Box::into_raw_with_allocator`
`alloc::boxed::Box::new_uninit`
`alloc::slice::[T]::into_vec`
Note that this does not allow for the use of the `vec![(); 4]` arm of this macro to be used in const-eval, since that uses specialization (spec and const traits don't really like each other so I didn't want to touch any of that in this).
Improve consistency of attribute error messages
This PR aims to improve how attributes are referred to in error messages. A lot of test outputs will change, so there will be follow-ups, but this PR has enough changes to cover a lot of cases and give a good feel for where things are headed.
r? @estebank
std: Implement futex on wasip3 targets, update target spec
This commit is in preparation for eventual [tier 2 status] for the `wasm32-wasip3` target. Initially this target will not have support for threads but it's expected to come ~later this year. The first step in supporting this is switching internal `#[cfg]` in the standard library to "ok this target has threads", and this commit is the update for synchronization primitives. All synchronization primitives on the `wasm32-wasip3` now use a `futex`-based implementation, and the implementation of the futex itself is located in wasi-libc (see WebAssembly/wasi-libc#834). Other WASI targets can eventually all use this implementation as well, but `wasi-libc`'s implementation of these symbols will need to percolate, so those targets aren't changed yet. For `wasm32-wasip3`, however, any supporting `wasi-libc` will have these symbols.
This then additionally fixes the target to actually build with a modern LLVM by passing a necessary flag to `wasm-ld`. This flag isn't supported until LLVM 23, but the `wasm32-wasip3` target isn't fully supported until LLVM 23 anyway (hence its Tier 3 status currently).
[tier 2 status]: https://github.com/rust-lang/compiler-team/issues/1001
[rustdoc] Retrieve `cfg_attr` information for derived impls for `doc_cfg` feature
Fixes https://github.com/rust-lang/rust/issues/103300.
After long last, this PR finally allows the derive proc-macro `cfg_attr` cfg predicates information to be kept so rustdoc can use it for its `doc_cfg` feature (cc https://github.com/rust-lang/rust/issues/43781).
It works as follows: for `impl` generated by macro expansion, we then look for the attributes on the type for which the `impl` block is implemented. Then, to know which `cfg_attr` attribute we want to look at, we use `expn_that_defined` on the impl's `DefId` which returns the `Span` where the macro was expanded. If it's part of a `cfg_attr`, then the `cfg_attr`'s `Span` will contain the derive's, so from then, we just need to add the `cfg` information.
This PR also adds the cfg predicates into the `AttributeKind::CfgAttrTrace` variant so it can be reused by rustdoc (hence the `compiler/*` changes).
Thanks a lot @petrochenkov for the pointers here!
r? @petrochenkov
rustfmt: Discover modules via `cfg_select!`
This PR renames all occurrences of `cfg_match!` in rustfmt to `cfg_select!`. This makes the module file detection logic from https://github.com/rust-lang/rustfmt/pull/6522 kick in for `cfg_select!` instead of `cfg_match!`, which no longer exists.
This PR performs no other adjustments to the logic to be as small as possible.
I am opening this PR in this repo since that is also the target for the more comprehensive https://github.com/rust-lang/rust/pull/154202, which covers more than merely detecting other files through `cfg_select!`.
Closes https://github.com/rust-lang/rust/issues/158371.
CC: @ytmimi, @CAD97
trait solver: account for universes from replace_bound_vars
Fixesrust-lang/rust#157840.
The ICE was not really because eager placeholder handling looked at too many universes. Boxy was right: with `-Zassumptions-on-binders`, if the new solver creates a placeholder universe, that universe needs an assumptions entry.
The bad path is `FindParamInClause` entering a binder through `replace_bound_vars`. `BoundVarReplacer` materializes a placeholder universe for the escaping bound vars, but nothing records placeholder assumptions for it. Later eager placeholder handling walks all non-input universes, which imo is the right behavior, and `get_placeholder_assumptions` hits the missing entry.
This moves the empty-assumptions bookkeeping into `EvalCtxt::replace_bound_vars` instead of keeping it local to `FindParamInClause`. The helper snapshots the universe slots before replacement and inserts `Assumptions::empty()` for any slot that got filled.
There is still a FIXME there because idk that empty assumptions is the final shape irl. `replace_bound_vars` does not have the param-env context to compute proper assumptions. But for this PR, imo this is the least weird local fix: it keeps the eager pass looking at all non-input universes and fixes the missing bookkeeping where the universe is created.
The repro is covered by a UI test. It reports the overflow diagnostic instead of ICEing.
Update bootstrap to use -Zembed-metadata=no instead of -Zno-embed-metadata
The recent Cargo submodule update picked up <https://github.com/rust-lang/cargo/pull/17149>
However, bootstrap was still using the old name, resulting in:
```
Building stage1 library artifacts (stage1 -> stage1, arm64ec-pc-windows-msvc)
error: unknown `-Z` flag specified: no-embed-metadata
```
Fix is to switch to the rename.
I also removed the diff in the Cranelift setup script, since they must have already hit this issue and no longer need the workaround.
Avoid spurious rebuilds of JSON docs in bootstrap
Found this while working on https://github.com/rust-lang/rust/pull/159671.
Before, repeated runs of e.g. `x dist rust-docs-json` always rebuilt the docs. It was caused by Cargo not knowing that the output should be JSON, so it was trying to find the HTML files.
Instead of passing the output format through `RUSTDOCFLAGS`, which Cargo doesn't inspect, we now pass it to Cargo directly, which fixes the issue.
Mostly in a fashion similar to the previous commit.
There is one exceptional case: for errors involving `repr` the argument
is significant. For these, the argument is included in the error line
and the caret highlighting, e.g.
```
error: the `repr(C)` attribute cannot be used on functions
--> $DIR/naked-with-invalid-repr-attr.rs:10:3
|
LL | #[repr(C)]
| ^^^^^^^
|
= help: the `repr(C)` attribute can only be applied to data types
```
Contrast this with a more typical argument-excluding case used
everywhere else:
```
error: the `rustc_abi` attribute cannot be used on associated consts
--> $DIR/debug.rs:46:7
|
LL | #[rustc_abi(debug)]
| ^^^^^^^^^
|
= help: the `rustc_abi` attribute can be applied to functions and type aliases
```
These changes involve the error messages produced in
`check_attribute_stability`, plus some related ones.
The basic idea:
- Use "the `foo` attribute" in `error` lines as much as possible, where
`foo` is the attribute's path.
- Point carets at just the attribute's path, to match the `error` line.
Avoid ICEing in RPIT method chain suggestion
In the case that the return type captures a lifetime, `skip_binder()` will cause the later `can_eq()` call to ICE, so we call `enter_forall()` with the binder instead. Probably best reviewed with ignore-whitespace.
fixesrust-lang/rust#159685
Remove outdated workaround for `P` type
P is long gone, so this workaround is no longer necessary.
The workaround took attrs out of node, inspected and possibly modified it and then put it back at the end of each branch of the following match.
use `minicore::simd::Simd` more
follow-up to https://github.com/rust-lang/rust/pull/159656.
I've used `grep -rlZ "repr_simd" . | xargs -0 grep -l "use minicore"` to find all test files that used both `repr_simd` and `use minicore`, they now all use `minicore::simd` to `repr_simd` is no longer needed for them.
rustfmt fix: allow file not found errors for external mods annotated with `#[my_macro]`
Tracking issue: https://github.com/rust-lang/rust/issues/54727
`#[my_macro]` was stabilized for macro hygiene 2.0 in https://github.com/rust-lang/rust/pull/157857. There isn't a guarantee that the external module exists on the file system so ignore any file not found errors encountered when trying to resolve the module's file.
Fixesrust-lang/rustfmt#6959
r? @petrochenkov
cc: @TimNN
tests: add UI test for `.swap()` suggestion
adds a UI test covering the borrow checker diagnostic that suggests using
`.swap()` when `std::mem::swap(&mut arr[i], &mut arr[j])` is used.
closesrust-lang/rust#159664
early_otherwise: Don't hoist dereferences when the otherwise branch is reachable
Fixes https://github.com/rust-lang/rust/issues/159591.
A place may contain a dereference that cannot be safely hoisted when the otherwise branch is reachable.
doc: document wasm import symbol mangling
Document that foreign items from wasm_import_module extern blocks are mangled even with #[no_mangle] or #[link_name], so same-named imports from different WebAssembly modules remain distinct.
Update comments and add tests for `-Zrandomize-layout` for some guaranteed ZSTs
See https://github.com/rust-lang/reference/pull/2262 . T-lang wants to make some additional guarantees about zero-sized `repr(Rust)` structs and enums, that changes to `-Zrandomize-layout` could theoretically break in the future. This PR adds comments to `-Zrandomize-layout`'s implementation and tests to `tests/ui/layout/randomize.rs` to prevent breaking those guarantees.
First commit is the guarantees that T-lang already FCP'd in https://github.com/rust-lang/reference/pull/2262 .
Second commit is an additional guarantee (that zero-variant repr(Rust) enums are ZSTs) that's at https://github.com/rust-lang/reference/pull/2293 (FCP now completed)
rustdoc: Only synthesize auto/blanket impls for documented items
Previously, the code would skip synthesizing impls if the *trait* was
not documented, but it would still synthesize even if the *type* was not
documented. This is wasted work.