Commit Graph

6556 Commits

Author SHA1 Message Date
bors
1c77f7378e Auto merge of #123708 - matthiaskrgr:rollup-uf9w1e9, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #121884 (Port exit-code run-make test to use rust)
 - #122200 (Unconditionally show update nightly hint on ICE)
 - #123568 (Clean up tests/ui by removing `does-nothing.rs`)
 - #123609 (Don't use bytepos offsets when computing semicolon span for removal)
 - #123612 (Set target-abi module flag for RISC-V targets)
 - #123633 (Store all args in the unsupported Command implementation)
 - #123668 (async closure coroutine by move body MirPass refactoring)

Failed merges:

 - #123701 (Only assert for child/parent projection compatibility AFTER checking that theyre coming from the same place)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-04-10 02:43:17 +00:00
Matthias Krüger
4bc891aebf
Rollup merge of #123609 - compiler-errors:greek-question-mark, r=jieyouxu
Don't use bytepos offsets when computing semicolon span for removal

Causes problems when we recover confusable characters w/ a different byte width

Fixes #123607
2024-04-10 04:27:39 +02:00
Matthias Krüger
c14b468cca
Rollup merge of #123568 - Oneirical:delete-tests, r=wesleywiser
Clean up tests/ui by removing `does-nothing.rs`

