Commit graph

45583 commits

Author SHA1 Message Date
Matthias Krüger
db7e32c074
Rollup merge of #139468 - compiler-errors:has_stashed_diagnostic, r=oli-obk
Don't call `Span::with_parent` on the good path in `has_stashed_diagnostic`

More unnecessary incurred span tracking avoided by not calling `span.with_parent(None)`. This is useless on its own but makes it much easier to fix other "span tracking on the good path" issues in the future.

r? oli-obk
2025-04-09 14:52:38 +02:00
Matthias Krüger
7494bd9a4f
Rollup merge of #139364 - Kohei316:feat/doc-hidden-suggestion, r=nnethercote
Make the compiler suggest actual paths instead of visible paths if the visible paths are through any doc hidden path.

close #127011
Currently, when emitting a diagnostic about a valid trait, the compiler suggestes using visible paths of the trait even if they are through a doc hidden path. This PR updates the compiler to suggest actual paths in these cases.
2025-04-09 14:52:37 +02:00
bors
f06e5c1e35 Auto merge of #139327 - cjgillot:gvn-place, r=oli-obk
Allow GVN to produce places and not just locals.

That may be too big of a hammer, as we may introduce new deref projections (possible UB footgun + probably not good for perf).

The second commit opts out of introducing projections that don't have a stable offset, which is probably what we want. Hence no new Deref and no new Index projections.

Fixes https://github.com/rust-lang/rust/issues/138936
cc `@scottmcm` `@dianqk`
2025-04-09 08:50:33 +00:00
bors
97c966bb40 Auto merge of #139552 - matthiaskrgr:rollup-b194mk8, r=matthiaskrgr
Rollup of 10 pull requests

Successful merges:

 - #139494 (Restrict some queries by def-kind more)
 - #139496 (Revert r-a changes of rust-lang/rust#139455)
 - #139506 (add missing word in doc comment (part 2))
 - #139515 (Improve presentation of closure signature mismatch from `Fn` trait goal)
 - #139520 (compiletest maintenance: sort deps and drop dep on `anyhow`)
 - #139523 (Rustc dev guide subtree update)
 - #139526 (Fix deprecation note for std::intrinsics)
 - #139528 (compiletest: Remove the `--logfile` flag)
 - #139541 (Instantiate higher-ranked transmute goal w/ placeholders before emitting sub-obligations)
 - #139547 (Update library tracking issue template to set S-tracking-unimplemented)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-09 05:39:18 +00:00
bors
de5b8a4c77 Auto merge of #139536 - matthiaskrgr:rollup-j6goald, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #139476 (rm `RegionInferenceContext::var_infos`)
 - #139485 (compiletest: Stricter parsing for diagnostic kinds)
 - #139491 (Update books)
 - #139500 (document panic behavior of Vec::resize and Vec::resize_with)
 - #139501 (Fix stack overflow in exhaustiveness due to recursive HIR opaque hidden types)
 - #139504 (add missing word in doc comment)
 - #139509 (clean: remove Deref<Target=RegionKind> impl for Region and use `.kind()`)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-08 22:51:10 +00:00
Matthias Krüger
8a64ba5c3f
Rollup merge of #139541 - compiler-errors:transmute, r=lcnr
Instantiate higher-ranked transmute goal w/ placeholders before emitting sub-obligations

This avoids an ICE where we weren't keeping track of bound variables correctly in the `Freeze` obligations we emit for transmute goals. We could use `rebind` instead on that goal, but I think it's better just to instantiate the binder.

Fixes #139538

r? `@lcnr` or reassign
2025-04-08 21:26:02 +02:00
Matthias Krüger
b41e2bd807
Rollup merge of #139515 - compiler-errors:sig-mismatch, r=lcnr
Improve presentation of closure signature mismatch from `Fn` trait goal

Flip the order of "expected" and "found" since that wasn't correct.

Don't present the arguments as a tuple, since it leaves a trailing comma. Instead, just use `fn(arg, arg)`.

Finally, be better with binders since we were just skipping binders.

