2375 Commits

Author SHA1 Message Date
bors
e61dd437f3 Auto merge of #143074 - compiler-errors:rollup-cv64hdh, r=compiler-errors
Rollup of 18 pull requests

Successful merges:

 - rust-lang/rust#137843 (make RefCell unstably const)
 - rust-lang/rust#140942 (const-eval: allow constants to refer to mutable/external memory, but reject such constants as patterns)
 - rust-lang/rust#142549 (small iter.intersperse.fold() optimization)
 - rust-lang/rust#142637 (Remove some glob imports from the type system)
 - rust-lang/rust#142647 ([perf] Compute hard errors without diagnostics in impl_intersection_has_impossible_obligation)
 - rust-lang/rust#142700 (Remove incorrect comments in `Weak`)
 - rust-lang/rust#142927 (Add note to `find_const_ty_from_env`)
 - rust-lang/rust#142967 (Fix RwLock::try_write documentation for WouldBlock condition)
 - rust-lang/rust#142986 (Port `#[export_name]` to the new attribute parsing infrastructure)
 - rust-lang/rust#143001 (Rename run always )
 - rust-lang/rust#143010 (Update `browser-ui-test` version to `0.20.7`)
 - rust-lang/rust#143015 (Add `sym::macro_pin` diagnostic item for `core::pin::pin!()`)
 - rust-lang/rust#143033 (Expand const-stabilized API links in relnotes)
 - rust-lang/rust#143041 (Remove cache for citool)
 - rust-lang/rust#143056 (Move an ACE test out of the GCI directory)
 - rust-lang/rust#143059 (Fix 1.88 relnotes)
 - rust-lang/rust#143067 (Tracking issue number for `iter_macro`)
 - rust-lang/rust#143073 (Fix some fixmes that were waiting for let chains)

Failed merges:

 - rust-lang/rust#143020 (codegen_fn_attrs: make comment more precise)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-06-27 00:44:20 +00:00
Michael Goulet
48d311898b
Rollup merge of #142637 - compiler-errors:less-globs, r=lcnr
Remove some glob imports from the type system