In [a previous PR](https://github.com/rust-lang/rust/pull/123297#issuecomment-2039887806), it was suggested that this test be removed:

> it's testing a basic diagnostic for an unknown variable (added over a decade ago for https://github.com/rust-lang/rust/issues/154) that is already covered by probably dozens or hundreds of other tests.

It was then suggested that [opening a new PR](https://github.com/rust-lang/rust/pull/123563#discussion_r1554654102) for this would be more organized.

I'm setting this as a draft, as:

1. The tests/ui directory is rather disorganized, a large quantity of tests are not even contained inside their own directories. This PR could turn into "clean up the UI tests directory", if I were to place everything into categories (for example, everything related to CLI flags could get placed in a cli directory).
2. This will have a merge conflict with #123563 should that get merged. I trust that _this time_, I won't run into [The Incident](https://github.com/rust-lang/rust/pull/123297#issuecomment-2041137569) while rebasing. Edit: Yay, I did it properly!
2024-04-10 04:27:39 +02:00
Matthias Krüger
7dd24d88ab
Rollup merge of #122200 - jieyouxu:unconditional-nightly-update-hint, r=estebank
Unconditionally show update nightly hint on ICE

Instead of trying to guess if a update nightly hint should be shown (by checking for system time, querying version and channel info etc.), just show the update nightly hint for nightly compilers. This avoids breaking tests that match on ICE test outputs on nightly/dev channels.

> Another issue is that the outdated nightly hint triggers for ICE tests, causing a mismatch with the test expectation. There doesn't seem to be any env var to suppress this.

See <https://rust-lang.zulipchat.com/#narrow/stream/326414-t-infra.2Fbootstrap/topic/stage0.20compiletest.20broken/near/425543681> for context.
2024-04-10 04:27:38 +02:00
Esteban Küber
796be88062 Use fn ptr signature instead of {closure@..} in infer error
When suggesting a type on inference error, do not use `{closure@..}`.
Instead, replace with an appropriate `fn` ptr.

On the error message, use `short_ty_string` and write long types to
disk.

```
error[E0284]: type annotations needed for `Select<{closure@lib.rs:2782:13}, _, Expression<'_>, _>`
  --> crates/lang/src/parser.rs:41:13
   |
41 |         let lit = select! {
   |             ^^^
42 |             Token::Int(i) = e => Expression::new(Expr::Lit(ast::Lit::Int(i.parse().unwrap())), e.span()),
   |                                                                                                  ---- type must be known at this point
   |
   = note: the full type name has been written to '/home/gh-estebank/iowo/target/debug/deps/lang-e2d6e25819442273.long-type-4587393693885174369.txt'
   = note: cannot satisfy `<_ as chumsky::input::Input<'_>>::Span == SimpleSpan`
help: consider giving `lit` an explicit type, where the type for type parameter `I` is specified
   |
41 |         let lit: Select<for<'a, 'b> fn(tokens::Token<'_>, &'a mut MapExtra<'_, 'b, _, _>) -> Option<Expression<'_>>, _, Expression<'_>, _> = select! {
   |                +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
```

instead of

```
error[E0284]: type annotations needed for `Select<{closure@/home/gh-estebank/.cargo/registry/src/index.crates.io-6f17d22bba15001f/chumsky-1.0.0-alpha.6/src/lib.rs:2782:13: 2782:28}, _, Expression<'_>, _>`
  --> crates/lang/src/parser.rs:41:13
   |
41 |         let lit = select! {
   |             ^^^
42 |             Token::Int(i) = e => Expression::new(Expr::Lit(ast::Lit::Int(i.parse().unwrap())), e.span()),
   |                                                                                                  ---- type must be known at this point
   |
   = note: cannot satisfy `<_ as chumsky::input::Input<'_>>::Span == SimpleSpan`
help: consider giving `lit` an explicit type, where the type for type parameter `I` is specified
   |
41 |         let lit: Select<{closure@/home/gh-estebank/.cargo/registry/src/index.crates.io-6f17d22bba15001f/chumsky-1.0.0-alpha.6/src/lib.rs:2782:13: 2782:28}, _, Expression<'_>, _> = select! {
   |                ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
```

Fix #123630.
2024-04-10 00:41:27 +00:00
bors
93c131eba0 Auto merge of #122918 - jieyouxu:port-backtrace-line-tables-only, r=workingjubilee
Port backtrace's `line-tables-only` test over to rustc

Part of #122899.
2024-04-10 00:40:34 +00:00
Oneirical
cbf150177f remove does-nothing.rs
fix: restore issues_entry_limit
2024-04-09 20:26:40 -04:00
Esteban Küber
a983dd8563 Tweak value suggestions in borrowck and hir_analysis
Unify the output of `suggest_assign_value` and `ty_kind_suggestion`.

Ideally we'd make these a single function, but doing so would likely require modify the crate dependency tree.
2024-04-09 23:37:13 +00:00
Urgau
0c3f5cce89 Further cleanup cfgs in the UI test suite
This commit does three things:
 1. replaces (the last remaining) never true cfgs by the FALSE cfg
 2. fix derive-helper-configured.rs (typo in directive)
 3. and comment some current unused #[cfg_attr] (missing revisions)
2024-04-09 23:58:18 +02:00
bors
8b2459c1f2 Auto merge of #123683 - pietroalbini:pa-cve-2024-24576-nightly, r=pietroalbini
Backport fix of CVE-2024-24576

See https://blog.rust-lang.org/2024/04/09/cve-2024-24576.html

r? `@ghost`
2024-04-09 19:56:18 +00:00
Santiago Pastorino
30c546aee1
Handle const generic pattern types 2024-04-09 16:42:45 -03:00
Santiago Pastorino
a2bdb994d3
Add const generics failing test for pattern types 2024-04-09 15:14:02 -03:00
Michael Goulet
a439eb259d Don't use bytepos offsets when computing semicolon span for removal 2024-04-09 14:06:08 -04:00
Michael Goulet
a9e262a32d Split back out unused_lifetimes -> redundant_lifetimes 2024-04-09 12:17:34 -04:00
Michael Goulet
ee78eab62b Lint redundant lifetimes in impl header 2024-04-09 12:17:34 -04:00
Michael Goulet
2d813547bf Move check to wfcheck 2024-04-09 12:17:34 -04:00
Michael Goulet
89409494e3 Actually, just reuse the UNUSED_LIFETIMES lint 2024-04-09 12:15:27 -04:00
许杰友 Jieyou Xu (Joe)
09dab389e2 tests: bless ui and rustdoc-ui tests for ICE messages 2024-04-09 13:58:52 +00:00
Guillaume Gomez
e5b2935dc1
Rollup merge of #123662 - compiler-errors:no-upvars-yet, r=oli-obk
Don't rely on upvars being assigned just because coroutine-closure kind is assigned

Previously, code relied on the implicit assumption that if a coroutine-closure's kind variable was constrained, then its upvars were also constrained. This is because we assign all of them at once at the end up upvar analysis.

However, there's another way that a coroutine-closure's kind can be constrained: from a signature hint in closure signature deduction. After #123350, we use these hints, which means the implicit assumption above no longer holds.

This PR adds the necessary checks so that we don't ICE.

r? oli-obk
2024-04-09 13:39:23 +02:00
Guillaume Gomez
cfe1faa75d
Rollup merge of #123658 - compiler-errors:stop-assuming, r=oli-obk
Stop making any assumption about the projections applied to the upvars in the `ByMoveBody` pass

So it turns out that because of subtle optimizations like [`truncate_capture_for_optimization`](ab5bda1aa7/compiler/rustc_hir_typeck/src/upvar.rs (L2351)), we simply cannot make any assumptions about the shape of the projections applied to the upvar locals in a coroutine body.

So stop doing that -- the code is resilient to such projections, so the assertion really existed only to "protect against the unknown".

r? oli-obk
Fixes #123650
2024-04-09 13:39:23 +02:00
Guillaume Gomez
b3f40e3448
Rollup merge of #123653 - Urgau:split-test-non_local_defs, r=compiler-errors
Split `non_local_definitions` lint tests in separate test files

This PR splits the giant `non_local_definitions` lint UI test in separate test files.

This change is extracted from #123594 (where it was requested https://github.com/rust-lang/rust/pull/123594#discussion_r1555261772), to ease the review of the other PR and to reduce the size of the other PR.

r? ``@compiler-errors``
2024-04-09 13:39:22 +02:00
Oli Scherer
c0a9c8c954 Silence some follow-up errors on trait impls in case the trait has conflicting or otherwise incoherent impls 2024-04-09 10:23:58 +00:00
Oli Scherer
c8f6e03c15 Add regression test 2024-04-09 10:21:29 +00:00
Matthias Krüger
7e9eaba52b
Rollup merge of #123652 - cuviper:ui-vendor, r=jieyouxu
Fix UI tests with dist-vendored dependencies

There is already a workaround in `compiletest` to deal with custom
`CARGO_HOME` using `-Zignore-directory-in-diagnostics-source-blocks={}`.
A similar need exists when dependencies come from the local `vendor`
directory, which distro builds often use, so now we ignore that too.

Also, `issue-21763.rs` was normalizing `hashbrown-` paths, presumably
expecting a version suffix, but the vendored path doesn't include the
version. Now that matches `[\\/]hashbrown` instead.
2024-04-09 06:02:24 +02:00
Matthias Krüger
55e0668fea
Rollup merge of #123649 - maurer:kcfi-v0, r=compiler-errors
KCFI: Use legal charset in shim encoding

To separate `ReifyReason::FnPtr` from `ReifyReason::VTable`, we hyphenated the shims. Hyphens are not actually legal, but underscores are, so use those instead.

r? `@compiler-errors`
2024-04-09 06:02:24 +02:00
Matthias Krüger
727c31a797
Rollup merge of #123648 - oli-obk:pattern_types_syntax, r=compiler-errors
Avoid ICEing without the pattern_types feature gate

fixes  #123643
2024-04-09 06:02:23 +02:00
Matthias Krüger
643dee7573
Rollup merge of #122768 - oli-obk:why_is_E0699_so_bad, r=WaffleLapkin
Use the more informative generic type inference failure error on method calls on raw pointers
2024-04-09 06:02:21 +02:00
Michael Goulet
6f96d7d012 Don't rely on upvars being assigned just because coroutine-closure kind is assigned 2024-04-08 22:43:32 -04:00
Michael Goulet
54a93ab11e Actually, stop making any assumption about the projections applied to the upvar 2024-04-08 19:47:52 -04:00
Chris Denton
96b6459ba0
Use new-style directives in ui test 2024-04-09 01:19:43 +02:00
Chris Denton
f66a096607
Disallow or quote all specials in bat args 2024-04-09 01:19:08 +02:00
bors
b234e44944 Auto merge of #122077 - oli-obk:eager_opaque_checks4, r=lcnr
Pass list of defineable opaque types into canonical queries

This eliminates `DefiningAnchor::Bubble` for good and brings the old solver closer to the new one wrt cycles and nested obligations. At that point the difference between `DefiningAnchor::Bind([])` and `DefiningAnchor::Error` was academic. We only used the difference for some sanity checks, which actually had to be worked around in places, so I just removed `DefiningAnchor` entirely and just stored the list of opaques that may be defined.

fixes #108498
fixes https://github.com/rust-lang/rust/issues/116877

* [x] run crater
  - https://github.com/rust-lang/rust/pull/122077#issuecomment-2013293931
2024-04-08 23:01:50 +00:00
Urgau
ddc16e98e6 Split non_local_definitions lint tests in separate test files 2024-04-09 00:42:48 +02:00
Josh Stone
f7b2e37f72 Fix UI tests with dist-vendored dependencies
There is already a workaround in `compiletest` to deal with custom
`CARGO_HOME` using `-Zignore-directory-in-diagnostics-source-blocks={}`.
A similar need exists when dependencies come from the local `vendor`
directory, which distro builds often use, so now we ignore that too.

Also, `issue-21763.rs` was normalizing `hashbrown-` paths, presumably
expecting a version suffix, but the vendored path doesn't include the
version. Now that matches `[\\/]hashbrown` instead.
2024-04-08 15:04:44 -07:00
Matthew Maurer
233d94e72f KCFI: Use legal charset in shim encoding
To separate `ReifyReason::FnPtr` from `ReifyReason::VTable`, we
hyphenated the shims. Hyphens are not actually legal, but underscores
are, so use those instead.
2024-04-08 21:21:38 +00:00
Oli Scherer
24ee9b9423 Avoid ICEing without the pattern_types feature gate 2024-04-08 21:02:13 +00:00
Matthias Krüger
0520200a9c
Rollup merge of #123635 - maurer:kcfi-no-assoc, r=compiler-errors
CFI: Fix ICE in KCFI non-associated function pointers

We oddly weren't testing the more usual case of casting non-methods to function pointers. The KCFI shim insertion logic would ICE on these due to asking for an irrefutable associated item if we cast a function to a function pointer without needing a traditional shim.

r? `@compiler-errors`
2024-04-08 22:06:24 +02:00
Matthias Krüger
984767e500
Rollup merge of #123578 - lqd:regression-123275, r=compiler-errors
Restore `pred_known_to_hold_modulo_regions`

As requested by `@lcnr` in https://github.com/rust-lang/rust/issues/123275#issuecomment-2031885563 this PR restores `pred_known_to_hold_modulo_regions` to fix that "unexpected unsized tail" beta regression.

This also adds the reduced repro from https://github.com/rust-lang/rust/issues/123275#issuecomment-2041222851 as a sub-optimal test is better than no test at all, and it'll also cover #108721. It still ICEs on master, even though https://github.com/phlip9/rustc-warp-ice doesn't on nightly anymore, since https://github.com/rust-lang/rust/pull/122493.

Fixes #123275.

r? `@compiler-errors` but feel free to close if you'd rather have a better test instead
cc `@wesleywiser` who had signed up to do the revert

Will need a backport if we go with this PR: `@rustbot` label +beta-nominated
2024-04-08 22:06:23 +02:00
Matthias Krüger
36d1915449
Rollup merge of #123518 - compiler-errors:by-move-fixes, r=oli-obk
Fix `ByMove` coroutine-closure shim (for 2021 precise closure capturing behavior)

This PR reworks the way that we perform the `ByMove` coroutine-closure shim to account for the fact that the upvars of the outer coroutine-closure and the inner coroutine might not line up due to edition-2021 closure capture rules changes.

Specifically, the number of upvars may differ *and/or* the inner coroutine may have additional projections applied to an upvar. This PR reworks the information we pass into the `ByMoveBody` MIR visitor to account for both of these facts.

I tried to leave comments explaining exactly what everything is doing, but let me know if you have questions.

r? oli-obk
2024-04-08 22:06:21 +02:00
Matthias Krüger
0e27c99332
Rollup merge of #123367 - jswrenn:layoutify, r=compiler-errors
Safe Transmute: Compute transmutability from `rustc_target::abi::Layout`

In its first step of computing transmutability, `rustc_transmutability` constructs a byte-level representation of type layout (`Tree`). Previously, this representation was computed for ADTs by inspecting the ADT definition and performing our own layout computations. This process was error-prone, verbose, and limited our ability to analyze many types (particularly default-repr types).

In this PR, we instead construct `Tree`s from `rustc_target::abi::Layout`s. This helps ensure that layout optimizations are reflected our analyses, and increases the kinds of types we can now analyze, including:
- default repr ADTs
- transparent unions
- `UnsafeCell`-containing types

Overall, this PR expands the expressvity of `rustc_transmutability` to be much closer to the transmutability analysis performed by miri. Future PRs will work to close the remaining gaps (e.g., support for `Box`, raw pointers, `NonZero*`, coroutines, etc.).

r? `@compiler-errors`
2024-04-08 22:06:21 +02:00
Matthew Maurer
284da5d6b4 CFI: Fix ICE in KCFI non-associated function pointers
We oddly weren't testing the more usual case of casting non-methods to
function pointers. The KCFI shim insertion logic would ICE on these due
to asking for an irrefutable associated item if we cast a function to a
function pointer without needing a traditional shim.
2024-04-08 17:00:18 +00:00
bors
537aab7a2e Auto merge of #120131 - oli-obk:pattern_types_syntax, r=compiler-errors
Implement minimal, internal-only pattern types in the type system

rebase of https://github.com/rust-lang/rust/pull/107606

You can create pattern types with `std::pat::pattern_type!(ty is pat)`. The feature is incomplete and will panic on you if you use any pattern other than integral range patterns. The only way to create or deconstruct a pattern type is via `transmute`.

This PR's implementation differs from the MCP's text. Specifically

> This means you could implement different traits for different pattern types with the same base type. Thus, we just forbid implementing any traits for pattern types.

is violated in this PR. The reason is that we do need impls after all in order to make them usable as fields. constants of type `std::time::Nanoseconds` struct are used in patterns, so the type must be structural-eq, which it only can be if you derive several traits on it. It doesn't need to be structural-eq recursively, so we can just manually implement the relevant traits on the pattern type and use the pattern type as a private field.

Waiting on:

* [x] move all unrelated commits into their own PRs.
* [x] fix niche computation (see 2db07f94f44f078daffe5823680d07d4fded883f)
* [x] add lots more tests
* [x] T-types MCP https://github.com/rust-lang/types-team/issues/126 to finish
* [x] some commit cleanup
* [x] full self-review
* [x] remove 61bd325da19a918cc3e02bbbdce97281a389c648, it's not necessary anymore I think.
* [ ] ~~make sure we never accidentally leak pattern types to user code (add stability checks or feature gate checks and appopriate tests)~~ we don't even do this for the new float primitives
* [x] get approval that [the scope expansion to trait impls](https://rust-lang.zulipchat.com/#narrow/stream/326866-t-types.2Fnominated/topic/Pattern.20types.20types-team.23126/near/427670099) is ok

r? `@BoxyUwU`
2024-04-08 16:25:23 +00:00
Jack Wrenn
3aa14e3b2e Compute transmutability from rustc_target::abi::Layout
In its first step of computing transmutability, `rustc_transmutability`
constructs a byte-level representation of type layout (`Tree`). Previously, this
representation was computed for ADTs by inspecting the ADT definition and
performing our own layout computations. This process was error-prone, verbose,
and limited our ability to analyze many types (particularly default-repr types).

In this PR, we instead construct `Tree`s from `rustc_target::abi::Layout`s. This
helps ensure that layout optimizations are reflected our analyses, and increases
the kinds of types we can now analyze, including:
- default repr ADTs
- transparent unions
- `UnsafeCell`-containing types

Overall, this PR expands the expressvity of `rustc_transmutability` to be much
closer to the transmutability analysis performed by miri. Future PRs will work
to close the remaining gaps (e.g., support for `Box`, raw pointers, `NonZero*`,
coroutines, etc.).
2024-04-08 15:36:52 +00:00
León Orell Valerian Liehr
8a24ddf64b
Be more specific when flagging imports that are redundant due to the extern prelude 2024-04-08 17:34:06 +02:00
Oli Scherer
dc97b1eb58 Ensure the canonical_param_env_cache does not contain inconsistent information about the defining anchor 2024-04-08 15:08:06 +00:00
Oli Scherer
cd9453c637 Mark some tests as known-bugs and add the test case from the corresponding issue 2024-04-08 15:08:06 +00:00
Oli Scherer
dd72bf922a Scrape extraneous regions from instantiate_nll_query_response_and_region_obligations 2024-04-08 15:00:26 +00:00
Oli Scherer
19bd91d128 Pass list of defineable opaque types into canonical queries 2024-04-08 15:00:26 +00:00
Oli Scherer
0689a4f4f7 Add regression test 2024-04-08 15:00:03 +00:00
Matthias Krüger
337be99bb6
Rollup merge of #120144 - petrochenkov:unty, r=davidtwco
privacy: Stabilize lint `unnameable_types`

This is the last piece of ["RFC #2145: Type privacy and private-in-public lints"](https://github.com/rust-lang/rust/issues/48054).

Having unstable lints is not very useful because you cannot even dogfood them in the compiler/stdlib in this case (https://github.com/rust-lang/rust/pull/113284).
The worst thing that may happen when a lint is removed are some `removed_lints` warnings, but I haven't heard anyone suggesting removing this specific lint.

This lint is allow-by-default and is supposed to be enabled explicitly.
Some false positives are expected, because sometimes unnameable types are a legitimate pattern.
This lint also have some unnecessary false positives, that can be fixed - see https://github.com/rust-lang/rust/issues/120146 and https://github.com/rust-lang/rust/issues/120149.

Closes https://github.com/rust-lang/rust/issues/48054.
2024-04-08 14:31:10 +02:00
Oli Scherer
18ff131c4e Normalize layout test to protect against android alignment differences 2024-04-08 12:06:28 +00:00
Oli Scherer
84acfe86de Actually create ranged int types in the type system. 2024-04-08 12:02:19 +00:00
Oli Scherer
6b24a9cf70 Test macros 2024-04-08 12:02:12 +00:00
Oli Scherer
1d6cd8daf0 Start handling pattern types at the HIR -> Ty conversion boundary 2024-04-08 12:01:50 +00:00
Oli Scherer
c340e67dec Add pattern types to parser 2024-04-08 11:57:17 +00:00
bors
0e5f520788 Auto merge of #123577 - Urgau:prep-work-for-compiletest-check-cfg, r=oli-obk
Do some preparation work for compiletest check-cfg

This PR does several preparation work for having always-on check-cfg in compiletest.

In particular, this PR does two main things:
 - It unifies all the *always-false* cfgs under the `FALSE` cfg (as it seems to be the convention under `tests/ui`)
 - It also removes some useless conditions

This is done ahead of the introduction of the always-on check-cfg in compiletest to reduce the amount of changes in that follow-up work. I also think that this is useful even without that follow-up work.
2024-04-08 09:34:44 +00:00
Michael Goulet
87a387a722 Discard overflow obligations in impl_may_apply 2024-04-07 23:21:45 -04:00
Caio
ab8994d93e Move tests 2024-04-07 17:38:07 -03:00
Michael Goulet
651d02a2f0 Don't even parse an intrinsic unless the feature gate is enabled 2024-04-07 13:30:12 -04:00
Esteban Küber
e572a194bf Fix invalid silencing of parsing error
Given

```rust
macro_rules! a {
    ( ) => {
        impl<'b> c for d {
            e::<f'g>
        }
    };
}
```

ensure an error is emitted.

Fix #123079.
2024-04-07 17:22:34 +00:00
许杰友 Jieyou Xu (Joe)
de3857e553 tests/ui: remove workaround for broken revisioned run-rustfix test 2024-04-07 17:06:15 +00:00
许杰友 Jieyou Xu (Joe)
5dc276c0da compiletest: properly handle revisioned run-rustfix tests 2024-04-07 17:06:15 +00:00
许杰友 Jieyou Xu (Joe)
d4aeff711e Port over backtrace's line-tables-only test to a ui test 2024-04-07 15:25:38 +00:00
Matthias Krüger
bbc7807b42
Rollup merge of #123579 - matthiaskrgr:I_Love_Tests, r=jieyouxu
add some more tests

Fixes https://github.com/rust-lang/rust/issues/115806
Fixes https://github.com/rust-lang/rust/issues/116710
Fixes https://github.com/rust-lang/rust/issues/123145
Fixes https://github.com/rust-lang/rust/issues/105488
Fixes https://github.com/rust-lang/rust/issues/122488
Fixes https://github.com/rust-lang/rust/issues/123078
2024-04-07 09:17:15 +02:00
Matthias Krüger
4eef6e313e
Rollup merge of #123410 - madsmtm:relax-framework-linking-test, r=fmease
Relax framework linking test

This test was introduced by myself in https://github.com/rust-lang/rust/pull/118644, but was over-specified in that it assumed the path of the linker was always `cc`, which [causes a test failure for Chromium](https://issues.chromium.org/issues/332562251).
2024-04-07 09:17:14 +02:00
Matthias Krüger
88aa71f108 add test for assertion failed: !value.has_infer() #115806
Fixes https://github.com/rust-lang/rust/issues/115806
2024-04-07 01:45:31 +02:00
Rémy Rakic
54f8db8432 add non-regression test for issue 123275 2024-04-06 23:25:58 +00:00
Matthias Krüger
b976142439 add test for ice: unknown alias DefKind: AnonConst #116710
Fixes https://github.com/rust-lang/rust/issues/116710
2024-04-07 01:20:56 +02:00
Urgau
47ff773632 Rename invalid false cfg to valid _false cfg
While `false` is accepted by `--cfg` it isn't by `#[cfg(false)]`
since in that context `false` is the boolean not a ident.
2024-04-07 01:16:46 +02:00
Urgau
3ba0139c66 Remove useless configs in tests
Since they are never set and don't have impact on the test.

Or for the cfg-panic tests are already tested with check-cfg.
2024-04-07 01:16:45 +02:00
Urgau
c4a97d9407 Unify all the always-false cfgs under the FALSE cfg 2024-04-07 01:16:45 +02:00
Matthias Krüger
96dbde796c
Rollup merge of #123563 - Oneirical:version, r=jieyouxu
Rewrite `version` test run-make as an UI test

Claiming the simple `version` test from #121876.

Reasoning: As discussed in #123297, 10 years ago, some changes to CLI flags warranted the creation of the `version` test. Since it's not actually executing the compiled binary, it has no purpose being a `run-make` test and should instead be an UI test.

This is the exact same change as it was shown on my closed PR #123297. Changes were ready, but I did a major Git mishap while trying to fix a tidy error and messed up my branch. The details of this error are explained [here](https://github.com/rust-lang/rust/pull/123297#issuecomment-2041152379).
2024-04-07 00:51:27 +02:00
Matthias Krüger
f51ce75af4
Rollup merge of #123516 - estebank:issue-123428, r=compiler-errors
Do not ICE on field access check on expr with `ty::Error`

Fix #123428
2024-04-07 00:51:26 +02:00
Matthias Krüger
7c43bc0378 add test for ICE: failed to resolve instance for <fn() -> impl ...> #123145
Fixes https://github.com/rust-lang/rust/issues/123145
2024-04-07 00:48:47 +02:00
Matthias Krüger
7836909402 add test for ice called Option::unwrap() on a None value in collector.rs:934:13 #105488
Fixes https://github.com/rust-lang/rust/issues/105488
2024-04-07 00:25:56 +02:00
Matthias Krüger
7d9e1067fd add test for ICE: Unexpected unsized type tail: &ReStatic [u8] #122488
Fixes https://github.com/rust-lang/rust/issues/122488
2024-04-06 23:34:46 +02:00
Matthias Krüger
5dc7fe473b add test for ICE: !base.layout().is_sized() #123078
Fixes https://github.com/rust-lang/rust/issues/123078
2024-04-06 23:30:51 +02:00
Oneirical
a9c0ffa35b Rewrite version test as UI test
fix: re-add stout ignore

restore does-nothing

fix: universal check-pass
2024-04-06 15:14:16 -04:00
Esteban Küber
97ea48ce32 Do not ICE on field access check on expr with ty::Error
Fix #123428
2024-04-06 16:34:57 +00:00
Esteban Küber
731c0e59a4 Account for trait/impl difference when suggesting changing argument from ref to mut ref
Do not ICE when encountering a lifetime error involving an argument with
an immutable reference of a method that differs from the trait definition.

Fix #123414.
2024-04-06 16:23:10 +00:00
Ben Kimock
a7912cb421 Put checks that detect UB under their own flag below debug_assertions 2024-04-06 11:21:47 -04:00
Matthias Krüger
cb7f1eec04
Rollup merge of #122291 - lilasta:stabilize_const_location_fields, r=dtolnay
Stabilize `const_caller_location` and `const_location_fields`

Closes #102911. Closes #76156.

tests: [library/core/tests/panic/location.rs](3521a2f2f3/library/core/tests/panic/location.rs)

API:
```rust
// core::panic::location
impl Location {
    pub const fn caller() -> &'static Location<'static>;
    pub const fn file(&self) -> &str;
    pub const fn line(&self) -> u32;
    pub const fn column(&self) -> u32;
}
```
2024-04-06 13:00:05 +02:00
bors
3f10032eb0 Auto merge of #123540 - matthiaskrgr:rollup-8ewq0zt, r=matthiaskrgr
Rollup of 7 pull requests

Successful merges:

 - #123294 (Require LLVM_CONFIG to be set in rustc_llvm/build.rs)
 - #123467 (MSVC targets should use COFF as their archive format)
 - #123498 (explaining `DefKind::Field`)
 - #123519 (Improve cfg and check-cfg configuration)
 - #123525 (CFI: Don't rewrite ty::Dynamic directly)
 - #123526 (Do not ICE when calling incorrectly defined `transmute` intrinsic)
 - #123528 (Hide async_gen_internals from standard library documentation)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-04-06 08:39:09 +00:00
Mads Marquart
de212963f8 Relax framework linking test
This test was introduced in #118644, but was over-specified in that it assumed the path of the linker was always `cc`.
2024-04-06 09:00:07 +02:00
Matthias Krüger
fc2dbbb12f
Rollup merge of #123526 - estebank:issue-123442, r=compiler-errors
Do not ICE when calling incorrectly defined `transmute` intrinsic

Fix #123442
2024-04-06 08:56:36 +02:00
bors
8d490e33ad Auto merge of #123471 - compiler-errors:match_projection_projections, r=oli-obk
Check def id before calling `match_projection_projections`

When I "inlined" `assemble_candidates_from_predicates` into `for_each_item_bound` in #120584, I forgot to copy over the check that actually made sure the def id of the candidate was equal to the def id of the obligation. This means that we normalize goal a bit too often even if it's not productive to do so.

This PR adds that def id check back.
Fixes #123448
2024-04-06 06:36:42 +00:00
Esteban Küber
aa53bc0b04 Do not ICE when calling incorrectly defined transmute intrinsic
Fix #123442
2024-04-06 01:15:31 +00:00
bors
11853ecd86 Auto merge of #123517 - GuillaumeGomez:rollup-eys3jfp, r=GuillaumeGomez
Rollup of 8 pull requests

Successful merges:

 - #121419 (Add aarch64-apple-visionos and aarch64-apple-visionos-sim tier 3 targets)
 - #123159 (Fix target-cpu fpu features on Arm R/M-profile)
 - #123487 (CFI: Restore typeid_for_instance default behavior)
 - #123500 (Revert removing miri jobserver workaround)
 - #123505 (Revert "Use OS thread name by default")
 - #123509 (Add jieyouxu to compiler review rotation and as a reviewer for `tests/run-make`, `src/tools/run-make-support` and `src/tools/compiletest`)
 - #123514 (Fix typo in `compiler/rustc_middle/src/traits/solve/inspect.rs`)
 - #123515 (Use `include` command to reduce code duplication)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-04-05 22:12:43 +00:00
Michael Goulet
ad0fcac72b Account for an additional reborrow inserted by UniqueImmBorrow and MutBorrow 2024-04-05 17:35:03 -04:00
Michael Goulet
49c4ebcc40 Check the base of the place too! 2024-04-05 16:48:45 -04:00
Guillaume Gomez
74a5bc6c9e
Rollup merge of #121419 - agg23:xrOS-pr, r=davidtwco
Add aarch64-apple-visionos and aarch64-apple-visionos-sim tier 3 targets

Introduces `aarch64-apple-visionos` and `aarch64-apple-visionos-sim` as tier 3 targets. This allows native development for the Apple Vision Pro's visionOS platform.

This work has been tracked in https://github.com/rust-lang/compiler-team/issues/642. There is a corresponding `libc` change https://github.com/rust-lang/libc/pull/3568 that is not required for merge.

Ideally we would be able to incorporate [this change](https://github.com/gimli-rs/object/pull/626) to the `object` crate, but the author has stated that a release will not be cut for quite a while. Therefore, the two locations that would reference the xrOS constant from `object` are hardcoded to their MachO values of 11 and 12, accompanied by TODOs to mark the code as needing change. I am open to suggestions on what to do here to get this checked in.

# Tier 3 Target Policy

At this tier, the Rust project provides no official support for a target, so we place minimal requirements on the introduction of targets.

> A tier 3 target must have a designated developer or developers (the "target maintainers") on record to be CCed when issues arise regarding the target. (The mechanism to track and CC such developers may evolve over time.)

See [src/doc/rustc/src/platform-support/apple-visionos.md](e88379034a/src/doc/rustc/src/platform-support/apple-visionos.md)

> Targets must use naming consistent with any existing targets; for instance, a target for the same CPU or OS as an existing Rust target should use the same name for that CPU or OS. Targets should normally use the same names and naming conventions as used elsewhere in the broader ecosystem beyond Rust (such as in other toolchains), unless they have a very good reason to diverge. Changing the name of a target can be highly disruptive, especially once the target reaches a higher tier, so getting the name right is important even for a tier 3 target.
> * Target names should not introduce undue confusion or ambiguity unless absolutely necessary to maintain ecosystem compatibility. For example, if the name of the target makes people extremely likely to form incorrect beliefs about what it targets, the name should be changed or augmented to disambiguate it.
> * If possible, use only letters, numbers, dashes and underscores for the name. Periods (.) are known to cause issues in Cargo.

This naming scheme matches `$ARCH-$VENDOR-$OS-$ABI` which is matches the iOS Apple Silicon simulator (`aarch64-apple-ios-sim`) and other Apple targets.

> Tier 3 targets may have unusual requirements to build or use, but must not
  create legal issues or impose onerous legal terms for the Rust project or for
  Rust developers or users.
>  - The target must not introduce license incompatibilities.
>  - Anything added to the Rust repository must be under the standard Rust license (`MIT OR Apache-2.0`).
>  - The target must not cause the Rust tools or libraries built for any other host (even when supporting cross-compilation to the target) to depend on any new dependency less permissive than the Rust licensing policy. This applies whether the dependency is a Rust crate that would require adding new license exceptions (as specified by the `tidy` tool in the rust-lang/rust repository), or whether the dependency is a native library or binary. In other words, the introduction of the target must not cause a user installing or running a version of Rust or the Rust tools to besubject to any new license requirements.
>  - Compiling, linking, and emitting functional binaries, libraries, or other code for the target (whether hosted on the target itself or cross-compiling from another target) must not depend on proprietary (non-FOSS) libraries. Host tools built for the target itself may depend on the ordinary runtime libraries supplied by the platform and commonly used by other applications built for the target, but those libraries must not be required for code generation for the target; cross-compilation to the target must not require such libraries at all. For instance, `rustc` built for the target may depend on a common proprietary C runtime library or console output library, but must not depend on a proprietary code generation library or code optimization library. Rust's license permits such combinations, but the Rust project has no interest in maintaining such combinations within the scope of Rust itself, even at tier 3.
> - "onerous" here is an intentionally subjective term. At a minimum, "onerous" legal/licensing terms include but are *not* limited to: non-disclosure requirements, non-compete requirements, contributor license agreements (CLAs) or equivalent, "non-commercial"/"research-only"/etc terms, requirements conditional on the employer or employment of any particular Rust developers, revocable terms, any requirements that create liability for the Rust project or its developers or users, or any requirements that adversely affect the livelihood or prospects of the Rust project or its developers or users.

This contribution is fully available under the standard Rust license with no additional legal restrictions whatsoever. This PR does not introduce any new dependency less permissive than the Rust license policy.

The new targets do not depend on proprietary libraries.

> Tier 3 targets should attempt to implement as much of the standard libraries as possible and appropriate (core for most targets, alloc for targets that can support dynamic memory allocation, std for targets with an operating system or equivalent layer of system-provided functionality), but may leave some code unimplemented (either unavailable or stubbed out as appropriate), whether because the target makes it impossible to implement or challenging to implement. The authors of pull requests are not obligated to avoid calling any portions of the standard library on the basis of a tier 3 target not implementing those portions.

This new target mirrors the standard library for watchOS and iOS, with minor divergences.

> The target must provide documentation for the Rust community explaining how to build for the target, using cross-compilation if possible. If the target supports running binaries, or running tests (even if they do not pass), the documentation must explain how to run such binaries or tests for the target, using emulation if possible or dedicated hardware if necessary.

Documentation is provided in [src/doc/rustc/src/platform-support/apple-visionos.md](e88379034a/src/doc/rustc/src/platform-support/apple-visionos.md)

> Neither this policy nor any decisions made regarding targets shall create any binding agreement or estoppel by any party. If any member of an approving Rust team serves as one of the maintainers of a target, or has any legal or employment requirement (explicit or implicit) that might affect their decisions regarding a target, they must recuse themselves from any approval decisions regarding the target's tier status, though they may otherwise participate in discussions.
> * This requirement does not prevent part or all of this policy from being cited in an explicit contract or work agreement (e.g. to implement or maintain support for a target). This requirement exists to ensure that a developer or team responsible for reviewing and approving a target does not face any legal threats or obligations that would prevent them from freely exercising their judgment in such approval, even if such judgment involves subjective matters or goes beyond the letter of these requirements.

> Tier 3 targets must not impose burden on the authors of pull requests, or other developers in the community, to maintain the target. In particular, do not post comments (automated or manual) on a PR that derail or suggest a block on the PR based on a tier 3 target. Do not send automated messages or notifications (via any medium, including via `@)` to a PR author or others involved with a PR regarding a tier 3 target, unless they have opted into such messages.
> * Backlinks such as those generated by the issue/PR tracker when linking to an issue or PR are not considered a violation of this policy, within reason. However, such messages (even on a separate repository) must not generate notifications to anyone involved with a PR who has not requested such notifications.

> Patches adding or updating tier 3 targets must not break any existing tier 2 or tier 1 target, and must not knowingly break another tier 3 target without approval of either the compiler team or the maintainers of the other tier 3 target.
> * In particular, this may come up when working on closely related targets, such as variations of the same architecture with different features. Avoid introducing unconditional uses of features that another variation of the target may not have; use conditional compilation or runtime detection, as appropriate, to let each target run code supported by that target.

I acknowledge these requirements and intend to ensure that they are met.

This target does not touch any existing tier 2 or tier 1 targets and should not break any other targets.
2024-04-05 22:33:25 +02:00
bors
9d79cd5f79 Auto merge of #122747 - Urgau:non-local-defs_perfect_impl, r=lcnr
Implement T-types suggested logic for perfect non-local impl detection

This implement [T-types suggested logic](https://github.com/rust-lang/rust/issues/121621#issuecomment-1976826895) for perfect non-local impl detection:

> for each impl, instantiate all local types with inference vars and then assemble candidates for that goal, if there are more than 1 (non-private impls), it does not leak

This extension to the current logic is meant to address issues reported in https://github.com/rust-lang/rust/issues/121621.

This PR also re-enables the lint `non_local_definitions` to warn-by-default.

Implementation was discussed in this [zulip thread](https://rust-lang.zulipchat.com/#narrow/stream/144729-t-types/topic/Implementing.20new.20non-local.20impl.20defs.20logic).

Fixes https://github.com/rust-lang/rust/issues/121621
Fixes https://github.com/rust-lang/rust/issues/121746

r? `@lcnr` *(feel free to re-roll)*
2024-04-05 20:09:57 +00:00
Esteban Küber
9de6b70bb6 Provide suggestion to dereference closure tail if appropriate
When encoutnering a case like

```rust
//@ run-rustfix
use std::collections::HashMap;

fn main() {
    let vs = vec![0, 0, 1, 1, 3, 4, 5, 6, 3, 3, 3];

    let mut counts = HashMap::new();
    for num in vs {
        let count = counts.entry(num).or_insert(0);
        *count += 1;
    }

    let _ = counts.iter().max_by_key(|(_, v)| v);
```
produce the following suggestion
```
error: lifetime may not live long enough
  --> $DIR/return-value-lifetime-error.rs:13:47
   |
LL |     let _ = counts.iter().max_by_key(|(_, v)| v);
   |                                       ------- ^ returning this value requires that `'1` must outlive `'2`
   |                                       |     |
   |                                       |     return type of closure is &'2 &i32
   |                                       has type `&'1 (&i32, &i32)`
   |
help: dereference the return value
   |
LL |     let _ = counts.iter().max_by_key(|(_, v)| **v);
   |                                               ++
```

Fix #50195.
2024-04-05 19:42:55 +00:00
Michael Goulet
3674032eb2 Rework the ByMoveBody shim to actually work correctly 2024-04-05 15:28:13 -04:00
Urgau
2f2d5cc38d Put non_local_definitions lint back to warn-by-default 2024-04-05 19:25:58 +02:00
Urgau
8edf2558d2 Update non-local impl definition lint rule note 2024-04-05 19:25:58 +02:00
Urgau
a1d7bff7ef Eliminate false-positives in the non-local lint with the type-system 2024-04-05 19:25:43 +02:00
Guillaume Gomez
02ee8a8cee
Rollup merge of #123350 - compiler-errors:async-closure-by-move, r=oli-obk
Actually use the inferred `ClosureKind` from signature inference in coroutine-closures

A follow-up to https://github.com/rust-lang/rust/pull/123349, which fixes another subtle bug: We were not taking into account the async closure kind we infer during closure signature inference.

When I pass a closure directly to an arg like `fn(x: impl async FnOnce())`, that should have the side-effect of artificially restricting the kind of the async closure to `ClosureKind::FnOnce`. We weren't doing this -- that's a quick fix; however, it uncovers a second, more subtle bug with the way that `move`, async closures, and `FnOnce` interact.

Specifically, when we have an async closure like:
```
let x = Struct;
let c = infer_as_fnonce(async move || {
  println!("{x:?}");
}
```

The outer closure captures `x` by move, but the inner coroutine still immutably borrows `x` from the outer closure. Since we've forced the closure to by `async FnOnce()`, we can't actually *do* a self borrow, since the signature of `AsyncFnOnce::call_once` doesn't have a borrowed lifetime. This means that all `async move` closures that are constrained to `FnOnce` will fail borrowck.

We can fix that by detecting this case specifically, and making the *inner* async closure `move` as well. This is always beneficial to closure analysis, since if we have an `async FnOnce()` that's `move`, there's no reason to ever borrow anything, so `move` isn't artificially restrictive.
2024-04-05 16:38:51 +02:00
Guillaume Gomez
f2f8d8b722
Rollup merge of #123311 - Jules-Bertholet:andpat-everywhere, r=Nadrieril
Match ergonomics: implement "`&`pat everywhere"

Implements the eat-two-layers (feature gate `and_pat_everywhere`, all editions) ~and the eat-one-layer (feature gate `and_eat_one_layer_2024`, edition 2024 only, takes priority on that edition when both feature gates are active)~ (EDIT: will be done in later PR) semantics.

cc #123076

r? ``@Nadrieril``

``@rustbot`` label A-patterns A-edition-2024
2024-04-05 16:38:50 +02:00
Guillaume Gomez
cb6a1c8d45
Rollup merge of #122894 - compiler-errors:downgrade, r=lcnr
Move check for error in impl header outside of reporting

Fixes #121006

r? lcnr

test location kinda sucks, can move it if needed
2024-04-05 16:38:49 +02:00
bors
c0ddaef075 Auto merge of #123444 - saethlin:const-eval-inline-cycles, r=tmiasko
Teach MIR inliner query cycle avoidance about const_eval_select

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

r? tmiasko
2024-04-05 04:34:05 +00:00
Jacob Pratt
e8b0c30578
Rollup merge of #123478 - maurer:cfi-call-once-addr-taken, r=compiler-errors
CFI: Add test for `call_once` addr taken

One of the proposed ways to reduce the non-passed argument erasure would cause this test to fail. Adding this now ensures that any attempt to reduce non-passed argument erasure won't make the same mistake.

r? `@compiler-errors`

cc `@rcvalle`
2024-04-04 21:16:59 -04:00
Jacob Pratt
fcb0e9d07a
Rollup merge of #123363 - lcnr:normalizes-to-zero-to-inf, r=BoxyUwU
change `NormalizesTo` to fully structurally normalize

notes in https://hackmd.io/wZ016dE4QKGIhrOnHLlThQ

need to also update the dev-guide once this PR lands. in short, the setup is now as follows:

`normalizes-to` internally implements one step normalization, applying that normalization to the `goal.predicate.term` causes the projected term to get recursively normalized. With this `normalizes-to` normalizes until the projected term is rigid, meaning that we normalize as many steps necessary, but at least 1.

To handle rigid aliases, we add another candidate only if the 1 to inf step normalization failed. With this `normalizes-to` is now full structural normalization. We can now change `AliasRelate` to simply emit `normalizes-to` goals for the rhs and lhs.

This avoids the concerns from https://github.com/rust-lang/trait-system-refactor-initiative/issues/103 and generally feels cleaner
2024-04-04 21:16:56 -04:00
Michael Goulet
55e46612c1 Force move async-closures that are FnOnce to make their inner coroutines also move 2024-04-04 19:44:51 -04:00
Michael Goulet
3d9d5d7c96 Actually use the inferred ClosureKind from signature inference in coroutine-closures 2024-04-04 19:44:35 -04:00
Matthew Maurer
b53a0f2c9e CFI: Add test for call_once addr taken
One of the proposed ways to reduce the non-passed argument erasure would
cause this test to fail. Adding this now ensures that any attempt to
reduce non-passed argument erasure won't make the same mistake.
2024-04-04 22:06:58 +00:00
Michael Goulet
43dae69341 Check def id before calling match_projection_projections 2024-04-04 16:01:13 -04:00
bors
a4b11c8e60 Auto merge of #121394 - oli-obk:define_opaque_types, r=compiler-errors
some smaller DefiningOpaqueTypes::No -> Yes switches

r? `@compiler-errors`

These are some easy cases, so let's get them out of the way first.
I added tests exercising the specialization code paths that I believe weren't tested so far.

follow-up to https://github.com/rust-lang/rust/pull/117348
2024-04-04 17:42:07 +00:00
Oli Scherer
4e8d2f0040 Add regression test 2024-04-04 15:45:50 +00:00
Oli Scherer
0183d92df0 Allow defining opaque types when checking const equality bounds 2024-04-04 15:43:02 +00:00
bors
0fd571286e Auto merge of #123377 - oli-obk:private_projection, r=compiler-errors
Only inspect user-written predicates for privacy concerns

fixes #123288

Previously we looked at the elaborated predicates, which, due to adding various bounds on fields, end up requiring trivially true bounds. But these bounds can contain private types, which the privacy visitor then found and errored about.
2024-04-04 15:39:00 +00:00
Oli Scherer
29fba9f994 Add regression test 2024-04-04 15:15:21 +00:00
Oli Scherer
8e226e092e Add some regression tests for opaque types and const generics 2024-04-04 15:02:27 +00:00
Oli Scherer
ba316a902d amend to Switch can_eq and can_sub to DefineOpaqueTypes::Yes 2024-04-04 14:53:31 +00:00
Oli Scherer
83bd12c70f Only inspect user-written predicates for privacy concerns 2024-04-04 14:43:44 +00:00
Oli Scherer
169a045dca Switch upcast projections to allowing opaque types and add a test showing it works.
The old solver was already ICEing on this test before this change
2024-04-04 14:25:50 +00:00
Oli Scherer
cdcca7e8f4 Switch can_eq and can_sub to DefineOpaqueTypes::Yes
They are mostly used in diagnostics anyway
2024-04-04 14:25:45 +00:00
Matthias Krüger
ad300b6738
Rollup merge of #123431 - slanterns:literal_byte_character_c_string_stabilize, r=dtolnay
Stabilize `proc_macro_byte_character` and `proc_macro_c_str_literals`

This PR stabilizes `proc_macro_byte_character` and `proc_macro_c_str_literals`:

```rust
// proc_macro::Literal

impl Literal {
    pub fn byte_character(byte: u8) -> Literal;
    pub fn c_string(string: &CStr) -> Literal
}
```

<br>

Tracking issue: https://github.com/rust-lang/rust/issues/115268, https://github.com/rust-lang/rust/issues/119750.
Implementation PR: https://github.com/rust-lang/rust/pull/112711, https://github.com/rust-lang/rust/pull/119651.

FCPs already completed in their respective tracking issues.

Closes https://github.com/rust-lang/rust/issues/115268. Closes https://github.com/rust-lang/rust/issues/119750.

r? libs-api
2024-04-04 14:51:18 +02:00
Matthias Krüger
f254ab08f1
Rollup merge of #123397 - krtab:foreign_fn_qualif_diag, r=petrochenkov
Fix diagnostic for qualifier in extern block

Closes: https://github.com/rust-lang/rust/issues/123306
2024-04-04 14:51:17 +02:00
Matthias Krüger
504a78e2f2
Rollup merge of #123324 - Nadrieril:false-edges2, r=matthewjasper
match lowering: make false edges more precise

When lowering match expressions, we add false edges to hide details of the lowering from borrowck. Morally we pretend we're testing the patterns (and guards) one after the other in order. See the tests for examples. Problem is, the way we implement this today is too coarse for deref patterns.

In deref patterns, a pattern like `deref [1, x]` matches on a `Vec` by creating a temporary to store the output of the call to `deref()` and then uses that to continue matching. Here the pattern has a binding, which we set up after the pre-binding block. Problem is, currently the false edges tell borrowck that the pre-binding block can be reached from a previous arm as well, so the `deref()` temporary may not be initialized. This triggers an error when we try to use the binding `x`.

We could call `deref()` a second time, but this opens the door to soundness issues if the deref impl is weird. Instead in this PR I rework false edges a little bit.

What we need from false edges is a (fake) path from each candidate to the next, specifically from candidate C's pre-binding block to next candidate D's pre-binding block. Today, we link the pre-binding blocks directly. In this PR, I link them indirectly by choosing an earlier node on D's success path. Specifically, I choose the earliest block on D's success path that doesn't make a loop (if I chose e.g. the start block of the whole match (which is on the success path of all candidates), that would make a loop). This turns out to be rather straightforward to implement.

r? `@matthewjasper` if you have the bandwidth, otherwise let me know
2024-04-04 14:51:16 +02:00
Matthias Krüger
7c2d4eaf92
Rollup merge of #123218 - compiler-errors:synthetic-hir-parent, r=petrochenkov
Add test for getting parent HIR for synthetic HIR node

Fixes #122991, which was actually fixed by #123415
2024-04-04 14:51:16 +02:00
Matthias Krüger
0b54db7e3f
Rollup merge of #122448 - high-cloud:move-hir-tree, r=oli-obk
Port hir-tree run-make test to ui test

As part of #121876

cc `@jieyouxu`
2024-04-04 14:51:15 +02:00
Matthias Krüger
d5a657c95c
Rollup merge of #121546 - gurry:121473-ice-sizeof-mir-op, r=oli-obk
Error out of layout calculation if a non-last struct field is unsized

Fixes #121473
Fixes #123152
2024-04-04 14:51:14 +02:00
Yaodong Yang
2575b8e79c move hir-tree test from run-make to ui test 2024-04-04 18:43:26 +08:00
lcnr
92b280ce81 normalizes-to change from '1' to '0 to inf' steps 2024-04-04 12:39:58 +02:00
Gurinder Singh
313714331a Error out of layout calculation if a non-last struct field is unsized
Fixes an ICE that occurs when a struct with an unsized field
at a non-last position is const evaluated.
2024-04-04 15:50:36 +05:30
Oli Scherer
b8bd981545 Specialization already rejects defining opaque types 2024-04-04 10:01:45 +00:00
Arthur Carcano
109daa2d4b Fix diagnostic for qualifier in extern block
Closes: https://github.com/rust-lang/rust/issues/123306
2024-04-04 11:58:38 +02:00
Oli Scherer
769ab55558 Add regression test 2024-04-04 09:37:25 +00:00
bors
4c6c629866 Auto merge of #115538 - lcnr:fn-def-wf, r=compiler-errors
check `FnDef` return type for WF

better version of #106807, fixes #84533 (mostly). It's not perfect given that we still ignore WF requirements involving bound regions but I wasn't able to quickly write an example, so even if theoretically exploitable, it should be far harder to trigger.

This is strictly more restrictive than checking the return type for WF as part of the builtin `FnDef: FnOnce` impl (#106807) and moving to this approach in the future will not break any code.

~~It also agrees with my theoretical view of how this should behave~~

r? types
2024-04-04 08:43:53 +00:00
bors
29fe618f75 Auto merge of #123052 - maurer:addr-taken, r=compiler-errors
CFI: Support function pointers for trait methods

Adds support for both CFI and KCFI for function pointers to trait methods by attaching both concrete and abstract types to functions.

KCFI does this through generation of a `ReifyShim` on any function pointer for a method that could go into a vtable, and keeping this separate from `ReifyShim`s that are *intended* for vtable us by setting a `ReifyReason` on them.

CFI does this by setting both the concrete and abstract type on every instance.

This should land after #123024 or a similar PR, as it diverges the implementation of CFI vs KCFI.

r? `@compiler-errors`
2024-04-04 06:40:30 +00:00
lcnr
d99c775feb unconstrained NormalizesTo term for opaques 2024-04-04 07:47:22 +02:00
bors
43f4f2a3b1 Auto merge of #119820 - lcnr:leak-check-2, r=jackh726
instantiate higher ranked goals outside of candidate selection

This PR modifies `evaluate` to more eagerly instantiate higher-ranked goals, preventing the `leak_check` during candidate selection from detecting placeholder errors involving that binder.

For a general background regarding higher-ranked region solving and the leak check, see https://hackmd.io/qd9Wp03cQVy06yOLnro2Kg.

> The first is something called the **leak check**. You can think of it as a "quick and dirty" approximation for the region check, which will come later. The leak check detects some kinds of errors early, essentially deciding between "this set of outlives constraints are guaranteed to result in an error eventually" or "this set of outlives constraints may be solvable".

## The ideal future

We would like to end up with the following idealized design to handle universal binders:
```rust
fn enter_forall<'tcx, T, R>(
    forall: Binder<'tcx, T>,
    f: impl FnOnce(T) -> R,
) -> R {
    let new_universe = infcx.increment_universe_index();
    let value = instantiate_binder_with_placeholders_in(new_universe, forall);

    let result = f(value);

    eagerly_handle_higher_ranked_region_constraints_in(new_universe);
    infcx.decrement_universe_index();

    assert!(!result.has_placeholders_in_or_above(new_universe));
    result
}
```

That is, when universally instantiating a binder, anything using the placeholders has to happen inside of a limited scope (the closure `f`). After this closure has completed, all constraints involving placeholders are known.

We then handle any *external constraints* which name these placeholders. We destructure `TypeOutlives` constraints involving placeholders and eagerly handle any region constraints involving these placeholders. We do not return anything mentioning the placeholders created inside of this function to the caller.

Being able to eagerly handle *all* region constraints involving placeholders will be difficult due to complex `TypeOutlives` constraints, involving inference variables or alias types, and higher ranked implied bounds. The exact issues and possible solutions are out of scope of this FCP.

#### How does the leak check fit into this

The `leak_check` is an underapproximation of `eagerly_handle_higher_ranked_region_constraints_in`. It detects some kinds of errors involving placeholders from `new_universe`, but not all of them.

It only looks at region outlives constraints, ignoring `TypeOutlives`, and checks whether one of the following two conditions are met for **placeholders in or above `new_universe`**, in which case it results in an error:
- `'!p1: '!p2` a placeholder `'!p2` outlives a different placeholder `'!p1`
- `'!p1: '?2` an inference variable `'?2` outlives a placeholder `'!p1` *which it cannot name*

It does not handle all higher ranked region constraints, so we still return constraints involving placeholders from `new_universe` which are then (re)checked by `lexical_region_resolve` or MIR borrowck.

As we check higher ranked constraints in the full regionck anyways, the `leak_check` is not soundness critical. It's current only purpose is to move some higher ranked region errors earlier, enabling it to guide type inference and trait solving. Adding additional uses of the `leak_check` in the future would only strengthen inference and is therefore not breaking.

## Where do we use currently use the leak check

The `leak_check` is currently used in two places:

Coherence does not use a proper regionck, only relying on the `leak_check` called [at the end of the implicit negative overlap check](8b94152af6/compiler/rustc_trait_selection/src/traits/coherence.rs (L235-L238)). During coherence all parameters are instantiated with inference variables, so the only possible region errors are higher-ranked. We currently also sometimes make guesses when destructuring `TypeOutlives` constraints which can theoretically result in incorrect errors. This could result in overlapping impls.

We also use the `leak_check` [at the end of `fn evaluation_probe`](8b94152af6/compiler/rustc_trait_selection/src/traits/select/mod.rs (L607-L610)). This function is used during candidate assembly for `Trait` goals. Most notably we use [inside of `evaluate_candidate` during winnowing](0e4243538b/compiler/rustc_trait_selection/src/traits/select/mod.rs (L491-L502)). Conceptionally, it is as if we compute each candidate in a separate `enter_forall`.

## The current use in `fn evaluation_probe` is undesirable

Because we only instantiate a higher-ranked goal once inside of `fn evaluation_probe`, errors involving placeholders from that binder can impact selection. This results in inconsistent behavior ([playground](
*[playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=dac60ebdd517201788899ffa77364831)*)):

```rust
trait Leak<'a> {}
impl Leak<'_>      for Box<u32> {}
impl Leak<'static> for Box<u16> {}

fn impls_leak<T: for<'a> Leak<'a>>() {}

trait IndirectLeak<'a> {}
impl<'a, T: Leak<'a>> IndirectLeak<'a> for T {}
fn impls_indirect_leak<T: for<'a> IndirectLeak<'a>>() {}

fn main() {
    // ok
    //
    // The `Box<u16>` impls fails the leak check,
    // meaning that we apply the `Box<u32>` impl.
    impls_leak::<Box<_>>();

    // error: type annotations needed
    //
    // While the `Box<u16>` impl would fail the leak check
    // we have already instantiated the binder while applying
    // the generic `IndirectLeak` impl, so during candidate
    // selection of `Leak` we do not detect the placeholder error.
    // Evaluation of `Box<_>: Leak<'!a>` is therefore ambiguous,
    // resulting in `for<'a> Box<_>: Leak<'a>` also being ambiguous.
    impls_indirect_leak::<Box<_>>();
}
```

We generally prefer `where`-bounds over implementations during candidate selection, both for [trait goals](11f32b73e0/compiler/rustc_trait_selection/src/traits/select/mod.rs (L1863-L1887)) and during [normalization](11f32b73e0/compiler/rustc_trait_selection/src/traits/project.rs (L184-L198)). However, we currently **do not** use the `leak_check` during candidate assembly in normalizing. This can result in inconsistent behavior:
```rust
trait Trait<'a> {
    type Assoc;
}
impl<'a, T> Trait<'a> for T {
    type Assoc = usize;
}

fn trait_bound<T: for<'a> Trait<'a>>() {}
fn projection_bound<T: for<'a> Trait<'a, Assoc = usize>>() {}

// A function with a trivial where-bound which is more
// restrictive than the impl.
fn function<T: Trait<'static, Assoc = usize>>() {
    // ok
    //
    // Proving `for<'a> T: Trait<'a>` using the where-bound results
    // in a leak check failure, so we use the more general impl,
    // causing this to succeed.
    trait_bound::<T>();

    // error
    //
    // Proving the `Projection` goal `for<'a> T: Trait<'a, Assoc = usize>`
    // does not use the leak check when trying the where-bound, causing us
    // to prefer it over the impl, resulting in a placeholder error.
    projection_bound::<T>();

    // error
    //
    // Trying to normalize the type `for<'a> fn(<T as Trait<'a>>::Assoc)`
    // only gets to `<T as Trait<'a>>::Assoc` once `'a` has been already
    // instantiated, causing us to prefer the where-bound over the impl
    // resulting in a placeholder error. Even if were were to also use the
    // leak check during candidate selection for normalization, this
    // case would still not compile.
    let _higher_ranked_norm: for<'a> fn(<T as Trait<'a>>::Assoc) = |_| ();
}
```

This is also likely to be more performant. It enables more caching in the new trait solver by simply [recursively calling the canonical query][new solver] after instantiating the higher-ranked goal.

It is also unclear how to add the leak check to normalization in the new solver. To handle https://github.com/rust-lang/trait-system-refactor-initiative/issues/1 `Projection` goals are implemented via `AliasRelate`. This again means that we instantiate the binder before ever normalizing any alias. Even if we were to avoid this, we lose the ability to [cache normalization by itself, ignoring the expected `term`](5bd5d214ef/compiler/rustc_trait_selection/src/solve/normalizes_to/mod.rs (L34-L49)). We cannot replace the `term` with an inference variable before instantiating the binder, as otherwise `for<'a> T: Trait<Assoc<'a> = &'a ()>` breaks. If we only replace the term after instantiating the binder, we cannot easily evaluate the goal in a separate context, as [we'd then lose the information necessary for the leak check](11f32b73e0/compiler/rustc_next_trait_solver/src/canonicalizer.rs (L230-L232)). Adding this information to the canonical input also seems non-trivial.

## Proposed solution

I propose to instantiate the binder outside of candidate assembly, causing placeholders from higher-ranked goals to get ignored while selecting their candidate. This mostly[^1] matches the [current behavior of the new solver][new solver]. The impact of this change is therefore as follows:

```rust
trait Leak<'a> {}
impl Leak<'_>      for Box<u32> {}
impl Leak<'static> for Box<u16> {}

fn impls_leak<T: for<'a> Leak<'a>>() {}

trait IndirectLeak<'a> {}
impl<'a, T: Leak<'a>> IndirectLeak<'a> for T {}
fn impls_indirect_leak<T: for<'a> IndirectLeak<'a>>() {}

fn guide_selection() {
    // ok -> ambiguous
    impls_leak::<Box<_>>();

    // ambiguous
    impls_indirect_leak::<Box<_>>();
}

trait Trait<'a> {
    type Assoc;
}
impl<'a, T> Trait<'a> for T {
    type Assoc = usize;
}

fn trait_bound<T: for<'a> Trait<'a>>() {}
fn projection_bound<T: for<'a> Trait<'a, Assoc = usize>>() {}

// A function which a trivial where-bound which is more
// restrictive than the impl.
fn function<T: Trait<'static, Assoc = usize>>() {
    // ok -> error
    trait_bound::<T>();

    // error
    projection_bound::<T>();

    // error
    let _higher_ranked_norm: for<'a> fn(<T as Trait<'a>>::Assoc) = |_| ();
}
```

This does not change the behavior if candidates have higher ranked nested goals, as in this case the `leak_check` causes the nested goal to result in an error ([playground](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=a74c25300b23db9022226de99d8a2fa6)):
```rust
trait LeakCheckFailure<'a> {}
impl LeakCheckFailure<'static> for () {}

trait Trait<T> {}
impl Trait<u32> for () where for<'a> (): LeakCheckFailure<'a> {}
impl Trait<u16> for () {}
fn impls_trait<T: Trait<U>, U>() {}
fn main() {
    // ok
    //
    // It does not matter whether candidate assembly
    // considers the placeholders from higher-ranked goal.
    //
    // Either `for<'a> (): LeakCheckFailure<'a>` has no
    // applicable candidate or it has a single applicable candidate
    // when then later results in an error. This allows us to
    // infer `U` to `u16`.
    impls_trait::<(), _>()
}
```

## Impact on existing crates

This is a **breaking change**. [A crater run](https://github.com/rust-lang/rust/pull/119820#issuecomment-1926862174) found 17 regressed crates with 7 root causes.

For a full analysis of all affected crates, see https://gist.github.com/lcnr/7c1c652f30567048ea240554a36ed95c.

---

I believe this breakage to be acceptable and would merge this change. I am confident that the new position of the leak check matches our idealized future and cannot envision any other consistent alternative. Where possible, I intend to open PRs fixing/avoiding the regressions before landing this PR.

I originally intended to remove the `coherence_leak_check` lint in the same PR. However, while I am confident in the *position* of the leak check, deciding on its exact behavior is left as future work, cc #112999. This PR therefore only moves the leak check while keeping the lint when relying on it in coherence.

[new solver]: https://github.com/rust-lang/rust/blob/master/compiler/rustc_trait_selection/src/solve/eval_ctxt/mod.rs#L479-L484

[^1]: the new solver has a separate cause of inconsistent behavior rn https://github.com/rust-lang/trait-system-refactor-initiative/issues/53#issuecomment-1914310171

r? `@nikomatsakis`
2024-04-04 04:36:12 +00:00
Ben Kimock
b0b7c860e1 Teach MIR inliner query cycle avoidance about const_eval_select 2024-04-04 00:10:52 -04:00
bors
0accf4ec4c Auto merge of #123440 - jhpratt:rollup-yat6crk, r=jhpratt
Rollup of 4 pull requests

Successful merges:

 - #122356 (std::rand: fix dragonflybsd after #121942.)
 - #123093 (Add a nice header to our README.md)
 - #123307 (Fix f16 and f128 feature gating on different editions)
 - #123401 (Check `x86_64` size assertions on `aarch64`, too)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-04-04 02:11:23 +00:00
Boxy
82789763c7 rebase 2024-04-04 02:14:57 +01:00
lcnr
2b67f0104a check FnDef return type for WF 2024-04-04 01:55:29 +01:00
Jacob Pratt
819568a7b4
Rollup merge of #123307 - tgross35:f16-f128-feature-gate-fix, r=petrochenkov
Fix f16 and f128 feature gating on different editions

Apply the fix from https://github.com/rust-lang/rust/issues/123282#issuecomment-2035063388 to correctly gates `f16` and `f128` in editions other than 2015
2024-04-03 20:17:05 -04:00
bors
b4acbe4233 Auto merge of #123240 - compiler-errors:assert-args-compat, r=fmease
Assert that args are actually compatible with their generics, rather than just their count

Right now we just check that the number of args is right, rather than actually checking the kinds. Uplift a helper fn that I wrote from trait selection to do just that. Found a couple bugs along the way.

r? `@lcnr` or `@fmease` (or anyone really lol)
2024-04-04 00:09:02 +00:00
Boxy
f090de8875 rebase oddity 2024-04-03 22:48:55 +01:00
Michael Goulet
f029602920 Tests for getting parent of synthetic HIR 2024-04-03 17:44:47 -04:00
lcnr
4fa5fb684e move leak check out of candidate evaluation
this prevents higher ranked goals from guiding selection
2024-04-03 22:32:46 +01:00
Nadrieril
e2ebaa1a08 Add if let tests 2024-04-03 23:16:27 +02:00
Slanterns
fbc56dfac1
Stabilize Literal::c_string 2024-04-04 05:04:27 +08:00
Slanterns
61ac7812c6
Stabilize Literal::byte_character 2024-04-04 05:00:49 +08:00
Matthias Krüger
5f74403c8e
Rollup merge of #123301 - Nadrieril:unions, r=compiler-errors
pattern analysis: fix union handling

Little known fact: rust supports union patterns. Exhaustiveness handles them soundly but reports nonsensical missing patterns. This PR fixes the reported patterns and documents what we're doing.

r? `@compiler-errors`
2024-04-03 22:11:01 +02:00
Matthias Krüger
0c8c18fcc6
Rollup merge of #123291 - c410-f3r:testsssssss, r=petrochenkov
Move some tests

r? `@petrochenkov`
2024-04-03 22:11:01 +02:00
Matthias Krüger
80d592cc24
Rollup merge of #122964 - joboet:pointer_expose, r=Amanieu
Rename `expose_addr` to `expose_provenance`

`expose_addr` is a bad name, an address is just a number and cannot be exposed. The operation is actually about the provenance of the pointer.

This PR thus changes the name of the method to `expose_provenance` without changing its return type. There is sufficient precedence for returning a useful value from an operation that does something else without the name indicating such, e.g. [`Option::insert`](https://doc.rust-lang.org/nightly/std/option/enum.Option.html#method.insert) and [`MaybeUninit::write`](https://doc.rust-lang.org/nightly/std/mem/union.MaybeUninit.html#method.write).

Returning the address is merely convenient, not a fundamental part of the operation. This is implied by the fact that integers do not have provenance since
```rust
let addr = ptr.addr();
ptr.expose_provenance();
let new = ptr::with_exposed_provenance(addr);
```
must behave exactly like
```rust
let addr = ptr.expose_provenance();
let new = ptr::with_exposed_provenance(addr);
```
as the result of `ptr.expose_provenance()` and `ptr.addr()` is the same integer. Therefore, this PR removes the `#[must_use]` annotation on the function and updates the documentation to reflect the important part.

~~An alternative name would be `expose_provenance`. I'm not at all opposed to that, but it makes a stronger implication than we might want that the provenance of the pointer returned by `ptr::with_exposed_provenance`[^1] is the same as that what was exposed, which is not yet specified as such IIUC. IMHO `expose` does not make that connection.~~

A previous version of this PR suggested `expose` as name, libs-api [decided on](https://github.com/rust-lang/rust/pull/122964#issuecomment-2033194319) `expose_provenance` to keep the symmetry with `with_exposed_provenance`.

CC `@RalfJung`
r? libs-api

[^1]: I'm using the new name for `from_exposed_addr` suggested by #122935 here.
2024-04-03 22:11:00 +02:00
Matthias Krüger
bc8415b9e6
Rollup merge of #122619 - erikdesjardins:cast, r=compiler-errors
Fix some unsoundness with PassMode::Cast ABI

Fixes #122617

Reviewable commit-by-commit. More info in each commit message.
2024-04-03 22:11:00 +02:00
Matthias Krüger
32c8c5cb7e
Rollup merge of #121595 - strottos:issue_116615, r=compiler-errors
Better reporting on generic argument mismatchs

This allows better reporting as per issue #116615 .

If you have a function:
```
fn foo(a: T, b: T) {}
```
and call it like so:
```
foo(1, 2.)
```
it'll give improved error reported similar to the following:
```
error[E0308]: mismatched types
 --> generic-mismatch-reporting-issue-116615.rs:6:12
  |
6 |     foo(1, 2.);
  |     --- -  ^^ expected integer, found floating-point number
  |     |   |
  |     |   expected argument `b` to be an integer because that argument needs to match the type of this parameter
  |     arguments to this function are incorrect
  |
note: function defined here
 --> generic-mismatch-reporting-issue-116615.rs:1:4
  |
1 | fn foo<T>(a: T, b: T) {}
  |    ^^^ -  ----  ----
  |        |  |     |
  |        |  |     this parameter needs to match the integer type of `a`
  |        |  `b` needs to match the type of this parameter
  |        `a` and `b` all reference this parameter T
```

Open question, do we need to worry about error message translation into other languages? Not sure what the status of that is in Rust.

NB: Needs some checking over and some tests have altered that need sanity checking, but overall this is starting to get somewhere now. Will take out of draft PR status when this has been done, raising now to allow feedback at this stage, probably 90% ready.
2024-04-03 22:10:59 +02:00
Trevor Gross
5afe072ead Fix f16 and f128 feature gates in editions other than 2015
Fixes https://github.com/rust-lang/rust/issues/123282

Co-authored-by: Vadim Petrochenkov <vadim.petrochenkov@gmail.com>
2024-04-03 16:03:22 -04:00
Trevor Gross
9a7b176227 Update f16 and f128 tests to run on both 2015 and 2018 editions
Reproduce the bug from <https://github.com/rust-lang/rust/issues/123282>
that indicates this feature gate hits edition-dependent resolution paths.
Resolution changed in edition 2018, so test that as well.
2024-04-03 16:03:22 -04:00
Nadrieril
50103ab14d Add tests 2024-04-03 21:02:47 +02:00
Michael Goulet
e3025d6a55 Stop chopping off args for no reason 2024-04-03 11:16:58 -04:00
Matthias Krüger
deb48aa0f5
Rollup merge of #123394 - compiler-errors:postfix-match-fixes, r=estebank
Postfix match fixes

1. Don't ice on `expr as Ty.match {}`
2. Fix the suggestion span for non-exhaustive matches to add `_ => todo!(),`

Fixes #123383
2024-04-03 17:15:50 +02:00
joboet
989660c3e6
rename expose_addr to expose_provenance 2024-04-03 16:00:38 +02:00
bors
99c42d2340 Auto merge of #123322 - matthewjasper:remove-mir-unsafeck, r=lcnr,compiler-errors
Remove MIR unsafe check

Now that THIR unsafeck is enabled by default in stable I think we can remove MIR unsafeck entirely. This PR also removes safety information from MIR.
2024-04-03 10:30:34 +00:00
Matthew Jasper
a277c901d9 Remove MIR unsafe check
This also remove safety information from MIR.
2024-04-03 08:50:12 +00:00
Jubilee
f700fb24f3
Rollup merge of #123349 - compiler-errors:async-closure-captures, r=oli-obk
Fix capture analysis for by-move closure bodies

The check we were doing to figure out if a coroutine was borrowing from its parent coroutine-closure was flat-out wrong -- a misunderstanding of mine of the way that `tcx.closure_captures` represents its captures.

Fixes #123251 (the miri/ui test I added should more than cover that issue)

r? `@oli-obk` -- I recognize that this PR may be underdocumented, so please ask me what I should explain further.
2024-04-02 23:44:29 -07:00
bors
b688d53a17 Auto merge of #123396 - jhpratt:rollup-oa54mh1, r=jhpratt
Rollup of 5 pull requests

Successful merges:

 - #122865 (Split hir ty lowerer's error reporting code in check functions to mod errors.)
 - #122935 (rename ptr::from_exposed_addr -> ptr::with_exposed_provenance)
 - #123182 (Avoid expanding to unstable internal method)
 - #123203 (Add `Context::ext`)
 - #123380 (Improve bootstrap comments)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-04-03 02:13:07 +00:00
Jacob Pratt
9c1c0bfcb2
Rollup merge of #123203 - jkarneges:context-ext, r=Amanieu
Add `Context::ext`

This change enables `Context` to carry arbitrary extension data via a single `&mut dyn Any` field.

```rust
#![feature(context_ext)]

impl Context {
    fn ext(&mut self) -> &mut dyn Any;
}

impl ContextBuilder {
    fn ext(self, data: &'a mut dyn Any) -> Self;

    fn from(cx: &'a mut Context<'_>) -> Self;
    fn waker(self, waker: &'a Waker) -> Self;
}
```

Basic usage:

```rust
struct MyExtensionData {
    executor_name: String,
}

let mut ext = MyExtensionData {
    executor_name: "foo".to_string(),
};

let mut cx = ContextBuilder::from_waker(&waker).ext(&mut ext).build();

if let Some(ext) = cx.ext().downcast_mut::<MyExtensionData>() {
    println!("{}", ext.executor_name);
}
```

Currently, `Context` only carries a `Waker`, but there is interest in having it carry other kinds of data. Examples include [LocalWaker](https://github.com/rust-lang/rust/issues/118959), [a reactor interface](https://github.com/rust-lang/libs-team/issues/347), and [multiple arbitrary values by type](https://docs.rs/context-rs/latest/context_rs/). There is also a general practice in the ecosystem of sharing data between executors and futures via thread-locals or globals that would arguably be better shared via `Context`, if it were possible.

The `ext` field would provide a low friction (to stabilization) solution to enable experimentation. It would enable experimenting with what kinds of data we want to carry as well as with what data structures we may want to use to carry such data.

Dedicated fields for specific kinds of data could still be added directly on `Context` when we have sufficient experience or understanding about the problem they are solving, such as with `LocalWaker`. The `ext` field would be for data for which we don't have such experience or understanding, and that could be graduated to dedicated fields once proven.

Both the provider and consumer of the extension data must be aware of the concrete type behind the `Any`. This means it is not possible for the field to carry an abstract interface. However, the field can carry a concrete type which in turn carries an interface. There are different ways one can imagine an interface-carrying concrete type to work, hence the benefit of being able to experiment with such data structures.

## Passing interfaces

Interfaces can be placed in a concrete type, such as a struct, and then that type can be casted to `Any`. However, one gotcha is `Any` cannot contain non-static references. This means one cannot simply do:

```rust
struct Extensions<'a> {
    interface1: &'a mut dyn Trait1,
    interface2: &'a mut dyn Trait2,
}

let mut ext = Extensions {
    interface1: &mut impl1,
    interface2: &mut impl2,
};

let ext: &mut dyn Any = &mut ext;
```

To work around this without boxing, unsafe code can be used to create a safe projection using accessors. For example:

```rust
pub struct Extensions {
    interface1: *mut dyn Trait1,
    interface2: *mut dyn Trait2,
}

impl Extensions {
    pub fn new<'a>(
        interface1: &'a mut (dyn Trait1 + 'static),
        interface2: &'a mut (dyn Trait2 + 'static),
        scratch: &'a mut MaybeUninit<Self>,
    ) -> &'a mut Self {
        scratch.write(Self {
            interface1,
            interface2,
        })
    }

    pub fn interface1(&mut self) -> &mut dyn Trait1 {
        unsafe { self.interface1.as_mut().unwrap() }
    }

    pub fn interface2(&mut self) -> &mut dyn Trait2 {
        unsafe { self.interface2.as_mut().unwrap() }
    }
}

let mut scratch = MaybeUninit::uninit();
let ext: &mut Extensions = Extensions::new(&mut impl1, &mut impl2, &mut scratch);

// ext can now be casted to `&mut dyn Any` and back, and used safely
let ext: &mut dyn Any = ext;
```

## Context inheritance

Sometimes when futures poll other futures they want to provide their own `Waker` which requires creating their own `Context`. Unfortunately, polling sub-futures with a fresh `Context` means any properties on the original `Context` won't get propagated along to the sub-futures. To help with this, some additional methods are added to `ContextBuilder`.

Here's how to derive a new `Context` from another, overriding only the `Waker`:

```rust
let mut cx = ContextBuilder::from(parent_cx).waker(&new_waker).build();
```
2024-04-02 20:37:40 -04:00
Jacob Pratt
e41d7e7aaf
Rollup merge of #123182 - jhpratt:fix-decodable-derive, r=davidtwco
Avoid expanding to unstable internal method

Fixes #123156

Rather than expanding to `std::rt::begin_panic`, the expansion is now to `unreachable!()`. The resulting behavior is identical. A test that previously triggered the same error as #123156 has been added to ensure it does not regress.

r? compiler
2024-04-02 20:37:40 -04:00
Jacob Pratt
e9ef8e1efa
Rollup merge of #122935 - RalfJung:with-exposed-provenance, r=Amanieu
rename ptr::from_exposed_addr -> ptr::with_exposed_provenance

As discussed on [Zulip](https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/To.20expose.20or.20not.20to.20expose/near/427757066).

The old name, `from_exposed_addr`, makes little sense as it's not the address that is exposed, it's the provenance. (`ptr.expose_addr()` stays unchanged as we haven't found a better option yet. The intended interpretation is "expose the provenance and return the address".)

The new name nicely matches `ptr::without_provenance`.
2024-04-02 20:37:39 -04:00
Jacob Pratt
0697ee9af5
Rollup merge of #122865 - surechen:refactor_astconv_error_report_20240321, r=lcnr
Split hir ty lowerer's error reporting code in check functions to mod errors.

Move some error report codes to mod `astconv/errors.rs`

r? `@lcnr`
2024-04-02 20:37:39 -04:00
bors
40f743da23 Auto merge of #122791 - compiler-errors:make-coinductive-always, r=lcnr
Make inductive cycles always ambiguous

 This makes inductive cycles always result in ambiguity rather than be treated like a stack-dependent error.

This has some  interactions with specialization, and so breaks a few UI tests that I don't agree should've ever worked in the first place, and also breaks a handful of crates in a way that I don't believe is a problem.

On the bright side, it puts us in a better spot when it comes to eventually enabling coinduction everywhere.

## Results

This was cratered in https://github.com/rust-lang/rust/pull/116494#issuecomment-2008657494, which boils down to two regressions:
* `lu_packets` - This code should have never compiled in the first place. More below.
* **ALL** other regressions are due to `commit_verify@0.11.0-beta.1` (edit: and `commit_verify@0.10.x`) - This actually seems to be fixed in version `0.11.0-beta.5`, which is the *most* up to date version, but it's still prerelease on crates.io so I don't think cargo ends up picking `beta.5` when building dependent crates.

### `lu_packets`

Firstly, this crate uses specialization, so I think it's automatically worth breaking. However, I've minimized [the regression](https://crater-reports.s3.amazonaws.com/pr-116494-3/try%23d614ed876e31a5f3ad1d0fbf848fcdab3a29d1d8/gh/lcdr.lu_packets/log.txt) to:

```rust
// Upstream crate
pub trait Serialize {}
impl Serialize for &() {}
impl<S> Serialize for &[S] where for<'a> &'a S: Serialize {}

// ----------------------------------------------------------------------- //

// Downstream crate
#![feature(specialization)]
#![allow(incomplete_features, unused)]

use upstream::Serialize;

trait Replica {
    fn serialize();
}

impl<T> Replica for T {
    default fn serialize() {}
}

impl<T> Replica for Option<T>
where
    for<'a> &'a T: Serialize,
{
    fn serialize() {}
}
```

Specifically this fails when computing the specialization graph for the `downstream` crate.

The code ends up cycling on `&[?0]: Serialize` when we equate `&?0 = &[?1]` during impl matching, which ends up needing to prove `&[?1]: Serialize`, which since cycles are treated like ambiguity, ends up in a **fatal overflow**. For some reason this requires two crates, squashing them into one crate doesn't work.

Side-note: This code is subtly order dependent. When minimizing, I ended up having the code start failing on `nightly` very easily after removing and reordering impls. This seems to me all the more reason to remove this behavior altogether.

## Side-note: Item Bounds (edit: this was fixed independently in #121123)

Due to the changes in #120584 where we now consider an alias's item bounds *and* all the item bounds of the alias's nested self type aliases, I've had to add e6b64c6194 which is a hack to make sure we're not eagerly normalizing bounds that have nothing to do with the predicate we're trying to solve, and which result in.

This is fixed in a more principled way in #121123.

---

r? lcnr for an initial review
2024-04-03 00:09:44 +00:00
Michael Goulet
ec74a304bb Comments, comments, comments 2024-04-02 20:07:49 -04:00
Michael Goulet
a1a1f41027 Fix capture analysis for by-move closure bodies 2024-04-02 20:07:48 -04:00
Michael Goulet
bed8b70d67 Fix suggestions for match non-exhaustiveness 2024-04-02 19:06:28 -04:00
Michael Goulet
9d116e8e18 Don't ICE for postfix match after as 2024-04-02 18:31:42 -04:00
Jacob Pratt
0fcdf34861
Avoid expanding to unstable internal method 2024-04-02 22:21:16 +00:00
Matthias Krüger
9372948889
Rollup merge of #123368 - maurer:cfi-non-general-coroutines, r=compiler-errors
CFI: Support non-general coroutines

Previously, we assumed all `ty::Coroutine` were general coroutines and attempted to generalize them through the `Coroutine` trait. Select appropriate traits for each kind of coroutine.

I have this marked as a draft because it currently only fixes async coroutines, and I think it make sense to try to fix gen/async gen coroutines before this is merged.

If the issue [mentioned](https://github.com/rust-lang/rust/pull/123106#issuecomment-2030794213) in the original PR is actually affecting someone, we can land this as is to remedy it.
2024-04-02 21:22:03 +02:00
Matthias Krüger
5b717684ff
Rollup merge of #123362 - oli-obk:thread_local_nested_statics, r=estebank
Check that nested statics in thread locals are duplicated per thread.

follow-up to #123310

cc ``@compiler-errors`` ``@RalfJung``

fwiw: I have no idea how thread local statics make that work under LLVM, and miri fails on this example, which I would have expected to be the correct behaviour.

Since the `#[thread_local]` attribute is just an internal implementation detail, I'm just going to start hard erroring on nested mutable statics in thread locals.
2024-04-02 21:22:03 +02:00
Matthias Krüger
a38dde9289
Rollup merge of #123302 - compiler-errors:sized-bound-first, r=estebank
Make sure to insert `Sized` bound first into clauses list

#120323 made it so that we don't insert an implicit `Sized` bound whenever we see an *explicit* `Sized` bound. However, since the code that inserts implicit sized bounds puts the bound as the *first* in the list, that means that it had the **side-effect** of possibly meaning we check `Sized` *after* checking other trait bounds.

If those trait bounds result in ambiguity or overflow or something, it may change how we winnow candidates. (**edit: SEE** #123303) This is likely the cause for the regression in https://github.com/rust-lang/rust/issues/123279#issuecomment-2028899598, since the impl...

```rust
impl<T: Job + Sized> AsJob for T { // <----- changing this to `Sized + Job` or just `Job` (which turns into `Sized + Job`) will FIX the issue.
}
```

...looks incredibly suspicious.

Fixes [after beta-backport] #123279.

Alternative is to revert #120323. I don't have a strong opinion about this, but think it may be nice to keep the diagnostic changes around.
2024-04-02 21:22:01 +02:00
Matthias Krüger
1b0e46f8a0
Rollup merge of #123226 - scottmcm:u32-shifts, r=WaffleLapkin
De-LLVM the unchecked shifts [MCP#693]

This is just one part of the MCP (https://github.com/rust-lang/compiler-team/issues/693), but it's the one that IMHO removes the most noise from the standard library code.

Seems net simpler this way, since MIR already supported heterogeneous shifts anyway, and thus it's not more work for backends than before.

r? WaffleLapkin
2024-04-02 21:22:01 +02:00
Matthew Maurer
473a70de84 CFI: Support function pointers for trait methods
Adds support for both CFI and KCFI for attaching concrete and abstract
types to functions. KCFI does this through generation of `ReifyShim` on
any function pointer that could go in a vtable, and checking the
`ReifyReason` when emitting the instance. CFI does this by attaching
both the concrete and abstract type to every instance.

TypeID codegen tests are switched to be anchored on the left rather than
the right in order to allow emission of additional type attachments.

Fixes #115953
2024-04-02 19:11:16 +00:00
Matthew Maurer
a333b82d04 CFI: Support non-general coroutines
Previously, we assumed all `ty::Coroutine` were general coroutines and
attempted to generalize them through the `Coroutine` trait. Select
appropriate traits for each kind of coroutine.
2024-04-02 17:34:42 +00:00
Eduardo Sánchez Muñoz
858a1dfd5b Remove dangling .mir.stderr and .thir.stderr test files 2024-04-02 18:02:06 +02:00
Jules Bertholet
9d200f2d88
Address review comments 2024-04-02 10:57:54 -05:00
Oli Scherer
64b75f736d Forbid implicit nested statics in thread local statics 2024-04-02 13:00:46 +00:00
surechen
1012218ba8 t plit astconv's error report code in check functions to mod errors.
Move some error report codes to mod `astconv/errors.rs`
2024-04-02 20:10:35 +08:00
Oli Scherer
6c5c48e880 Check that nested statics in thread locals are duplicated per thread. 2024-04-02 12:06:52 +00:00
Michael Goulet
09ea3f93ee Fix obligation param and bless tests 2024-04-01 22:48:23 -04:00
Michael Goulet
5f59b7f763 Instantiate closure-like bounds with placeholders to deal with binders correctly 2024-04-01 22:48:23 -04:00
Michael Goulet
f2fd2d8c70 Make sure to insert Sized bound first into clauses list 2024-04-01 21:41:45 -04:00
bors
c518e5aeec Auto merge of #123265 - joboet:guardians_of_the_unix, r=ChrisDenton
Refactor stack overflow handling

Currently, every platform must implement a `Guard` that protects a thread from stack overflow. However, UNIX is the only platform that actually does so. Windows has a different mechanism for detecting stack overflow, while the other platforms don't detect it at all. Also, the UNIX stack overflow handling is split between `sys::pal::unix::stack_overflow`, which implements the signal handler, and `sys::pal::unix::thread`, which detects/installs guard pages.

This PR cleans this by getting rid of `Guard` and unifying UNIX stack overflow handling inside `stack_overflow` (commit 1). Therefore we can get rid of `sys_common::thread_info`, which stores `Guard` and the current `Thread` handle and move the `thread::current` TLS variable into `thread` (commit 2).

The second commit is not strictly speaking necessary. To keep the implementation clean, I've included it here, but if it causes too much noise, I can split it out without any trouble.
2024-04-01 14:35:38 +00:00
bors
3d5528c287 Auto merge of #123310 - compiler-errors:nested-static-codegen-attrs, r=oli-obk
Don't inherit codegen attrs from parent static

Putting this up partly for discussion and partly for review. Specifically, in #121644, `@oli-obk` designed a system that creates new static items for representing nested allocations in statics. However, in that PR, oli made it so that these statics inherited the codegen attrs from the parent.

This causes problems such as colliding symbols with `#[export_name]` and ICEs with `#[no_mangle]` since these synthetic statics have no `tcx.item_name(..)`.

So the question is, is there any case where we *do* want to inherit codegen attrs from the parent? The only one that seems a bit suspicious is the thread-local attribute. And there may be some interesting interactions with the coverage attributes as well...

Fixes (after backport) #123274. Fixes #123243. cc #121644.

r? `@oli-obk` cc `@nnethercote` `@RalfJung` (reviewers on that pr)
2024-04-01 09:22:01 +00:00
bors
defef8658e Auto merge of #122972 - beetrees:use-align-type, r=fee1-dead
Use the `Align` type when parsing alignment attributes

Use the `Align` type in `rustc_attr::parse_alignment`, removing the need to call `Align::from_bytes(...).unwrap()` later in the compilation process.
2024-04-01 03:16:45 +00:00
Michael Goulet
4ff8a9bd6b Don't inherit codegen attrs from parent static 2024-03-31 22:34:00 -04:00
beetrees
6e5f1dacf3
Use the Align type when parsing alignment attributes 2024-04-01 03:05:55 +01:00
Michael Goulet
56dbeeb5ac Add regression tests for 123303 2024-03-31 21:03:59 -04:00
Michael Goulet
b8396d10c4 Always make inductive cycles as ambig during typeck 2024-03-31 20:44:30 -04:00
Nadrieril
27704c7f9e Fix union handling in exhaustiveness 2024-04-01 00:01:46 +02:00
Nadrieril
db9b4eac48 Add tests 2024-03-31 23:57:47 +02:00
Caio
4c0aea0d47 Move some tests 2024-03-31 14:58:17 -03:00
joboet
41434ff4a3
refer to a different module in UI test 2024-03-31 15:38:22 +02:00
bors
5da1a1b59a Auto merge of #123085 - tgross35:f16-f128-step4.0-libs-basic-impls, r=Amanieu
Add basic trait impls for `f16` and `f128`

Split off part of <https://github.com/rust-lang/rust/pull/122470> so the compiler doesn't ICE because it expects primitives to have some minimal traits.

Fixes <https://github.com/rust-lang/rust/issues/123074>
2024-03-30 21:58:49 +00:00
bors
8df7e723ea Auto merge of #99322 - GKFX:const-int-parse, r=Mark-Simulacrum
Make {integer}::from_str_radix constant

This commit makes FromStr on integers constant so that `const x: u32 = "23".parse();` works. More practical use-case is with environment variables at build time as discussed in https://github.com/rust-lang/rfcs/issues/1907.

Tracking issue #59133.

ACP: https://github.com/rust-lang/libs-team/issues/74
2024-03-30 19:56:58 +00:00
Jules Bertholet
f37a4d55ee
Implement "&<pat> everywhere"
The original proposal allows reference patterns
with "compatible" mutability, however it's not clear
what that means so for now we require an exact match.

I don't know the type system code well, so if something
seems to not make sense it's probably because I made a
mistake
2024-03-30 12:57:54 -05:00
bors
70714e38f2 Auto merge of #123106 - maurer:cfi-closures, r=compiler-errors
CFI: Abstract Closures and Coroutines

This will abstract coroutines in a moment, it's just abstracting closures for now to show `@rcvalle`

This uses the same principal as the methods on traits - figure out the `dyn` type representing the fn trait, instantiate it, and attach that alias set. We're essentially just computing how we would be called in a dynamic context, and attaching that.
2024-03-30 17:56:26 +00:00
Matthew Maurer
8cc9a912d7 CFI: Rewrite closure and coroutine instances to their trait method
Similar to methods on a trait object, the most common way to indirectly
call a closure or coroutine is through the vtable on the appropriate
trait. This uses the same approach as we use for trait methods, after
backing out the trait arguments from the type.
2024-03-30 16:40:38 +00:00