Rollup of 7 pull requests
Successful merges:
- #134216 (Enable "jump to def" feature on patterns)
- #134880 (Made `Path::name` only have item name rather than full name)
- #135466 (Leak check in `impossible_predicates` to avoid monomorphizing impossible instances)
- #135476 (Remove remnant of asmjs)
- #135479 (mir borrowck: cleanup late-bound region handling)
- #135493 (Fix legacy symbol mangling of closures)
- #135495 (Add missing closing backtick in commit hook message 🐸)
r? `@ghost`
`@rustbot` modify labels: rollup
Fix legacy symbol mangling of closures
When this code was written, there was no `type_of` implementation for closures. That has long since been changed.
In the UI test:
```
trait A where
[(); (|| {}, 1).1]: Sized,
{
}
```
We tried to walk up the def path tree for the closure, from closure -> anon const -> trait. When we reached the trait, we tried to call `type_of` on it which obviously doesn't do the right thing and ICEs.
Fixes#135418
Made `Path::name` only have item name rather than full name
Closes#134853
This PR makes `Path::name` to only have item name rather than full name, i.e. with the following code
```rust
pub mod foo {
pub struct Bar;
}
pub fn get_bar() -> foo::Bar {
foo::Bar
}
```
and running `./rustdoc ./demo.rs -wjson -Zunstable-options` gives:
```json
{
"41": {
"id": 41,
"name": "get_bar",
"inner": {
"function": {
"sig": {
"inputs": [],
"output": {
"resolved_path": {
"name": "Bar",
"id": 0,
"args": { "angle_bracketed": { "args": [], "constraints": [] }
}
}
}
}
}
}
}
}
```
_Information which isn't useful here was trimmed_
r? aDotInTheVoid
Enable "jump to def" feature on patterns
Part of https://github.com/rust-lang/rust/issues/89095.
Pattern (as in "patterns in pattern matching") were not handled by the feature, it's now added.
It all started when I realized that prelude values like `Some` or `Err` were not getting a link generated either (added support for it in the first commit).
r? ``@fmease``
Eagerly mono drop for structs with lifetimes
That is, use `!generics.requires_monomorphization()` rather than `generics.is_empty()` like the rest of the mono collector code.
Exclude dependencies of `std` for diagnostics
Currently crates in the sysroot can show up in diagnostic suggestions, such as in https://github.com/rust-lang/rust/issues/135232. To prevent this, duplicate `all_traits` into `visible_traits` which only shows traits in non-private crates.
Setting `#![feature(rustc_private)]` overrides this and makes items in private crates visible as well, since `rustc_private` enables use of `std`'s private dependencies.
This may be reviewed per-commit.
Fixes: https://github.com/rust-lang/rust/issues/135232
In order to avoid diagnostics suggesting stdlib-private dependencies,
make everything that is a direct dependency of any `std` crates private
by default. Note that this will be overridden, if the same crate is
public elsewhere in the crate graph then that overrides the private
default.
It may also be feasible to do this in the library crate, marking `std`'s
dependencies private via Cargo. However, given that the feature is still
rather unstable, doing this within the compiler seems more
straightforward.
Fixes: https://github.com/rust-lang/rust/issues/135232 [1]
Add an alternative to `tcx.all_traits()` that only shows traits that the
user might be able to use, for diagnostic purposes. With this available,
make use of it for diagnostics including associated type errors, which
is part of the problem with [1].
Includes a few comment updates for related API.
[1]: https://github.com/rust-lang/rust/issues/135232
Really this is always-visible override only needs to happen when the
crate is a dependency of itself. However, this is a very internal
feature, so it doesn't seem worth doing any additional filtering here.
Currently `root` or `crate_root` is used to refer to an instance of
`CrateRoot` (representation of a crate's serialized metadata), but the
name `root` sometimes also refers to a `CratePath` representing a "root"
node in the dependency graph. In order to disambiguate, rename all
instances of the latter to `dep_root`.
Rollup of 3 pull requests
Successful merges:
- #135381 (Add an example for `Vec::splice` inserting elements without removing)
- #135451 (Remove code duplication when hashing query result and interning node)
- #135464 (fix ICE with references to infinite structs in consts)
r? `@ghost`
`@rustbot` modify labels: rollup
fix ICE with references to infinite structs in consts
fixes https://github.com/rust-lang/rust/issues/114484
Normalizing `<Type as Pointee>::Metadata` may emit a (non-fatal) error during trait selection if finding the struct tail of `Type` hits the recursion limit. When this happens, prior this PR, we would treat the projection as rigid, i.e. don't normalize it further. This PR changes it so that we normalize to `ty::Error` instead.
This is important, because to compute the layout of `&Type` we need to compute the layout of `<Type as Pointee>::Metadata`
2ae9916816/compiler/rustc_ty_utils/src/layout.rs (L247-L273)
and computing the layout of a rigid alias will (correctly) fail and needs to report an error to the user. For example:
```rust
trait Project {
type Assoc;
}
fn foo<T: Project>() {
[(); {
let _: Option<T::Assoc> = None;
// ^^^^^^^^ this projection is rigid, so we can't know it's layout
0
}];
}
```
```
error: constant expression depends on a generic parameter
--> src/lib.rs:6:10
|
6 | [(); {
| __________^
7 | | let _: Option<T::Assoc> = None;
8 | | // ^^^^^^^^ this projection is rigid, so we can't know it's layout
9 | | 0
10 | | }];
| |_____^
|
= note: this may fail depending on what value the parameter takes
```
For non-generic rigid projections we will currently ICE, because we incorrectly assume that `LayoutError::Unknown` means that a const must be generic (https://github.com/rust-lang/rust/issues/135138). This is being fixed and turned into a proper error in https://github.com/rust-lang/rust/pull/135158.
```rust
#![feature(trivial_bounds)]
trait Project {
type Assoc;
}
fn foo()
where
u8: Project,
{
[(); {
let _: Option<<u8 as Project>::Assoc> = None; // ICEs currently, but will be an error
0
}];
}
```
However, if we hit the recursion limit when normalizing `<Type as Pointee>::Metadata` we don't want to report a layout error, because we already emitted the recursion error. So by normalizing to `ty::Error` here, we get a `LayoutError::ReferencesError` instead of a `LayoutError::Unknown` and don't report the layout error to the user.
Remove code duplication when hashing query result and interning node
Refactored the duplicated code into a function.
`with_feed_task` currently passes the query key to `debug_assert!`. I believe that's a mistake, since `with_task` prints the `DepNode` which is more sensible, so this commit changes that, so it debug prints the `DepNode`.
Add an example for `Vec::splice` inserting elements without removing
This example clearly showcases how `splice` can be used to insert multiple elements efficiently at an index into a vector.
Fixes#135369.
The added example:
> Using `splice` to insert new items into a vector efficiently at a specific position indicated by an empty range:
> ```rust
> let mut v = vec![1, 5];
> let new = [2, 3, 4];
> v.splice(1..1, new);
> assert_eq!(v, [1, 2, 3, 4, 5]);
> ```
`@rustbot` label A-docs A-collections
use a single large catch_unwind in lang_start
I originally planned to use `abort_unwind` but reading the comment in `thread_cleanup` it seems we are deliberately going for slightly nicer error messages here, so this preserves that. It still seems nice to not repeat `catch_unwind` so often.
llvm: Allow sized-word rather than ymmword in tests
llvm/llvm-project#122530 changes LLVM to use sized-word rather than ymmword for scatter gather pointers. While this will not always be qword, it is for these two tests.
`@rustbot` label: +llvm-main
Fix emscripten-wasm-eh with unwind=abort
If we build the standard library with wasm-eh then we need to link with `-fwasm-exceptions` even if we compile with `panic=abort`.
Without this change, linking a `panic=abort` crate fails with: `undefined symbol: __cpp_exception`.
Followup to #131830.
r? workingjubilee
Update books
## rust-lang/book
10 commits in 04d06dfe541607e6419f3d028c3f9b245f3be4d9..5a65e2af063ff701ae858f1f7536ee347b3cfe63
2025-01-09 17:59:43 UTC to 2025-01-06 13:47:07 UTC
- Appendix E: Update for 2024 Edition (rust-lang/book#4196)
- Implement and integrate an mdBook plugin to strip markup from headings (rust-lang/book#4195)
- Update appendix-06-translation.md - new persian translation added (rust-lang/book#4192)
- Remove extraneous `use` statement (rust-lang/book#4193)
- Take measurement inaccuracy intervals into account (rust-lang/book#4078)
- Ch. 21.3: remove error ferris from working code (rust-lang/book#4183)
- infra: match mdbook version in CI to rust-lang/rust (rust-lang/book#4191)
- Ch. 17: Set correct heading level for the chapter (rust-lang/book#4190)
- Switch back from `eprintln!` to `println!` in listing 17-12 (rust-lang/book#4178)
- fix typo in Listing invocation for listing 20-14 (rust-lang/book#4184)
## rust-lang/nomicon
1 commits in 7ef05b9777c94836bc92f50f23e6e00981521a89..625b200e5b33a5af35589db0bc454203a3d46d20
2025-01-06 17:17:38 UTC to 2025-01-06 17:17:38 UTC
- Fix accidental inline HTML in Markdown (rust-lang/nomicon#474)
## rust-lang/reference
3 commits in acd6794e712d5e2ef6f5c84fb95688d32a69b816..293af991003772bdccf2d6b980182d84dd055942
2025-01-07 16:31:22 UTC to 2025-01-06 17:17:15 UTC
- Add spec identifiers to dynamically-sized-types.md (rust-lang/reference#1582)
- fix typo in a "rule" name in type-coercions.md (rust-lang/reference#1708)
- Fix unclosed `<sup>` elements (rust-lang/reference#1709)
## rust-lang/rust-by-example
2 commits in 093397535b48ae13ec76bc526b7e6eb8c096a85c..054259ed1bf01cdee4309ee764c7e103f6df3de5
2025-01-13 10:44:04 UTC to 2025-01-03 18:59:26 UTC
- Fix function name in new_types.md in Japanese (rust-lang/rust-by-example#1907)
- Fix typo in static_lifetime.md (rust-lang/rust-by-example#1905)
Make sure to mark `IMPL_TRAIT_REDUNDANT_CAPTURES` as `Allow` in edition 2024
I never got sign-off on #127672 for this lint being warn by default in edition 2024, so let's turn downgrade this lint to allow for now.
Should be backported so it ships with the edition.
```@rustbot``` label: +beta-nominated
uefi: helpers: Introduce OwnedDevicePath
This PR is split off from #135368 to reduce noise.
No real functionality changes, just some quality of life improvements.
Also implement Debug for OwnedDevicePath for some quality of life
improvements.
Re-added regression test for #122638
Re-adds the test for #122638😄fixes#122638
r? `@BoxyUwU`
(please let me know if this can be improved. I am still fairly new to using compiletest)
Detect `mut arg: &Ty` meant to be `arg: &mut Ty` and provide structured suggestion
When a newcomer attempts to use an "out parameter" using borrows, they sometimes get confused and instead of mutating the borrow they try to mutate the function-local binding instead. This leads to either type errors (due to assigning an owned value to a mutable binding of reference type) or a multitude of lifetime errors and unused binding warnings.
This change adds a suggestion to the type error
```
error[E0308]: mismatched types
--> $DIR/mut-arg-of-borrowed-type-meant-to-be-arg-of-mut-borrow.rs:6:14
|
LL | fn change_object(mut object: &Object) {
| ------- expected due to this parameter type
LL | let object2 = Object;
LL | object = object2;
| ^^^^^^^ expected `&Object`, found `Object`
|
help: you might have meant to mutate the pointed at value being passed in, instead of changing the reference in the local binding
|
LL ~ fn change_object(object: &mut Object) {
LL | let object2 = Object;
LL ~ *object = object2;
|
```
and to the unused assignment lint
```
error: value assigned to `object` is never read
--> $DIR/mut-arg-of-borrowed-type-meant-to-be-arg-of-mut-borrow.rs:11:5
|
LL | object = &object2;
| ^^^^^^
|
note: the lint level is defined here
--> $DIR/mut-arg-of-borrowed-type-meant-to-be-arg-of-mut-borrow.rs:1:9
|
LL | #![deny(unused_assignments, unused_variables)]
| ^^^^^^^^^^^^^^^^^^
help: you might have meant to mutate the pointed at value being passed in, instead of changing the reference in the local binding
|
LL ~ fn change_object2(object: &mut Object) {
LL | let object2 = Object;
LL ~ *object = object2;
|
```
Fix#112357.
Fix cycle error only occurring with -Zdump-mir
fixes#134205
During mir dumping, we evaluate static items to render their allocations. If a static item refers to itself, its own MIR will have a reference to itself, so during mir dumping we end up evaluating the static again, causing us to try to build MIR again (mir dumping happens during MIR building).
Thus I disabled evaluation of statics during MIR dumps in case the MIR body isn't far enough along yet to be able to be guaranteed cycle free.
If we build the standard library with wasm-eh then we need to link
with `-fwasm-exceptions` even if we compile with `panic=abort`
Without this change, linking a `panic=abort` crate fails with:
`undefined symbol: __cpp_exception`.
Followup to #131830.
llvm/llvm-project#122530 changes LLVM to use sized-word rather than
ymmword for scatter gather pointers. While this will not always be
qword, it is for these two tests.