Namely, remove the glob imports for `BoundRegionConversionTime`, `RegionVariableOrigin`, `SubregionOrigin`, `TyOrConstInferVar`, `RegionResolutionError`, `SelectionError`, `ProjectionCandidate`, `ProjectionCandidateSet`, and some more specific scoped globs (like `Inserted` in the impl overlap graph construction.

These glob imports are IMO very low value, since they're not used nearly as often as other globs (like `TyKind`).
2025-06-26 20:15:19 -04:00
Matthias Krüger
aa8ba54caf
Rollup merge of #124595 - estebank:issue-104232, r=davidtwco
Suggest cloning `Arc` moved into closure

```
error[E0382]: borrow of moved value: `x`
  --> $DIR/moves-based-on-type-capture-clause-bad.rs:9:20
   |
LL |     let x = "Hello world!".to_string();
   |         - move occurs because `x` has type `String`, which does not implement the `Copy` trait
LL |     thread::spawn(move || {
   |                   ------- value moved into closure here
LL |         println!("{}", x);
   |                        - variable moved due to use in closure
LL |     });
LL |     println!("{}", x);
   |                    ^ value borrowed here after move
   |
   = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider cloning the value before moving it into the closure
   |
LL ~     let value = x.clone();
LL ~     thread::spawn(move || {
LL ~         println!("{}", value);
   |
```

Fix rust-lang/rust#104232.
2025-06-26 15:47:16 +02:00
Jana Dönszelmann
63c5a84b74
Rollup merge of #142724 - xizheyin:avoid_overwrite_args, r=oli-obk
Add runtime check to avoid overwrite arg in `Diag`

## Origin PR description
At first, I set up a `debug_assert` check for the arg method to make sure that `args` in `Diag` aren't easily overwritten, and I added the `remove_arg()` method, so that if you do need to overwrite an arg, then you can explicitly call `remove_arg()` to remove it first, then call `arg()` to overwrite it.

For the code before the rust-lang/rust#142015 change, it won't compile because it will report an error
```
arg `instance`already exists.
```

This PR also modifies all diagnostics that fail the check to pass the check. There are two cases of check failure:

1. ~~Between *the parent diagnostic and the subdiagnostic*, or *between the subdiagnostics* have the same field between them. In this case, I renamed the conflicting fields.~~
2. ~~For subdiagnostics stored in `Vec`, the rendering may iteratively write the same arg over and over again. In this case, I changed the auto-generation with `derive(SubDiagnostic)` to manually implementing `SubDiagnostic` and manually rendered it with `eagerly_translate()`, similar to https://github.com/rust-lang/rust/issues/142031#issuecomment-2984812090, and after rendering it I manually deleted useless arg with the newly added `remove_arg` method.~~

## Final Decision

After trying and discussing, we made a final decision.

For `#[derive(Subdiagnostic)]`, This PR made two changes:

1. After the subdiagnostic is rendered, remove all args of this subdiagnostic, which allows for usage like `Vec<Subdiag>`.
2. Store `diag.args` before setting arguments, so that you can restore the contents of the main diagnostic after deleting the arguments after subdiagnostic is rendered, to avoid deleting the main diagnostic's arg when they have the same name args.
2025-06-25 22:14:55 +02:00
Michael Goulet
c995070b6a rename RegionVariableOrigin::MiscVariable to RegionVariableOrigin::Misc 2025-06-25 15:35:18 +00:00
Michael Goulet
44254c8cd7 Remove some glob imports from the type system 2025-06-25 15:35:16 +00:00
xizheyin
d2d17c60bd
Add runtime check to avoid overwrite arg easily in diag and store and restore snapshot when set subdiag arg
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-06-25 21:07:16 +08:00
Esteban Küber
904652b2d0 Suggest cloning Arc moved into closure
```
error[E0382]: borrow of moved value: `x`
  --> $DIR/moves-based-on-type-capture-clause-bad.rs:9:20
   |
LL |     let x = "Hello world!".to_string();
   |         - move occurs because `x` has type `String`, which does not implement the `Copy` trait
LL |     thread::spawn(move || {
   |                   ------- value moved into closure here
LL |         println!("{}", x);
   |                        - variable moved due to use in closure
LL |     });
LL |     println!("{}", x);
   |                    ^ value borrowed here after move
   |
   = note: this error originates in the macro `$crate::format_args_nl` which comes from the expansion of the macro `println` (in Nightly builds, run with -Z macro-backtrace for more info)
help: consider cloning the value before moving it into the closure
   |
LL ~     let value = x.clone();
LL ~     thread::spawn(move || {
LL ~         println!("{}", value);
   |
```
2025-06-24 18:44:41 +00:00
Kornel
d18a43c3ac
Init local_names lazily for borrowck diagnostics 2025-06-22 17:16:36 +01:00
Kornel
a7baff819d
Avoid panic when debug info is missing 2025-06-22 17:00:09 +01:00
Mara Bos
b4f2cac097 Remove old format_args diagnostic. 2025-06-19 14:08:29 +02:00
Urgau
994794a50b Handle same-crate macro for borrowck semicolon suggestion 2025-06-16 19:58:01 +02:00
bors
e314b97ee5 Auto merge of #142550 - fmease:rollup-fteyzcv, r=fmease
Rollup of 10 pull requests

Successful merges:

 - rust-lang/rust#133952 (Remove wasm legacy abi)
 - rust-lang/rust#134661 (Reduce precedence of expressions that have an outer attr)
 - rust-lang/rust#141769 (Move metadata object generation for dylibs to the linker code )
 - rust-lang/rust#141937 (Report never type lints in dependencies)
 - rust-lang/rust#142347 (Async drop - fix for StorageLive/StorageDead codegen for pinned future)
 - rust-lang/rust#142389 (Apply ABI attributes on return types in `rustc_codegen_cranelift`)
 - rust-lang/rust#142470 (Add some missing mailmap entries)
 - rust-lang/rust#142481 (Add `f16` inline asm support for LoongArch)
 - rust-lang/rust#142499 (Remove check run bootstrap)
 - rust-lang/rust#142543 (Suggest adding semicolon in user code rather than macro impl details)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-06-16 00:39:47 +00:00
León Orell Valerian Liehr
07048643dd
Rollup merge of #142543 - Urgau:span-borrowck-semicolon, r=fmease
Suggest adding semicolon in user code rather than macro impl details

This PR tries to find the right span (by peeling expansion) so that the suggestion for adding a semicolon is suggested in user code rather than in the expanded code (in the example a macro impl).

Fixes rust-lang/rust#139049
r? `@fmease`
2025-06-15 23:51:58 +02:00
bors
f768dc01da Auto merge of #142471 - lqd:sparse-borrows, r=nnethercote
use `MixedBitSet` for borrows-in-scope dataflow analysis

The `Borrows` dataflow analysis uses a dense bitset, but a bitset supporting _some_ amount of sparseness is better suited for big functions with a big number of loans.

The cutoff between dense and chunked bitset is around 2K loans IIRC, and we could finesse that value if we wanted to, but as-is it happens to a couple of rustc-perf benchmarks (which IIRC are at least partially generated from macros and the likes.). It's a small win on these two, and shouldn't have any impact on the others.

r? `@matthewjasper`
2025-06-15 21:38:13 +00:00
Urgau
6ff3713e0f Suggest adding semicolon in user code rather than macro impl details 2025-06-15 20:03:46 +02:00
Matthias Krüger
db23a76217
Rollup merge of #141811 - mejrs:bye_locals, r=compiler-errors
Unimplement unsized_locals

Implements https://github.com/rust-lang/compiler-team/issues/630

Tracking issue here: https://github.com/rust-lang/rust/issues/111942

Note that this just removes the feature, not the implementation, and does not touch `unsized_fn_params`. This is because it is required to support `Box<dyn FnOnce()>: FnOnce()`.

There may be more that should be removed (possibly in follow up prs)
- the `forget_unsized` function and `forget` intrinsic.
- the `unsized_locals` test directory; I've just fixed up the tests for now
- various codegen support for unsized values and allocas

cc ``@JakobDegen`` ``@oli-obk`` ``@Noratrieb`` ``@programmerjake`` ``@bjorn3``

``@rustbot`` label F-unsized_locals

Fixes rust-lang/rust#79409
2025-06-14 11:27:10 +02:00
Rémy Rakic
2554f8f74d use MixedBitSet for borrows-in-scope computation
Some code can have a few thousand loans, and this bitset is better
suited to these somewhat sparse cases.

That includes a couple of rustc-perf benchmarks.
2025-06-13 18:01:32 +00:00
mejrs
c0e02e26b3 Unimplement unsized_locals 2025-06-13 01:16:36 +02:00
Matthias Krüger
bfd8abd8f3
Rollup merge of #141069 - chenyukang:yukang-fix-137486-suggest-mut, r=davidtwco
Suggest mut when possbile for temporary value dropped while borrowed

Fixes #137486
2025-06-12 22:09:41 +02:00
bors
bdb04d6c4f Auto merge of #141763 - lcnr:fixme-gamer, r=BoxyUwU
`FIXME(-Znext-solver)` triage

r? `@BoxyUwU`
2025-06-11 11:47:05 +00:00
Matthias Krüger
c1d1f7a16f
Rollup merge of #142012 - oli-obk:no-optional-spans, r=fee1-dead
Replace some `Option<Span>` with `Span` and use DUMMY_SP instead of None

Turns out many locations actually have a span available that we could use, so I used it
2025-06-06 00:58:44 +02:00
Oli Scherer
fd3da4bebd Replace some Option<Span> with Span and use DUMMY_SP instead of None 2025-06-05 14:14:59 +00:00
bors
425e142686 Auto merge of #140466 - amandasystems:move-to-preprocessing-step, r=lcnr
Move placeholder handling to a proper preprocessing step

This commit breaks out the logic of placheolder rewriting into its own preprocessing step. It's one of the more boring
parts of #130227.

The only functional change from this is that the preprocessing step (where extra `r: 'static` constraints are added) is performed upstream of Polonius legacy, finally affecting Polonius. That is mostly a by-product, though.

This should be reviewable by anyone in the compiler team, so
r? rust-lang/compiler
2025-06-05 05:27:41 +00:00
Mara Bos
fcfa9b0ba0 Don't refer to 'local binding' in extern macro.
The user has no clue what 'local binding' the compiler is talking about,
if they don't know the expansion of the macro.
2025-06-04 15:07:47 +02:00
Amanda Stjerna
f455c4fc39 Use an enum for SCC representatives, plus other code review
Co-authored-by: lcnr <rust@lcnr.de>
2025-06-04 13:26:08 +02:00
Oli Scherer
5fbdfc3e10
Add iter macro
This adds an `iter!` macro that can be used to create movable
generators.

This also adds a yield_expr feature so the `yield` keyword can be used
within iter! macro bodies. This was needed because several unstable
features each need `yield` expressions, so this allows us to stabilize
them separately from any individual feature.

Co-authored-by: Oli Scherer <github35764891676564198441@oli-obk.de>
Co-authored-by: Jieyou Xu <jieyouxu@outlook.com>
Co-authored-by: Travis Cross <tc@traviscross.com>
2025-06-03 10:52:32 -07:00
lcnr
7dac755be8 FIXME(-Znext-solver) triage
Co-authored-by: Michael Goulet <michael@errs.io>
2025-06-03 14:23:56 +02:00
Amanda Stjerna
aca36fd12a Move placeholder handling to a proper preprocessing step
This commit breaks out the logic of placheolder rewriting
into its own preprocessing step.

The only functional change from this is that the preprocessing
step (where extra `r: 'static` constraints are added) is
performed upstream of Polonius legacy, finally affecting
Polonius. That is mostly a by-product, though.
2025-06-03 12:20:15 +02:00
Matthias Krüger
f3622ead6e
Rollup merge of #141891 - jdonszelmann:fix-141764, r=jieyouxu
Fix borrowck mentioning a name from an external macro we (deliberately) don't save

Most of the info is already in the title 🤷

Closes rust-lang/rust#141764
2025-06-03 07:03:46 +02:00
Jana Dönszelmann
2e527f03d1
fix bug where borrowck tries to describe a name from a macro in another crate 2025-06-02 11:29:27 +02:00
Guillaume Gomez
b0b98a078d
Rollup merge of #141823 - amandasystems:reverse_scc_graph_once_cell, r=jieyouxu
Drive-by refactor: use `OnceCell` for the reverse region SCC graph

During region inference, the reverse SCC region graph is sometimes computed lazily. This changes the implementation for that from using an `Option` to a `OnceCell` which clearly communicates the intention and simplifies the code somewhat.

There shouldn't be any performance impact, except that this pulls the computation of the reverse SCC graph slightly later than before, and so may avoid computing it in some instances.

Note that this changes a mutable reference into an immutable (interior mutable) one.
2025-06-01 19:35:44 +02:00
Amanda Stjerna
95115b907b Drive-by refactor: use OnceCell for the reverse region SCC graph 2025-05-31 17:46:07 +02:00
bors
ec28ae9454 Auto merge of #141667 - lqd:lazy-maybe-init, r=matthewjasper
Add fast path for maybe-initializedness in liveness

r? `@matthewjasper`

Correct me if I'm wrong Matthew, but my understanding is that
1. `MaybeInitializedPlaces` is currently eagerly computed, in `do_mir_borrowck`
2. but this data is only used in liveness
3. and `liveness::trace` actually only uses it for drop-liveness

This PR moves the computation to `liveness::trace` which looks to be its only use-site. We also add a fast path there, so that it's only computed by drop-liveness.

This is interesting because 1) liveness is only computed for relevant live locals, 2) drop-liveness is only computed for relevant live locals with >0 drop points; 0 is the common case from our benchmarks, as far as I can tell, so even just computing the entire data lazily helps.