r? oli-obk or reassign
2025-04-08 21:25:59 +02:00
Matthias Krüger
894f471d1e
Rollup merge of #139494 - compiler-errors:restrict-queries, r=oli-obk
Restrict some queries by def-kind more

Random cleanup. I prefer things to assert more so as to catch bugs :)

r? oli-obk
2025-04-08 21:25:57 +02:00
Michael Goulet
68692b7fbb Instantiate higher-ranked transmute goal 2025-04-08 17:00:29 +00:00
Matthias Krüger
1cbf8b56af
Rollup merge of #139509 - xizheyin:issue-139359, r=lcnr
clean: remove Deref<Target=RegionKind> impl for Region and use `.kind()`

Closes #139359

r? `@lcnr`
2025-04-08 18:05:34 +02:00
Matthias Krüger
9ea9339435
Rollup merge of #139501 - compiler-errors:suppress-stack-overflow, r=lcnr
Fix stack overflow in exhaustiveness due to recursive HIR opaque hidden types

This fixes several spicy non-trivial recursive opaque definitions inferred from HIR typeck, ensuring that they don't cause stack overflows in exhaustiveness code, which currently reveals opaques manually in a way that is not overflow aware (as opposed to something like the normalizer folders).

These should eventually be outright rejected, but today (some) non-trivial recursive opaque definitions are accepted, and changing that requires an FCP, so for now just make sure we don't stack overflow :^)

Fixes https://github.com/rust-lang/rust/issues/139402

r? lcnr
2025-04-08 18:05:31 +02:00
Matthias Krüger
75f3bd6ed0
Rollup merge of #139476 - lcnr:rm-var_infos, r=compiler-errors
rm `RegionInferenceContext::var_infos`

we already track this info in the `definitions` field

r? types
2025-04-08 18:05:19 +02:00
bors
d4f880f8ce Auto merge of #138499 - lcnr:borrowck-typeck_root, r=oli-obk
borrowck typeck children together with their root

This introduces new cycle errors, even with `feature(inline_const_pat)` removed, see the `non-structural-match-types-cycle-err.rs` test.

The new cycle error happens as the layout of `async`-blocks relies on their `optimized_mir`. As that now depends on `mir_borrowck` of its typeck parent, computing the layout of an `async`-block during MIR building, e.g. when evaluating a named `const` pattern. I think there's currently no way to have a named const pattern whose type references an async block while being allowed? cc `@oli-obk` `@RalfJung`

I cannot think of other cases where we currently rely on the MIR of a typeck children while borrowchecking their parent. The crater run came back without any breakage. My work here will prevent any future features which rely on this as we'll get locked into borrowchecking them together as I continue to work on https://github.com/rust-lang/types-team/issues/129, cc `@rust-lang/types.`

r? compiler-errors
2025-04-08 16:01:37 +00:00
Stuart Cook
24369adae7
Rollup merge of #139464 - nnethercote:fix-139248-AND-fix-139445, r=petrochenkov
Allow for reparsing failure when reparsing a pasted metavar.

Fix some metavar reparsing issues.

Fixes #139248 and #139445.

r? `@petrochenkov`
2025-04-08 20:55:11 +10:00
Stuart Cook
056756c7c4
Rollup merge of #139421 - compiler-errors:upcast-no-principal-with-proj, r=oli-obk
Fix trait upcasting to dyn type with no principal when there are projections

#126660 (which I had originally authored, lol) had a subtle bug that is the moral equivalent of #114036, which is that when upcasting from `dyn Principal<Projection = Ty> + AutoTrait` to `dyn AutoTrait`, we were dropping the trait ref for `Principal` but not its projections (if there were any).

With debug assertions enabled, this triggers the assertion I luckily added in a2a0cfe825, but even without debug assertions this is a logical bug since we had a dyn type with just a projection bound but no principal, so it caused a type mismatch.

This does not need an FCP because this should've been covered by the FCP in #126660, but we just weren't testing a case when casting from a `dyn` type with projections 😸

