Commit Graph

19780 Commits

Author SHA1 Message Date
Trevor Gross
75ed6de1ee Rollup merge of #143698 - benschulz:unused-parens-2, r=lcnr,compiler-errors
Fix unused_parens false positive

Resolves rust-lang/rust#143653.

The "no bounds exception" was indiscriminately set to `OneBound` for referents and pointees. However, if the reference or pointer type itself appears in no-bounds position, any constraints it has must be propagated.

```rust
// unused parens: not in no-bounds position
fn foo(_: Box<(dyn Send)>) {}

// unused parens: in no-bounds position, but one-bound exception applies
fn bar(_: Box<dyn Fn(&u32) -> &(dyn Send)>) {}

// *NOT* unused parens: in no-bounds position, but no exceptions to be made
fn baz(_: Box<dyn Fn(&u32) -> &(dyn Send) + Send>) {}
```
2025-07-26 02:19:28 -05:00
Trevor Gross
d8f4ceb8c0 Rollup merge of #143585 - folkertdev:loop-match-suggest-const-block, r=oli-obk
`loop_match`: suggest extracting to a `const` item

tracking issue: https://github.com/rust-lang/rust/issues/132306
fixes https://github.com/rust-lang/rust/issues/143310
fixes https://github.com/rust-lang/rust/issues/143936
2025-07-26 02:19:28 -05:00
Trevor Gross
33ed3fc07f Rollup merge of #140871 - Amanieu:naked-asm-label, r=compiler-errors
Don't lint against named labels in `naked_asm!`

Naked functions are allowed to define global labels, just like `global_asm!`.
2025-07-26 02:19:26 -05:00
Amanieu d'Antras
1f4561b63d Don't lint against named labels in naked_asm!
Naked functions are allowed to define global labels, just like
`global_asm!`.
2025-07-26 00:42:21 +01:00
Folkert de Vries
730d33dd64 loop_match: suggest extracting to a const item
if the expression cannot be evaluated in a straightforward way
2025-07-26 00:10:56 +02:00
Matthias Krüger
acd4a1ccd2 Rollup merge of #144390 - oli-obk:arbitrary-enum-discrs, r=SparrowLii
Remove dead code and extend test coverage and diagnostics around it

I was staring a bit at the `dont_niche_optimize_enum` variable and figured out that part of it is dead code (at least today it is). I changed the diagnostic and test around the code that makes that part dead code, so everything that makes removing that code sound is visible in this PR
2025-07-25 11:16:39 +02:00
Matthias Krüger
405b2e6c06 Rollup merge of #144340 - Oneirical:uncertain-illusion, r=jieyouxu
UI test suite clarity changes: Rename `tests/ui/SUMMARY.md` and update rustc dev guide on `error-pattern`

To match convention, rename `tests/ui/SUMMARY.md` to `tests/ui/README.md`.

Also, remove misleading lines in the rustc development guide about `error-pattern` being "not recommended", when it really is just a last resort which *should* be used in the niche situations where it is useful.

r? ````@jieyouxu````
2025-07-25 11:16:38 +02:00
Matthias Krüger
f414e7ac54 Rollup merge of #144209 - scottmcm:assume_less, r=lcnr,dianqk
Don't emit two `assume`s in transmutes when one is a subset of the other

For example, transmuting between `bool` and `Ordering` doesn't need two `assume`s because one range is a superset of the other.

Multiple are still used for things like `char` <-> `NonZero<u32>`, which overlap but where neither fully contains the other.
2025-07-25 11:16:36 +02:00
Matthias Krüger
33a9e4f821 Rollup merge of #144200 - estebank:dont-point-at-closure, r=lcnr
Tweak output for non-`Clone` values moved into closures

When we encounter a non-`Clone` value being moved into a closure, try to find the corresponding type of the binding being moved, if it is a `let`-binding or a function parameter. If any of those cases, we point at them with the note explaining that the type is not `Copy`, instead of giving that label to the place where it is captured. When it is a `let`-binding with no explicit type, we point at the initializer (if it fits in a single line).