It seems possible to also reduce the domain here, and speed up the analysis for the cases where it has to be computed -- so I've left a fixme for that, and may look into it soon.

(I've come upon this while doing implementation work for polonius, so don't be too enamored with possible wins: the goal is to reduce the eventual polonius overhead and make it more palatable 😓)
2025-05-31 04:52:37 +00:00
Michael Goulet
9871e160ea Normalize possibly unnormalized type in relate_type_and_user_type 2025-05-29 11:20:45 +00:00
Michael Goulet
2a339ce492 Structurally normalize types as needed in projection_ty_core 2025-05-29 11:16:44 +00:00
Rémy Rakic
703e051f36 add perf fixme for MaybeInitializedPlaces domain 2025-05-27 21:21:28 +00:00
Rémy Rakic
430e230449 fast path: compute MaybeInitializedPlaces lazily
Only drop-liveness checks for maybe-initializedness of move paths, and
it does so only for the relevant live locals that have drop points.

This adds a fast path by computing this dataflow analysis only when checking for such
initializedness. This avoids this expensive computation for the common
case.

For example, it avoids computing initializedness for 20K locals in the
`cranelift-codegen` benchmark, it has 7K relevant live locals but none
with drop points. That saves 900ms on end-to-end compilation times.
2025-05-27 21:21:28 +00:00
Rémy Rakic
10d39f52a9 remove unneeded lifetime 2025-05-27 21:21:28 +00:00
Rémy Rakic
45197887cb move MaybeInitializedPlaces computation to where it's used
This dataflow analysis is only used by `liveness::trace`. We move it
there to make it lazy.
2025-05-27 21:21:28 +00:00
yukang
d5d4cecee9 Suggest mut when possbile for temporary value dropped while borrowed 2025-05-27 22:19:56 +08:00
Michael Goulet
5f3ae06db0 Fix some var names 2025-05-27 11:14:47 +00:00
Michael Goulet
29c3babd7c Rename unpack to kind 2025-05-27 11:14:45 +00:00
Matthias Krüger
706dc70916
Rollup merge of #139668 - matthewjasper:upper-bound-fix, r=compiler-errors
Handle regions equivalent to 'static in non_local_bounds