Fixes #139418

r? ````@oli-obk```` (or anyone)
2025-04-08 20:55:09 +10:00
Stuart Cook
133cec7363
Rollup merge of #139346 - compiler-errors:non-lifetime-binder-diag-hir-wf-check, r=oli-obk
Don't construct preds w escaping bound vars in `diagnostic_hir_wf_check`

See comment inline.

Fixes #139330

r? oli-obk
2025-04-08 20:55:07 +10:00
Stuart Cook
5913c5248b
Rollup merge of #139124 - xtexx:gh-139082, r=compiler-errors
compiler: report error when trait object type param reference self

Fixes #139082.

Emits an error when `Self` is found in the projection bounds of a trait
object. In type aliases, `Self` has no meaning, so `type A = &'static
dyn B` where `trait B = Fn() -> Self` will expands to `type A = &'static
Fn() -> Self` which is illegal, causing the region solver to bail out
when hitting the uninferred Self.

r? ````@compiler-errors```` ````@fee1-dead````
2025-04-08 20:55:04 +10:00
Stuart Cook
7ffa56c3a3
Rollup merge of #139098 - scottmcm:assert-impossible-tags, r=WaffleLapkin
Tell LLVM about impossible niche tags

I was trying to find a better way of emitting discriminant calculations, but sadly had no luck.

So here's a fairly small PR with the bits that did seem worth bothering:

