Commit Graph

19780 Commits

Author SHA1 Message Date
Boxy
bc9cdc960f Return correct error term kind on projection errors 2025-05-22 12:02:45 +01:00
Boxy
cc10370fc8 Reviews 2025-05-22 11:39:49 +01:00
Ralf Jung
3c020e59a2 make enabling the neon target feature a FCW 2025-05-22 12:19:25 +02:00
bendn
8373bb17d6 use uX::from instead of _ as uX in non - const contexts 2025-05-22 17:08:32 +07:00
bors
1d679446b0 Auto merge of #140527 - GuillaumeGomez:doctest-main-fn, r=notriddle
Emit a warning if the doctest `main` function will not be run

Fixes #140310.

I think we could try to go much further like adding a "link" (ie UI annotations) on the `main` function in the doctest. However that will require some more computation, not sure if it's worth it or not. Can still be done in a follow-up if we want it.

For now, this PR does two things:
1. Pass the `DiagCtxt` to the doctest parser to emit the warning.
2. Correctly generate the `Span` to where the doctest is starting (I hope the way I did it isn't too bad either...).

cc `@fmease`
r? `@notriddle`
2025-05-22 08:40:58 +00:00
Matthias Krüger
79f0a97783 Rollup merge of #141364 - aDotInTheVoid:atttrdocss, r=GuillaumeGomez
rustdoc-json: Remove false docs and add test for inline attribute

The docs about how `#[inline]` was represented isn't true. Updates the comment, and adds a test.

CC #137645

r? `@GuillaumeGomez`
2025-05-22 07:19:03 +02:00
Matthias Krüger
981bbf4197 Rollup merge of #140868 - SpecificProtagonist:rustdoc-trait-impl-code-link, r=notriddle
rustdoc: Fix links with inline code in trait impl docs

Fixes #140857
2025-05-22 07:19:01 +02:00
Matthias Krüger
cc87ae85dd Rollup merge of #140431 - bend-n:dont_handle_bool_transmute, r=Nadrieril
dont handle bool transmute

removes `transmute(u8) -> bool` suggestion due to ambiguity, leave it for clippy

elaboration on ambiguity in question:
`transmute::<u8, bool>(x)` will codegen to an `assume(u8 < 2)`;
`_ == 1` or `_ != 0` or `_ % 2 == 0` would remove that assumption
`match _ { x @ (0 | 1) => x == 1, _ => std::hint::unreachable_unchecked() }` is very verbose

`@rustbot` label L-unnecessary_transmutes
2025-05-22 07:19:01 +02:00
Matthias Krüger
fea2e5c746 Rollup merge of #141356 - dianne:thir-lower-params-before-body-expr, r=compiler-errors
lower bodies' params to thir before the body's value

Two motivations for this:
- Lowering params first means errors from lowering the params are emitted before errors from lowering the body's expression. This comes up in [tests/ui/associated-consts/associated-const-type-parameter-pattern.stderr](https://github.com/rust-lang/rust/compare/master...dianne:rust:thir-lower-params-before-body-expr?expand=1#diff-acac6ea10e991af0da91633e08b2739f9f9ca0c8f826401b6ba829914d0806f2), where both the params and expression encounter errors in translating consts to patterns. This change puts the errors in the order they appear in the source file.
- Guard patterns (#129967) contain expressions, so lowering params containing guard patterns may add more expressions to the THIR. However, there's a check for `-Zunpretty=thir-tree` that the final expression in the THIR corresponds to its value [(link)](c43786c9b7/compiler/rustc_mir_build/src/builder/mod.rs (L453-L455)); lowering params last would break this. As an alternative way to get guard patterns to work, I think the pretty-printer could use the expression returned by `thir_body` and the check could be removed or changed (#141357).
2025-05-21 22:15:00 +02:00
Matthias Krüger
69b13e4cab Rollup merge of #141347 - lcnr:lets-make-it-unsound-3, r=compiler-errors
incorrectly prefer builtin `dyn` impls :3

This makes #57893 slightly more exploitable with the new solver. It's still strictly better than the old solver and the underlying unsoundness persists in the new one even without this preference.

Properly fixing #57893 is something we've been looking at more deeply recently and discussed at the [Types Meetup during the All-Hands](https://hackmd.io/rz-4ghMzTb2wXOkdLKHaHw#Dyn-traits). Whatever approach we'll end up deciding on will likely require a fairly long transition period and some significant further design work. This should not block `-Znext-solver`.

fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/183

r? `@compiler-errors` cc `@rust-lang/types`
2025-05-21 22:14:59 +02:00
Matthias Krüger
b9c6b337ce Rollup merge of #141341 - folkertdev:limit-VaArgSafe-impls, r=workingjubilee
limit impls of `VaArgSafe` to just types that are actually safe

tracking issue: https://github.com/rust-lang/rust/issues/44930

Retrieving 8- or 16-bit integer arguments from a `VaList` is not safe, because such types are subject to upcasting. See https://github.com/rust-lang/rust/issues/61275#issuecomment-2193942535 for more detail.

This PR also makes the instances of `VaArgSafe` visible in the documentation, and uses a private sealed trait to make sure users cannot create additional impls of `VaArgSafe`, which would almost certainly cause UB.

r? `@workingjubilee`
2025-05-21 22:14:58 +02:00
Michael Goulet
e0f8055871 Fix FnOnce impl for AsyncFn/AsyncFnMut closures in new solver 2025-05-21 20:02:29 +00:00
Alona Enraght-Moony
8cdfabd230 rustdoc-json: Remove false docs and add test for inline attribute
The docs about how `#[inline]` was represented isn't true. Updates the
comment, and adds a test.

CC https://www.github.com/rust-lang/rust/issues/137645
2025-05-21 19:47:41 +00:00
Boxy
508a9f0853 Check for element being const before resolving repeat count 2025-05-21 20:38:49 +01:00
Boxy
77a2fc60a1 GAI logic on stable too 2025-05-21 20:38:49 +01:00
Boxy
52f2c45dee Properly test whether repeat expr checks are pre/post integer fallback 2025-05-21 20:38:49 +01:00
Boxy
f60bab475e Don't allow repeat expr count inference side effects to propagate 2025-05-21 20:38:49 +01:00
Boxy
b1774b8d73 Fix tests 2025-05-21 20:20:19 +01:00
dianne
2a403dc81d lower bodies' params to thir before the body's value 2025-05-21 09:17:11 -07:00
lcnr
5d9141c6c8 fix better_any breakage by making the solver more unsound 2025-05-21 13:54:19 +00:00
Matthias Krüger
9fd0ab6876 Rollup merge of #141334 - lcnr:coerce-nested-obligations, r=compiler-errors
eagerly check nested obligations when coercing fndefs

fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/212

r? `@compiler-errors`
2025-05-21 15:38:12 +02:00
Matthias Krüger
ab9109ad19 Rollup merge of #141333 - compiler-errors:param-env-candidate-unnorm, r=lcnr
Use `DeepRejectCtxt` in `assemble_inherent_candidates_from_param`

Fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/214

We were not properly considering unnormalized param-env candidates in `assemble_inherent_candidates_from_param`.

r? lcnr
2025-05-21 15:38:12 +02:00
Matthias Krüger
6606fd9a14 Rollup merge of #141332 - compiler-errors:no-fold-const, r=lcnr
Do not eagerly fold consts in `normalize_param_env_or_error` if new solver

Fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/213

Given:

```
trait Trait: Deref<Target = [u8; { 1 + 1 }]> {}
```

when elaborating param env for `Trait`, we have `Self: Trait`, `Self: Deref<Target = [u8; {anon const}]>`.

Before this PR, we would fold the anon consts away *before* elaborating. However, we end up getting another *un-folded* copy of the anon const from elaborating `Self: Trait`. This leads to normalization ambiguity.

r? lcnr
2025-05-21 15:38:11 +02:00
Matthias Krüger
1461ca3f39 Rollup merge of #141328 - azhogin:azhogin/async-drop-ice-for-empty-impl-fix, r=oli-obk
When AsyncDrop impl is empty, sync drop generated in elaborator

Fixes #140974.
2025-05-21 15:38:10 +02:00
Matthias Krüger
ad6fb066dd Rollup merge of #141296 - azhogin:azhogin/async-drop-broken-mir-place-deref-fix, r=oli-obk
Async drop fix for 'broken mir, place has deref as later projection'

fixes #140975

Problem in codegen fixed with an additional temporary local.
2025-05-21 15:38:10 +02:00
Matthias Krüger
af081a4247 Rollup merge of #141267 - dianne:fix-141265, r=oli-obk
only resolve top-level guard patterns' guards once

We resolve guard patterns' guards in `resolve_pattern_inner`, so to avoid resolving them multiple times, we must avoid doing so earlier. To accomplish this, `LateResolutionVisitor::visit_pat` contains a case for guard patterns that avoids visiting their guards while walking patterns.

This PR fixes #141265, which was due to `visit::walk_pat` being used instead; this meant guards at the top level of a pattern would be visited twice. e.g. it would ICE on `for x if x in [] {}`, but not `for (x if x) in [] {}`. `visit_pat` was already used for the guard pattern in the second example, on account of the top-level pattern being parens.
2025-05-21 15:38:08 +02:00
Folkert de Vries
d8a22a281c limit impls of VaArgSafe to just types that are actually safe
8 and 16-bit integers are subject to upcasting in C, and hence are not reliably safe. users should perform their own casting and deal with the consequences
2025-05-21 15:36:29 +02:00
Ben Kimock
e36dc78edd Add some track_caller info to precondition panics 2025-05-21 09:10:06 -04:00
Andrew Zhogin
7c38b6fd28 Async drop fix for 'broken mir in AsyncDropGlue, place has deref as a later projection' (#140975) 2025-05-21 18:29:13 +07:00
Andrew Zhogin
dc794f18a4 When AsyncDrop impl is empty, sync drop generated in elaborator (Fixes #140974) 2025-05-21 18:18:27 +07:00
lcnr
196c3b3ef4 eagerly check nested obligations when coercing fndefs 2025-05-21 11:09:48 +00:00
Michael Goulet
ad59f0b6e6 Use DeepRejectCtxt in assemble_inherent_candidates_from_param 2025-05-21 10:02:54 +00:00
Matthias Krüger
5b150e3122 Rollup merge of #141318 - nnethercote:fix-140884, r=compiler-errors
Avoid creating an empty identifer in `Symbol::to_ident_string`.

Because that causes an assertion failure in debug builds.

Fixes #140884.

r? `@oli-obk`
2025-05-21 11:28:47 +02:00
Matthias Krüger
aaa684fd1d Rollup merge of #141317 - dianne:continue-liveness-ice-fix, r=compiler-errors
typeck: catch `continue`s pointing to blocks

This taints the typeck results with errors if a `continue` is found not pointing to a loop.

A few things were going wrong here. First, since this wasn't caught in typeck, we'd end up building the THIR and then running liveness lints on ill-formed HIR. Since liveness assumes all `continue`s point to loops, it wasn't setting a live node for the `continue`'s destination. There was a fallback for if it couldn't retrieve that live node, but it was faulty; it would create a new live node to represent an erroneous state after the analysis's RWU table had already been built. This would ICE if the new live node was used in operations, such as merging results from the arms of a match. I've removed this error-recovery since it was buggy, and we should really catch bad labels before liveness.

I've also replaced an outdated comment about when liveness lints are run. At this point, I think the call to `check_liveness` could be moved elsewhere, but if it can be run when the typeck results are tainted by errors, it'll need some slight refactoring so it can bail out in that case. In lieu of that, I've added an assert.

Fixes #113379
Fixes #121623
2025-05-21 11:28:46 +02:00
Matthias Krüger
d30f0471c3 Rollup merge of #141213 - xizheyin:issue-141136, r=nnethercote
Suggest use "{}", self.x instead of {self.x} when resolve x as field of `self`

Fixes #141136

Changes can be seen in the second commit: 9de7fff0d8

r? compiler
2025-05-21 11:28:45 +02:00
Michael Goulet
44a2af3068 Do not eagerly fold consts in normalize_param_env_or_error if new solver 2025-05-21 09:23:36 +00:00
Nicholas Nethercote
1cc0e38fdc Avoid creating an empty identifer in Symbol::to_ident_string.
Because that causes an assertion failure in debug builds.

Fixes #140884.
2025-05-21 18:59:04 +10:00
Marcelo Domínguez
8917ff6024 Update generic tests 2025-05-21 07:24:43 +00:00
Marcelo Domínguez
8dd62e8188 Update UI tests 2025-05-21 07:24:43 +00:00
Marcelo Domínguez
2041de7083 Update codegen and pretty tests
UI tests are pending, will depend on error messages change.
2025-05-21 07:24:42 +00:00
Matthias Krüger
1b3159a4c0 Rollup merge of #141308 - spastorino:fix-rpitit-error-reporting-ice, r=nnethercote
Do not call name() on rpitit assoc_item

Fixes #141143

r? `@nnethercote`
2025-05-21 08:05:25 +02:00
Matthias Krüger
197898d003 Rollup merge of #140981 - est31:guard_let_chains_tests, r=petrochenkov
Add match guard let chain drop order and scoping tests

We have a bunch of tests for if let chain drop order, but those tests don't cover match guard chains to the same depth. This PR adds the following tests:

* match guard equivalents of the if let chains tests in the `drop-order-comparisons.rs` test, added by  #133605.
* match guard equivalent of the `mir_let_chains_drop_order.rs` test, added by #107251
* match guard equivalent of `temporary-early-drop.rs`, added by #133093

The added tests all have variants for 2021 and 2024, showing that the behavior on both editions matches that of if let chains on 2024.

tracking issue: https://github.com/rust-lang/rust/issues/51114
2025-05-21 08:05:11 +02:00
bors
87b4541569 Auto merge of #127721 - bvanjoi:issue-124273, r=petrochenkov
collect doc alias as tips during resolution

Close #124273

Collect the symbol in the doc alias attributes and provide a tip when a match is found.

r? `@estebank`
2025-05-21 02:21:28 +00:00
dianne
ed01a20514 typeck: catch continues pointing to blocks
This taints the typeck results with errors if a `continue` is found not
pointing to a loop, which fixes an ICE.

A few things were going wrong here. First, since this wasn't caught in
typeck, we'd end up building the THIR and then running liveness lints on
ill-formed HIR. Since liveness assumes all `continue`s point to loops,
it wasn't setting a live node for the `continue`'s destination. However,
the fallback for this was faulty; it would create a new live node to
represent the erroneous state after the analysis's RWU table had already
been built. This would ICE if the new live node was used in operations,
such as merging results from the arms of a match. I've removed this
error-recovery since it was buggy, and we should really catch bad labels
before liveness.

I've also replaced an outdated comment about when liveness lints are
run. At this point, I think the call to `check_liveness` could be moved
elsewhere, but if it can be run when the typeck results are tainted by
errors, it'll need some slight refactoring so it can bail out in that
case. In lieu of that, I've added an assertion.
2025-05-20 17:45:16 -07:00
Santiago Pastorino
66d47c1687 Do not call name() on rpitit assoc_item 2025-05-20 17:30:08 -03:00
bohan
097b7a2ac7 collect doc alias as tips during resolution 2025-05-21 00:47:36 +08:00
Matthias Krüger
ac500add80 Rollup merge of #141275 - dianne:gather-guard-pat-locals-once, r=compiler-errors
`gather_locals`: only visit guard pattern guards when checking the guard

When checking a pattern with guards in it, `GatherLocalsVisitor` will visit both the pattern (when type-checking the let, arm, or param containing it) and local declarations in the guard expression (when checking the guard itself). This keeps it from visiting the guard when visiting the pattern, since otherwise it would gather locals from the guard twice, which would lead to a delayed bug: "evaluated expression more than once".

Tracking issue for guard patterns: #129967
2025-05-20 16:50:41 +02:00
Matthias Krüger
5364668fb5 Rollup merge of #141253 - azhogin:azhogin/async-drop-feature-inconsistency-warning, r=oli-obk
Warning added when dependency crate has async drop types, and the feature is disabled

In continue of https://github.com/rust-lang/rust/pull/141031.

When dependency crate has non-empty `adt_async_destructor` table in metadata, and `async_drop` feature is disabled for local crate, warning will be emitted.

Test `dependency-dropped` has two revisions - with and without feature enabled. With feature enabled, async drop for dropee is executed ("Async drop" printed). Without the feature enabled, sync drop is executed ("Sync drop" printed) and warning is emitted.

Warning example:
```
warning: found async drop types in dependecy `async_drop_dep`, but async_drop feature is disabled for `dependency_dropped`
  --> $DIR/dependency-dropped.rs:7:1
   |
LL | #![cfg_attr(with_feature, feature(async_drop))]
   | ^
   |
   = help: if async drop type will be dropped in a crate without `feature(async_drop)`, sync Drop will be used
```
2025-05-20 16:50:40 +02:00
Matthias Krüger
42ed69c756 Rollup merge of #141236 - jagunter:issue-140823, r=compiler-errors
Resolved issue with mismatched types triggering ICE in certain scenarios

## Background

The function `annotate_mut_binding_to_immutable_binding` called in `emit_coerce_suggestions` performs a type comparison between the `expected` and `found` types from `ExpectedFound` in the `TypeError`. This can fail if the `found` type contains a region variable that's been rolled back.

## What is being changed?

This updates `annotate_mut_binding_to_immutable_binding` to use `expr_ty` and `expected` from the parent function instead of the types from the `TypeError`. This sidesteps the issue of using `found` from `TypeError` which may leak lingering inference region variables.

This does change the diagnostic behavior to _only_ support cases where the expected outermost type is `&T`, but that seems to be the intended functionality.

Also fixed the example in the `annotate_mut_binding_to_immutable_binding` rustdocs.

r? rust-lang/types

Fixes #140823
2025-05-20 16:50:39 +02:00
Michael Goulet
7e7c2c3947 Just error on recursive opaque ty in HIR typeck 2025-05-20 10:08:56 +00:00