`non_local_bounds` would only find non local bounds that strictly bound a given region, but it's possible that a local region is equated to 'static when showing a type referencing a locally bound lifetime, such as `dyn Any + 'a` in the tests added, is well-formed. In this case we should return 'static.

closes #122704
closes #139004
2025-05-22 16:02:26 +02:00
Matthias Krüger
d0ea342440
Rollup merge of #140947 - compiler-errors:pending-norm, r=lcnr
Flush errors before deep normalize in `dropck_outlives`

Deep normalization doesn't allow the ocx to have pending obligations, so process them before deeply normalizing.

Fixes https://github.com/rust-lang/rust/issues/140931
Fixes https://github.com/rust-lang/rust/issues/140462
2025-05-15 22:28:51 +02:00
Michael Goulet
a508011b1f Expect deep norm to fail if query norm failed 2025-05-13 09:18:17 +00:00
Pietro Albini
2ce08ca5d6
update cfg(bootstrap) 2025-05-12 15:33:37 +02:00
Matthias Krüger
8a3ab85e7d
Rollup merge of #140260 - compiler-errors:only-global-post-norm, r=lcnr
Only prefer param-env candidates if they remain non-global after norm

Introduce `CandidateSource::GlobalParamEnv`, and dynamically compute the `CandidateSource` based on whether the predicate contains params *post-normalization*.