```
error[E0507]: cannot move out of `foo`, a captured variable in an `Fn` closure
  --> f111.rs:14:25
   |
13 | fn do_stuff(foo: Option<Foo>) {
   |             ---  ----------- move occurs because `foo` has type `Option<Foo>`, which does not implement the `Copy` trait
   |             |
   |             captured outer variable
14 |     require_fn_trait(|| async {
   |                      -- ^^^^^ `foo` is moved here
   |                      |
   |                      captured by this `Fn` closure
15 |         if foo.map_or(false, |f| f.foo()) {
   |            --- variable moved due to use in coroutine
```

instead of

```
error[E0507]: cannot move out of `foo`, a captured variable in an `Fn` closure
  --> f111.rs:14:25
   |
13 | fn do_stuff(foo: Option<Foo>) {
   |             --- captured outer variable
14 |     require_fn_trait(|| async {
   |                      -- ^^^^^ `foo` is moved here
   |                      |
   |                      captured by this `Fn` closure
15 |         if foo.map_or(false, |f| f.foo()) {
   |            ---
   |            |
   |            variable moved due to use in coroutine
   |            move occurs because `foo` has type `Option<Foo>`, which does not implement the `Copy` trait
```
2025-07-25 11:16:36 +02:00
Matthias Krüger
dfbd0c4e5a Rollup merge of #143979 - dpaoliello:arm64ectest, r=petrochenkov
Test fixes for Arm64EC Windows

* `tests/ui/cfg/conditional-compile-arch.rs` needs an Arm64EC case.
* `tests/ui/runtime/backtrace-debuginfo.rs` should skip Arm64EC as it suffers from the same truncated backtraces as Arm64 Windows.
* `tests/ui/linkage-attr/incompatible-flavor.rs` is a general issue: it assumes that the Rust compiler is always built with the x86 target enabled in the backend, but I only enabled AArch64 when building locally to speed up the LLVM compilation.
2025-07-25 11:16:35 +02:00
Matthias Krüger
e9744c9ec1 Rollup merge of #143401 - Enselic:no-stack-backtrace-print-in-display, r=davidtwco
tests: Don't check for self-printed output in std-backtrace.rs test

The `Display` implementation for `Backtrace` used to print

    stack backtrace:

but that print was since removed. See https://github.com/rust-lang/backtrace-rs/pull/286 and https://github.com/rust-lang/rust/pull/69042. To make the existing test pass, the print was added to the test instead. But it doesn't make sense to check for something that the test itself does since that will not detect any regressions in the implementation of `Backtrace`.

What the test _should_ check is that "stack backtrace:" is _not_ printed in `Display` of `Backtrace`. So do that instead.

This is one small steps towards resolving https://github.com/rust-lang/rust/issues/71706. The next steps after this step involves extending and hardening that test further.
2025-07-25 11:16:33 +02:00
Matthias Krüger
2e54f7f0a1 Rollup merge of #142569 - xizheyin:139253, r=davidtwco
Suggest clone in user-write-code instead of inside macro

Fixes rust-lang/rust#139253

Inspired by rust-lang/rust#142543

r? ````@fmease````
2025-07-25 11:16:32 +02:00
Oneirical
94c0cf891e Rename tests/ui/SUMMARY.md and update rustc dev guide on error-pattern 2025-07-24 17:09:42 -04:00
bors
b56aaec52b Auto merge of #144389 - scottmcm:no-more-mir-cast-assume, r=davidtwco
MIR-build: No longer emit assumes in enum-as casting

This just uses the `valid_range` from the backend, so it's duplicating the range metadata that now we include on parameters and loads, and thus no longer seems to be useful -- notably there's no codegen test failures from removing it.