1. As the [`TagEncoding::Niche` docs](https://doc.rust-lang.org/nightly/nightly-rustc/rustc_abi/enum.TagEncoding.html#variant.Niche) describe, it's possible to end up with a dead value in the input that's not already communicated via the range parameter attribute nor the range load metadata attribute.  So this adds an `llvm.assume` in non-debug mode to tell LLVM about that.  (That way it can tell that the sides of the `select` have disjoint possible values.)

2. I'd written a bunch more tests, or at least made them parameterized, in the process of trying things out, so this checks in those tests to hopefully help future people not trip on the same weird edge cases, like when the tag type is `i8` but yet there's still a variant index and discriminant of `258` which doesn't fit in that tag type because the enum is really weird.
2025-04-08 20:55:03 +10:00
Stuart Cook
6257825c8f
Rollup merge of #139024 - compiler-errors:tweak-default-value-err, r=lcnr
Make error message for missing fields with `..` and without `..` more consistent

When `..` is not present, we say "missing field `bar` in initializer", but when it is present we say "missing mandatory field `bar`". I don't see why the primary error message should change, b/c the root cause is the same.

Let's harmonize these error messages and instead use a label to explain that `..` is required b/c it's not defaulted.

r? estebank
2025-04-08 20:55:01 +10:00
Stuart Cook
2b1afcbd1a
Rollup merge of #138676 - compiler-errors:overflow-implied-bounds, r=lcnr
Implement overflow for infinite implied lifetime bounds

Not a great error message, but better than a hang

Fixes #138665
Fixes #102966
Fixes #115407

r? lcnr
2025-04-08 20:54:58 +10:00
xizheyin
c66d35e946
update if let to match in universal_regions.rs
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-04-08 17:39:15 +08:00
xizheyin
a8b0eb7c65
Update compiler/rustc_borrowck/src/diagnostics/region_errors.rs
Co-authored-by: lcnr <rust@lcnr.de>
2025-04-08 17:36:44 +08:00
Michael Goulet
d940038636 Remove unnecessary dyn Display in favor of str 2025-04-08 06:09:04 +00:00
Michael Goulet
c5320454ed Improve presentation of closure signature mismatch from Fn trait goal 2025-04-08 05:54:57 +00:00
xizheyin
c7272a6cbc
clean code: remove Deref<Target=RegionKind> impl for Region and use .kind()
Signed-off-by: xizheyin <xizheyin@smail.nju.edu.cn>
2025-04-08 10:51:41 +08:00
Nicholas Nethercote
e177921ae9 Allow for reparsing failure when reparsing a pasted metavar.
Fixes #139445.

The additional errors aren't great but the first one is still good and
it's the most important, and imperfect errors are better than ICEing.
2025-04-08 12:06:42 +10:00
Nicholas Nethercote
eb5d8923fc Allow for missing invisible close delim when reparsing an expression.
This can happen when invalid syntax is passed to a declarative macro. We
shouldn't be too strict about the token stream position once the parser
has rejected the invalid syntax.

Fixes #139248.
2025-04-08 12:06:40 +10:00
Scott McMurray
502f7f9c24 Address PR feedback 2025-04-07 18:12:06 -07:00
Michael Goulet
b08e9c2a60 Fix stack overflow in exhaustiveness due to recursive HIR opaque type values 2025-04-07 22:41:48 +00:00
lcnr
d35ad8d836 add negative impl 2025-04-08 00:34:40 +02:00
lcnr
474ec7a3f4 move ClosureRegionRequirements to rustc_borrowck 2025-04-08 00:34:40 +02:00
lcnr
f05a23be5c borrowck typeck children together with their parent 2025-04-08 00:34:40 +02:00
bors
c6c179662d Auto merge of #133781 - cjgillot:shallow-allowed-lints, r=petrochenkov
Do not visit whole crate to compute `lints_that_dont_need_to_run`.

This allows to reuse the computed lint levels instead of re-visiting the whole crate.
2025-04-07 21:03:55 +00:00
Michael Goulet
268c56e144 Implement overflow for infinite implied lifetime bounds 2025-04-07 21:01:24 +00:00
Michael Goulet
250b848272 Make error message for missing fields with .. and without .. more consistent 2025-04-07 20:45:08 +00:00
Michael Goulet
14d1215719 Restrict some queries by def-kind more 2025-04-07 18:10:28 +00:00
Stuart Cook
6e0b67419c
Rollup merge of #139466 - compiler-errors:trivial-incr-tainting, r=oli-obk
Trivial tweaks to stop tracking source span directly

Firstly, remove some unnecessary work from `sccs_info`. This included debug printing which ends up giving all mir borrowck queries a dependency edge from the query to `source_span` (I think?).

Secondly, turn some calls from `hir_span` (which does some span adjustment, and thus incurs span tracking, which causes a dependency edge from the query to `source_span`) to `def_span`, which should cache better.

r? oli-obk
2025-04-07 22:29:22 +10:00
Stuart Cook
5863b426b9
Rollup merge of #139465 - EnzymeAD:autodiff-sret, r=oli-obk
add sret handling for scalar autodiff

r? `@oli-obk`

Fixing one of the todo's which I left in my previous batching PR.
This one handles sret for scalar autodiff.  `sret` mostly shows up when we try to return a lot of scalar floats.
People often start testing autodiff which toy functions which just use a few scalars as inputs and outputs, and those were the most likely to be affected by this issue. So this fix should make learning/teaching hopefully a bit easier.

Tracking:

- https://github.com/rust-lang/rust/issues/124509
2025-04-07 22:29:21 +10:00
Stuart Cook
0178254f46
Rollup merge of #139461 - compiler-errors:significant-drop-span, r=oli-obk
Stop calling `source_span` query in significant drop order code

`source_span` is only meant for incremental tracking. I don't really think we need to highlight the whole drop impl span anyways; it can be quite large.

r? oli-obk
2025-04-07 22:29:21 +10:00
Stuart Cook
9209c5eb60
Rollup merge of #139455 - Skgland:remove_rust-intrinsic_ABI, r=oli-obk
Remove support for `extern "rust-intrinsic"` blocks

Part of rust-lang/rust#132735

Looked manageable and there didn't appear to have been progress in the last two weeks,
so decided to give it a try.
2025-04-07 22:29:20 +10:00
Stuart Cook
ddf099ff4e
Rollup merge of #139397 - Zalathar:virtual, r=jieyouxu
coverage: Build the CGU's global file table as late as possible

Embedding coverage metadata in the output binary is a delicate dance, because per-function records need to embed references to the per-CGU filename table, but we only want to include files in that table if they are successfully used by at least one function.

The way that we build the file tables has changed a few times over the last few years. This particular change is motivated by experimental work on properly supporting macro-expansion regions, which adds some additional constraints that our previous implementation wasn't equipped to deal with.

LLVM is very strict about not allowing unused entries in local file tables. Currently that's not much of an issue, because we assume one source file per function, but to support expansion regions we need the flexibility to avoid committing to the use of a file until we're completely sure that we are able and willing to produce at least one coverage mapping region for it. In particular, when preparing a function's covfun record, we need the flexibility to decide at a late stage that a particular file isn't needed/usable after all.

(It's OK for the *global* file table to contain unused entries, but we would still prefer to avoid that if possible, and this implementation also achieves that.)
2025-04-07 22:29:20 +10:00
Stuart Cook
f4c429fde5
Rollup merge of #139365 - Bryanskiy:leak-perf, r=lcnr
Default auto traits: fix perf

Skip computing `requires_default_supertraits` if `experimental-default-bounds` option is not enabled. Possible perf fix for https://github.com/rust-lang/rust/pull/120706

r? lcnr
2025-04-07 22:29:19 +10:00
Stuart Cook
27c6e40755
Rollup merge of #139112 - m-ou-se:super-let, r=lcnr
Implement `super let`

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

This implements `super let` as proposed in #139080, based on the following two equivalence rules.

1. For all expressions `$expr` in any context, these are equivalent:
  - `& $expr`
  - `{ super let a = & $expr; a }`

2. And, additionally, these are equivalent in any context when `$expr` is a temporary (aka rvalue):
  - `& $expr`
  - `{ super let a = $expr; & a }`

So far, this experiment has a few interesting results:

## Interesting result 1

In this snippet:

```rust
super let a = f(&temp());
```

I originally expected temporary `temp()` would be dropped at the end of the statement (`;`), just like in a regular `let`, because `temp()` is not subject to temporary lifetime extension.

However, it turns out that that would break the fundamental equivalence rules.

For example, in

```rust
g(&f(&temp()));
```

the temporary `temp()` will be dropped at the `;`.

The first equivalence rule tells us this must be equivalent:

```rust
g({ super let a = &f(&temp()); a });
```

But that means that `temp()` must live until the last `;` (after `g()`), not just the first `;` (after `f()`).

While this was somewhat surprising to me at first, it does match the exact behavior we need for `pin!()`: The following _should work_. (See also https://github.com/rust-lang/rust/issues/138718)

```rust
g(pin!(f(&mut temp())));
```

Here, `temp()` lives until the end of the statement. This makes sense from the perspective of the user, as no other `;` or `{}` are visible. Whether `pin!()` uses a `{}` block internally or not should be irrelevant.

This means that _nothing_ in a `super let` statement will be dropped at the end of that super let statement. It does not even need its own scope.

This raises questions that are useful for later on:

- Will this make temporaries live _too long_ in cases where `super let` is used not in a hidden block in a macro, but as a visible statement in code like the following?

    ```rust
    let writer = {
        super let file = File::create(&format!("/home/{user}/test"));
        Writer::new(&file)
    };
    ```

- Is a `let` statement in a block still the right syntax for this? Considering it has _no_ scope of its own, maybe neither a block nor a statement should be involved

This leads me to think that instead of `{ super let $pat = $init; $expr }`, we might want to consider something like `let $pat = $init in $expr` or `$expr where $pat = $init`. Although there are also issues with these, as it isn't obvious anymore if `$init` should be subject to temporary lifetime extension. (Do we want both `let _ = _ in ..` and `super let _ = _ in ..`?)

## Interesting result 2

What about `super let x;` without initializer?

```rust
let a = {
    super let x;
    x = temp();
    &x
};
```

This works fine with the implementation in this PR: `x` is extended to live as long as `a`.

While it matches my expectations, a somewhat interesting thing to realize is that these are _not_ equivalent:

- `super let x = $expr;`
- `super let x; x = $expr;`

In the first case, all temporaries in $expr will live at least as long as (the result of) the surrounding block.
In the second case, temporaries will be dropped at the end of the assignment statement. (Because the assignment statement itself "is not `super`".)

This difference in behavior might be confusing, but it _might_ be useful.
One might want to extend the lifetime of a variable without extending all the temporaries in the initializer expression.

On the other hand, that can also be expressed as:

- `let x = $expr; super let x = x;` (w/o temporary lifetime extension), or
- `super let x = { $expr };` (w/ temporary lifetime extension)

So, this raises these questions:

- Do we want to accept `super let x;` without initializer at all?

- Does it make sense for statements other than let statements to be "super"? An expression statement also drops temporaries at its `;`, so now that we discovered that `super let` basically disables that `;` (see interesting result 1), is there a use to having other statements without their own scope? (I don't think that's ever useful?)

## Interesting result 3

This works now:

```rust
super let Some(x) = a.get(i) else { return };
```

I didn't put in any special cases for `super let else`. This is just the behavior that 'naturally' falls out when implementing `super let` without thinking of the `let else` case.

- Should `super let else` work?

## Interesting result 4

This 'works':

```rust
fn main() {
    super let a = 123;
}
```

I didn't put in any special cases for `super let` at function scope. I had expected the code to cause an ICE or other weird failure when used at function body scope, because there's no way to let the variable live as long as the result of the function.

This raises the question:

- Does this mean that this behavior is the natural/expected behavior when `super let` is used at function scope? Or is this just a quirk and should we explicitly disallow `super let` in a function body? (Probably the latter.)

---

The questions above do not need an answer to land this PR. These questions should be considered when redesigning/rfc'ing/stabilizing the feature.
2025-04-07 22:29:18 +10:00
Stuart Cook
9955b7634d
Rollup merge of #139108 - Nadrieril:simplify-expandedconstant, r=oli-obk
Simplify `thir::PatKind::ExpandedConstant`

I made it a bit less ad-hoc. In particular, I removed `is_inline: bool` that was just caching the output of `tcx.def_kind(def_id)`. This makes inline consts a tiny bit less special in patterns.

r? `@oli-obk`

cc `@Zalathar`
2025-04-07 22:29:18 +10:00
Stuart Cook
82df6229b6
Rollup merge of #139035 - nnethercote:PatKind-Missing, r=oli-obk
Add new `PatKind::Missing` variants

To avoid some ugly uses of `kw::Empty` when handling "missing" patterns, e.g. in bare fn tys. Helps with #137978. Details in the individual commits.

r? ``@oli-obk``
2025-04-07 22:29:17 +10:00
Manuel Drehwald
d6467d34ae handle sret for scalar autodiff 2025-04-07 07:07:16 -04:00
lcnr
1862b311f6 rm RegionInferenceContext::var_infos
we already track this info in the `definitions` field
2025-04-07 12:19:35 +02:00
Zalathar
4322b6e97d coverage: Build the CGU's global file table as late as possible 2025-04-07 17:11:49 +10:00
bors
8fb32ab8e5 Auto merge of #139473 - Kobzol:rollup-ycksn9b, r=Kobzol
Rollup of 5 pull requests

Successful merges:

 - #138314 (fix usage of `autodiff` macro with inner functions)
 - #139426 (Make the UnifyKey and UnifyValue imports non-nightly)
 - #139431 (Remove LLVM 18 inline ASM span fallback)
 - #139456 (style guide: add let-chain rules)
 - #139467 (More trivial tweaks)

r? `@ghost`
`@rustbot` modify labels: rollup
2025-04-07 06:27:35 +00:00
Jakub Beránek
58ad76313f
Rollup merge of #139467 - compiler-errors:more-trivial-tweaks, r=oli-obk
More trivial tweaks

Found some really tiny nits when trying to find places that span tracking caused queries to be recomputed in incremental; these probably don't need a perf run b/c they're so simple.

r? oli-obk
2025-04-07 08:23:36 +02:00