This code needs some cleanup and documentation. I'm just putting this up for review.

cc https://github.com/rust-lang/trait-system-refactor-initiative/issues/179

r? lcnr
2025-05-08 08:14:16 +02:00
bors
ae3e8c6191 Auto merge of #140751 - GuillaumeGomez:rollup-eahw4ta, r=GuillaumeGomez
Rollup of 8 pull requests

Successful merges:

 - #140234 (Separate dataflow analysis and results)
 - #140614 (Correct warning message in restricted visibility)
 - #140671 (Parser: Recover error from named params while parse_path)
 - #140700 (Don't crash on error codes passed to `--explain` which exceed our internal limit of 9999 )
 - #140706 ([rustdoc] Ensure that temporary doctest folder is correctly removed even if doctests failed)
 - #140734 (Fix regression from #140393 for espidf / horizon / nuttx / vita)
 - #140741 (add armv5te-unknown-linux-gnueabi target maintainer)
 - #140745 (run-make-support: set rustc dylib path for cargo wrapper)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-05-07 23:03:25 +00:00
bors
e9f8103f93 Auto merge of #140590 - lcnr:closure-in-dead-code, r=compiler-errors
borrowck nested items in dead code

fixes https://github.com/rust-lang/rust/issues/140583

r? `@compiler-errors`
2025-05-07 19:49:36 +00:00