(Because it's using data from the same source as the backend annotations, it doesn't do anything to mitigate things like rust-lang/rust#144388 where the range in the layout is more permissive than the actual possible discriminants.  A variant of this that actually checked the discriminants more specifically might be useful, so could potentially be added in future, but I don't think the *current* checks are actually providing value.)

r? mir

Randomly turns out that this
Fixes https://github.com/rust-lang/rust/issues/121097
2025-07-24 20:38:53 +00:00
Ben Schulz
6fc68c16e7 Add test case for single bound 2025-07-24 20:44:10 +02:00
Ben Schulz
e958b20af7 Fix unused_parens false positive 2025-07-24 20:44:09 +02:00
Scott McMurray
01524abb05 MIR-build: No longer emit assumes in enum-as casting
This just uses the `valid_range` from the backend, so it's duplicating the range metadata that now we include on parameters and loads.
2025-07-24 10:18:37 -07:00
León Orell Valerian Liehr
6dc41520e9 Rollup merge of #144358 - JonathanBrouwer:fix-stability-malformed, r=oli-obk
Stop using the old `validate_attr` logic for stability attributes

I think this was accidentally missed when implementing the stability attributes?

r? `````@oli-obk`````
cc `````@jdonszelmann`````
2025-07-24 15:08:28 +02:00
León Orell Valerian Liehr
237098c92d Rollup merge of #144335 - fmease:no-angle-no-colon, r=SparrowLii
Don't suggest assoc ty bound on non-angle-bracketed problematic assoc ty binding

Fixes https://github.com/rust-lang/rust/issues/140543.
2025-07-24 15:08:28 +02:00
León Orell Valerian Liehr
ac4ffdce9a Rollup merge of #144276 - cjgillot:no-hir-privacy, r=petrochenkov
Use less HIR in check_private_in_public.

r? ````````@petrochenkov````````
2025-07-24 15:08:25 +02:00
León Orell Valerian Liehr
3d82cccab4 Rollup merge of #144240 - yuk1ty:false-sealed-traits-note-reported-in-another-issue, r=fee1-dead
Add more test case to check if the false note related to sealed trait suppressed

Closes rust-lang/rust#143121

I started to fix the issue but I found that this one has already been addressed in this PR (https://github.com/rust-lang/rust/pull/143431). I added an additional test to prove the reported thing has been resolved just in case.

I think we can discard this pull request if there's no need to add such kind of tests👍🏻
2025-07-24 15:08:23 +02:00
León Orell Valerian Liehr
cdca384e40 Rollup merge of #144221 - usamoi:versym, r=bjorn3
generate elf symbol version in raw-dylib

For link names like `aaa@bbb`, it generates a symbol named `aaa` and a version named `bbb`.

For link names like `aaa\0bbb`, `aaa@`@bbb`` or `aa@bb@cc`, it emits errors.

It adds a test that the executable is linked with glibc using raw-dylib.

cc rust-lang/rust#135694
2025-07-24 15:08:23 +02:00
León Orell Valerian Liehr
2a8bb6eda1 Rollup merge of #144218 - Noratrieb:target-spec-json-de-jank, r=fee1-dead
Use serde for target spec json deserialize

The previous manual parsing of `serde_json::Value` was a lot of complicated code and extremely error-prone. It was full of janky behavior like sometimes ignoring type errors, sometimes erroring for type errors, sometimes warning for type errors, and sometimes just ICEing for type errors (the icing on the top).

Additionally, many of the error messages about allowed values were out of date because they were in a completely different place than the FromStr impls. Overall, the system caused confusion for users.

I also found the old deserialization code annoying to read. Whenever a `key!` invocation was found, one had to first look for the right macro arm, and no go to definition could help.

This PR replaces all this manual parsing with a 2-step process involving serde.
First, the string is parsed into a `TargetSpecJson` struct. This struct is a 1:1 representation of the spec JSON. It already parses all the enums and is very simple to read and write.
Then, the fields from this struct are copied into the actual `Target`. The reason for this two-step process instead of just serializing into a `Target` is because of a few reasons

 1. There are a few transformations performed between the two formats
 2. The default logic is implemented this way. Otherwise all the default field values would have to be spelled out again, which is suboptimal. With this logic, they fall out naturally, because everything in the json struct is an `Option`.

Overall, the mapping is pretty simple, with the vast majority of fields just doing a 1:1 mapping that is captured by two macros. I have deliberately avoided making the macros generic to keep them simple.

All the `FromStr` impls now have the error message right inside them, which increases the chance of it being up to date. Some "`from_str`" impls were turned into proper `FromStr` impls to support this.

The new code is much less involved, delegating all the JSON parsing logic to serde, without any manual type matching.

This change introduces a few breaking changes for consumers. While it is possible to use this format on stable, it is very much subject to change, so breaking changes are expected. The hope is also that because of the way stricter behavior, breaking changes are easier to deal with, as they come with clearer error messages.

1. Invalid types now always error, everywhere. Previously, they would sometimes error, and sometimes just be ignored (which meant the users JSON was still broken, just silently!)
2. This now makes use of `deny_unknown_fields` instead of just warning on unused fields, which was done previously. Serde doesn't make it easy to get such warning behavior, which was the primary reason that this now changed. But I think error behavior is very reasonable too. If someone has random stale fields in their JSON, it is likely because these fields did something at some point but no longer do, and the user likely wants to be informed of this so they can figure out what to do.

   This is also relevant for the future. If we remove a field but someone has it set, it probably makes sense for them to take a look whether they need this and should look for alternatives, or whether they can just delete it. Overall, the JSON is made more explicit.

This is the only expected breakage, but there could also be small breakage from small mistakes. All targets roundtrip though, so it can't be anything too major.

fixes rust-lang/rust#144153
2025-07-24 15:08:22 +02:00
León Orell Valerian Liehr
40482a2ffa Rollup merge of #144094 - saethlin:codegen-the-main-fn, r=petrochenkov
Ensure we codegen the main fn

This fixes two bugs. The one that was identified in the linked issue is that when we have a `main` function, mono collection didn't consider it as an extra collection root.

The other is that since CGU partitioning doesn't  know about the call edges between the entrypoint functions, naively it can put them in different CGUs and mark them all as internal. Which would result in LLVM just deleting all of them. There was an existing hack to exclude `lang = "start"` from internalization, which I've extended to include `main`.

Fixes https://github.com/rust-lang/rust/issues/144052
2025-07-24 15:08:21 +02:00
León Orell Valerian Liehr
940376f1b1 Rollup merge of #144014 - dianne:edition-guide-links, r=estebank
don't link to the nightly version of the Edition Guide in stable lints

As reported in rust-lang/rust#143557 for `rust_2024_incompatible_pat`, most future-Edition-incompatibility lints link to the nightly version of the Edition Guide; the lints were written before their respective Editions (and their guides) stabilized. But now that Rusts 2021 and 2024 are stable, these lints are emitted on stable versions of the compiler, where it makes more sense to present users with links that don't say "nightly" in them.

This does not change the link for `rust_2024_incompatible_pat`. That's handled in rust-lang/rust#144006.
2025-07-24 15:08:21 +02:00
usamoi
e31876c143 generate elf symbol version in raw-dylib 2025-07-24 19:04:00 +08:00
Oli Scherer
e44a7386c2 Remove dead code and extend test coverage and diagnostics around it
We lost the following comment during refactorings:

The current code for niche-filling relies on variant indices instead of actual discriminants, so enums with explicit discriminants (RFC 2363) would misbehave.
2025-07-24 10:21:20 +00:00
Camille GILLOT
9ff071219b Give an AllocId to ConstValue::Slice. 2025-07-23 23:54:37 +00:00
bors
ace6330903 Auto merge of #144233 - cjgillot:unsat-mir, r=oli-obk
Consider parent predicates in ImpossiblePredicates pass.

This pass is double edged. It avoids some ICEs (yay!) but also degrades diagnostics from constant evaluation.

Fixes rust-lang/rust#121363
Fixes rust-lang/rust#131507
Fixes rust-lang/rust#140100
Fixes rust-lang/rust#140365
2025-07-23 20:16:03 +00:00
bors
29a58723b0 Auto merge of #144360 - matthiaskrgr:rollup-b6ej0mm, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - rust-lang/rust#144173 (Remove tidy checks for `tests/ui/issues/`)
 - rust-lang/rust#144234 (Fix broken TLS destructors on 32-bit win7)
 - rust-lang/rust#144239 (Clean `rustc/parse/src/lexer` to improve maintainability)
 - rust-lang/rust#144256 (Don't ICE on non-TypeId metadata within TypeId)
 - rust-lang/rust#144290 (update tests/ui/SUMMARY.md)
 - rust-lang/rust#144292 (mbe: Use concrete type for `get_unused_rule`)
 - rust-lang/rust#144298 (coverage: Enlarge empty spans during MIR instrumentation, not codegen)
 - rust-lang/rust#144311 (Add powerpc64le-unknown-linux-musl to CI rustc targets)
 - rust-lang/rust#144315 (bootstrap: add package.json and package-lock.json to dist tarball)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-07-23 16:59:13 +00:00
Scott McMurray
a93a9aa2d5 Don't emit two assumes in transmutes when one is a subset of the other
For example, transmuting between `bool` and `Ordering` doesn't need two `assume`s because one range is a superset of the other.

Multiple are still used for things like `char` <-> `NonZero<u32>`, which overlap but where neither fully contains the other.
2025-07-23 09:16:32 -07:00
Esteban Küber
6237e735c4 Point at the type that doesn't impl Clone in more cases beyond closures 2025-07-23 16:04:45 +00:00
Matthias Krüger
7ec557ce72 Rollup merge of #144298 - Zalathar:empty-span, r=wesleywiser
coverage: Enlarge empty spans during MIR instrumentation, not codegen

This re-lands the part of rust-lang/rust#140847 that was (hopefully) not responsible for the coverage-instrumentation regressions that caused that PR to be reverted.

---

Enlarging empty spans was historically performed during MIR instrumentation, but had to be moved to codegen as part of larger changes in rust-lang/rust#134497, leading to the status quo. But now there should be no reason not to move that step back to its more logical home in instrumentaion.
2025-07-23 15:59:32 +02:00
Matthias Krüger
6f23c08597 Rollup merge of #144290 - makai410:summary-ups, r=jieyouxu
update tests/ui/SUMMARY.md

follow-up of rust-lang/rust#143985 .

r? ```````@jieyouxu```````
2025-07-23 15:59:31 +02:00
Matthias Krüger
16c10c9145 Rollup merge of #144256 - oli-obk:type-id-ice, r=RalfJung
Don't ICE on non-TypeId metadata within TypeId

fixes rust-lang/rust#144253

r? ``````````@RalfJung``````````
2025-07-23 15:59:30 +02:00
Jonathan Brouwer
af06bb925f Stop using the old validate_attr logic for stability attributes 2025-07-23 14:31:50 +02:00
Jonathan Brouwer
3303534dc8 Update uitest stderrs
Signed-off-by: Jonathan Brouwer <jonathantbrouwer@gmail.com>
2025-07-23 13:33:23 +02:00
León Orell Valerian Liehr
9bb9c39fa5 Don't suggest assoc ty bound on non-angle-bracketed problematic assoc ty binding 2025-07-23 01:59:25 +02:00
bors
a7a1618e6c Auto merge of #144249 - GuillaumeGomez:asm-tests, r=jieyouxu
Rename `tests/{assembly,codegen}` into `tests/{assembly,codegen}-llvm` and ignore these testsuites if configured backend doesn't match

Follow-up of https://github.com/rust-lang/rust/pull/144125.

This PR changes `compiletest` so that `asm` tests are only run if they match the current codegen backend. To better reflect it, I renamed the `tests/ui/asm` folder into `tests/ui/asm-llvm`. Like that, we can add new asm tests for other backends if we want without needing to add extra code to `compiletest`.

Next step will be to use the new code annotations added in rust-lang/rust#144125 to ignore ui tests failing in cg_gcc until it's fixed on our side.

cc `@antoyo` `@oli-obk`
r? `@Kobzol`
2025-07-22 18:39:58 +00:00
yuk1ty
0aa617001a Add a test case for ui test false-sealed-traits-note.rs 2025-07-22 23:31:10 +09:00
Guillaume Gomez
a27f3e3fd1 Rename tests/codegen into tests/codegen-llvm 2025-07-22 14:28:48 +02:00
Guillaume Gomez
ed93c1783b Rename tests/assembly into tests/assembly-llvm 2025-07-22 14:27:48 +02:00
Zalathar
f877aa7d14 coverage: Enlarge empty spans during MIR instrumentation, not codegen
This allows us to assume that coverage spans will only be discarded during
codegen in very unusual situations.
2025-07-22 19:49:54 +10:00
Matthias Krüger
749f895d95 Rollup merge of #144265 - compiler-errors:copy-ice, r=oli-obk
Dont ICE on copy error being suppressed due to overflow

See comment in test file.

Fixes https://github.com/rust-lang/rust/issues/144165
2025-07-22 10:26:16 +02:00
Matthias Krüger
cdc79bdbd9 Rollup merge of #144082 - mladedav:dm/pub-priv-tests, r=petrochenkov
tests: cover more `exported_private_dependencies` cases

This PR adds tests for all missing cases from rust-lang/rust#71043 and some on top of that. I believe with this, that issue can be closed.

Some of the lints can be improved, e.g. `provided_impl_trait` and `impl From<PublicWithStdImpl> for OtherType` lint twice.

cc ```@epage``` in case you want to double check I didn't miss anything.
2025-07-22 10:26:14 +02:00
Makai
6df15a172e update SUMMARY.md 2025-07-22 14:59:46 +08:00
Camille GILLOT
6e8762f769 Use less HIR in check_private_in_public. 2025-07-22 01:40:45 +00:00
Ben Kimock
c4eb077616 Ensure we codegen and don't internalize the entrypoint 2025-07-21 19:54:37 -04:00
Noratrieb
dad96b107c Use serde for target spec json deserialize
The previous manual parsing of `serde_json::Value` was a lot of
complicated code and extremely error-prone. It was full of janky
behavior like sometimes ignoring type errors, sometimes erroring for
type errors, sometimes warning for type errors, and sometimes just
ICEing for type errors (the icing on the top).

Additionally, many of the error messages about allowed values were out
of date because they were in a completely different place than the
FromStr impls. Overall, the system caused confusion for users.

I also found the old deserialization code annoying to read. Whenever a
`key!` invocation was found, one had to first look for the right macro
arm, and no go to definition could help.

This PR replaces all this manual parsing with a 2-step process involving
serde.
First, the string is parsed into a `TargetSpecJson` struct. This struct
is a 1:1 representation of the spec JSON. It already parses all the
enums and is very simple to read and write.
Then, the fields from this struct are copied into the actual `Target`.
The reason for this two-step process instead of just serializing into a
`Target` is because of a few reasons

 1. There are a few transformations performed between the two formats
 2. The default logic is implemented this way. Otherwise all the default
    field values would have to be spelled out again, which is
    suboptimal. With this logic, they fall out naturally, because
    everything in the json struct is an `Option`.

Overall, the mapping is pretty simple, with the vast majority of fields
just doing a 1:1 mapping that is captured by two macros. I have
deliberately avoided making the macros generic to keep them simple.

All the `FromStr` impls now have the error message right inside them,
which increases the chance of it being up to date. Some "`from_str`"
impls were turned into proper `FromStr` impls to support this.

The new code is much less involved, delegating all the JSON parsing
logic to serde, without any manual type matching.

This change introduces a few breaking changes for consumers. While it is
possible to use this format on stable, it is very much subject to
change, so breaking changes are expected. The hope is also that because
of the way stricter behavior, breaking changes are easier to deal with,
as they come with clearer error messages.

1. Invalid types now always error, everywhere. Previously, they would
   sometimes error, and sometimes just be ignored (which meant the users
   JSON was still broken, just silently!)
2. This now makes use of `deny_unknown_fields` instead of just warning
   on unused fields, which was done previously. Serde doesn't make it
   easy to get such warning behavior, which was the primary reason that
   this now changed. But I think error behavior is very reasonable too.
   If someone has random stale fields in their JSON, it is likely
   because these fields did something at some point but no longer do,
   and the user likely wants to be informed of this so they can figure
   out what to do.

   This is also relevant for the future. If we remove a field but
   someone has it set, it probably makes sense for them to take a look
   whether they need this and should look for alternatives, or whether
   they can just delete it. Overall, the JSON is made more explicit.

This is the only expected breakage, but there could also be small
breakage from small mistakes. All targets roundtrip though, so it can't
be anything too major.
2025-07-21 19:32:44 +02:00
许杰友 Jieyou Xu (Joe)
55a477efb2 Rollup merge of #144246 - jieyouxu:no-dual-test, r=lqd,RalfJung
Don't use another main test file as auxiliary

In this case, the exact extern crate isn't very important, it just needs to not be another main test file.

This is part of the changes needed to address the spurious failures from a main test `../removing-extern-crate.rs` being both an auxiliary and a main test file, causing fs races due to multiple `rustc` processes in multiple test threads trying to build the main test file both as a main test and also as an auxiliary at around the same time.

Part 1 of rust-lang/rust#144237.

r? ``@RalfJung`` (or compiler)
2025-07-22 00:54:32 +08:00