Commit Graph

245239 Commits

Author SHA1 Message Date
Michael Goulet
427896dd7e Construct body for by-move coroutine closure output 2024-02-06 02:22:58 +00:00
Michael Goulet
fc4fff4038 Build a shim to call async closures with different AsyncFn trait kinds 2024-02-06 02:22:58 +00:00
Michael Goulet
a82bae2172 Teach typeck/borrowck/solvers how to deal with async closures 2024-02-06 02:22:58 +00:00
Michael Goulet
c567eddec2 Add CoroutineClosure to TyKind, AggregateKind, UpvarArgs 2024-02-06 02:22:58 +00:00
Michael Goulet
a20421734b Make async closures directly lower to ClosureKind::CoroutineClosure 2024-02-06 02:22:58 +00:00
Michael Goulet
b2bb51734c Make sure that async closures (and fns) only capture their parent callable's parameters by move, and nothing else 2024-02-06 02:22:57 +00:00
bors
f3b9d47a46 Auto merge of #120392 - compiler-errors:async-bound-modifier, r=davidtwco,fmease
Introduce support for `async` bound modifier on `Fn*` traits

Adds `async` to the list of `TraitBoundModifiers`, which instructs AST lowering to map the trait to an async flavor of the trait. For now, this is only supported for `Fn*` to `AsyncFn*`, and I expect that this manual mapping via lang items will be replaced with a better system in the future.

The motivation for adding these bounds is to separate the users of async closures from the exact trait desugaring of their callable bounds. Instead of users needing to be concerned with the `AsyncFn` trait, they should be able to write `async Fn()` and it will desugar to whatever underlying trait we decide is best for the lowering of async closures.

Note: rustfmt support can be done in the rustfmt repo after a subtree sync.
2024-02-06 00:45:11 +00:00
León Orell Valerian Liehr
d321437204
Remove b-naber from the compiler review rotation 2024-02-06 00:37:57 +01:00
bors
f067fd6084 Auto merge of #120313 - Nadrieril:graceful-error, r=compiler-errors
pattern_analysis: Gracefully abort on type incompatibility

This leaves the option for a consumer of the crate to return `Err` instead of panicking on type error. rust-analyzer could use that (e.g. https://github.com/rust-lang/rust-analyzer/issues/15808).

Since the only use of `TypeCx::bug` is in `Constructor::is_covered_by`, it is tempting to return `false` instead of `Err()`, but that would cause "non-exhaustive match" false positives.

r? `@compiler-errors`
2024-02-05 21:36:25 +00:00
Ralf Jung
0184ca695b revert stabilization of const_intrinsic_copy 2024-02-05 20:58:31 +01:00
Ralf Jung
e00df17abd merge the accepted-structural-match tests into one 2024-02-05 20:36:11 +01:00
Ralf Jung
45d01b8131 update the tracking issue for structural match violations
and bless a test I missed
2024-02-05 20:36:11 +01:00
Ralf Jung
48abca761a show indirect_structural_match and pointer_structural_match in future compat reports 2024-02-05 20:36:11 +01:00
Ralf Jung
9f58cf43c7 get rid of nontrivial_structural_match lint and custom_eq const qualif 2024-02-05 20:36:09 +01:00
bors
ea37e8091f Auto merge of #117372 - Amanieu:stdarch_update, r=Mark-Simulacrum
Update stdarch submodule

Splits up #27731 into multiple tracking issues.

Closes #27731
2024-02-05 15:41:40 +00:00
bors
86eaa892c0 Auto merge of #120671 - matthiaskrgr:rollup-spjnpno, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #113833 (`std::error::Error` -> Trait Implementations: lifetimes consistency improvement)
 - #115386 (PartialEq, PartialOrd: update and synchronize handling of transitive chains)
 - #116284 (make matching on NaN a hard error, and remove the rest of illegal_floating_point_literal_pattern)
 - #118960 (Add LocalWaker and ContextBuilder types to core, and LocalWake trait to alloc.)
 - #120384 (Use `<T, U>` for array/slice equality `impl`s)
 - #120518 (riscv only supports split_debuginfo=off for now)
 - #120657 (Remove unused struct)
 - #120661 (target: default to the medium code model on LoongArch targets)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-02-05 13:23:56 +00:00
klensy
f32aa1aef9 rustc_metadata: fix typo 2024-02-05 14:20:15 +03:00
Nicholas Nethercote
d9508a1fd2 Make Emitter::emit_diagnostic consuming.
All the other `emit`/`emit_diagnostic` methods were recently made
consuming (e.g. #119606), but this one wasn't. But it makes sense to.

Much of this is straightforward, and lots of `clone` calls are avoided.
There are a couple of tricky bits.
- `Emitter::primary_span_formatted` no longer takes a `Diagnostic` and
  returns a pair. Instead it takes the two fields from `Diagnostic` that
  it used (`span` and `suggestions`) as `&mut`, and modifies them. This
  is necessary to avoid the cloning of `diag.children` in two emitters.
- `from_errors_diagnostic` is rearranged so various uses of `diag` occur
  before the consuming `emit_diagnostic` call.
2024-02-05 21:27:01 +11:00
Matthias Krüger
dc0b1f961a
Rollup merge of #120661 - xen0n:loong-medium-cmodel, r=heiher,Nilstrieb
target: default to the medium code model on LoongArch targets

The Rust LoongArch targets have been using the default LLVM code model so far, which is "small" in LLVM-speak and "normal" in LoongArch-speak. As [described][1] in the "Code Model" section of LoongArch ELF psABI spec v20231219, one can only make function calls as far as ±128MiB with the "normal" code model; this is insufficient for very large software containing Rust components that needs to be linked into the big text section, such as Chromium.

Because:

* we do not want to ask users to recompile std if they are to build such software,
* objects compiled with larger code models can be linked with those with smaller code models without problems, and
* the "medium" code model is comparable to the "small"/"normal" one performance-wise (same data access pattern; each function call becomes 2-insn long and indirect, but this may be relaxed back into the direct 1-insn form in a future LLVM version), but is able to perform function calls within ±128GiB,

it is better to just switch the targets to the "medium" code model, which is also "medium" in LLVM-speak.

[1]: https://github.com/loongson/la-abi-specs/blob/v2.30/laelf.adoc#code-models
2024-02-05 11:07:28 +01:00
Matthias Krüger
13ea09b22f
Rollup merge of #120657 - mu001999:clean, r=Nilstrieb
Remove unused struct

Detected by #118257
2024-02-05 11:07:28 +01:00
Matthias Krüger
540936ca99
Rollup merge of #120518 - kxxt:riscv-split-debug-info, r=compiler-errors
riscv only supports split_debuginfo=off for now

Disable packed/unpacked options for riscv linux/android. Other riscv targets already only have the off option.

The packed/unpacked options might be supported in the future. See upstream issue for more details:
https://github.com/llvm/llvm-project/issues/56642

Fixes #110224
2024-02-05 11:07:27 +01:00
Matthias Krüger
2624bfbc0d
Rollup merge of #120384 - wackbyte:array-equality-generics, r=Mark-Simulacrum
Use `<T, U>` for array/slice equality `impl`s

Makes the trait implementation documentation for arrays and slices appear more consistent.

[Example](https://doc.rust-lang.org/1.75.0/std/primitive.array.html): mixed `A`, `B`, and `U`.
![List of PartialEq implementations for arrays](https://github.com/wackbyte/rust/assets/29505620/823c010e-ee57-4de1-885b-a1cd6dcaf85f)

This change makes them all `U`.
2024-02-05 11:07:27 +01:00
Matthias Krüger
80e8c7e125
Rollup merge of #118960 - tvallotton:local_waker, r=Mark-Simulacrum
Add LocalWaker and ContextBuilder types to core, and LocalWake trait to alloc.

Implementation for  #118959.
2024-02-05 11:07:26 +01:00
Matthias Krüger
ed27148812
Rollup merge of #116284 - RalfJung:no-nan-match, r=cjgillot
make matching on NaN a hard error, and remove the rest of illegal_floating_point_literal_pattern

These arms would never be hit anyway, so the pattern makes little sense. We have had a future-compat lint against float matches in general for a *long* time, so I hope we can get away with immediately making this a hard error.

This is part of implementing https://github.com/rust-lang/rfcs/pull/3535.

Closes https://github.com/rust-lang/rust/issues/41620 by removing the lint.

https://github.com/rust-lang/reference/pull/1456 updates the reference to match.
2024-02-05 11:07:26 +01:00
Matthias Krüger
fd8ea25882
Rollup merge of #115386 - RalfJung:partial-eq-chain, r=dtolnay
PartialEq, PartialOrd: update and synchronize handling of transitive chains

It was brought up in https://internals.rust-lang.org/t/total-equality-relations-as-std-eq-rhs/19232 that we currently have a gap in our `PartialEq` rules, which this PR aims to close:

> For example, with PartialEq's conditions you may have a = b = c = d ≠ a (where a and c are of type A, b and d are of type B).

The second commit fixes https://github.com/rust-lang/rust/issues/87067 by updating PartialOrd to handle the requirements the same way PartialEq does.
2024-02-05 11:07:25 +01:00
Matthias Krüger
13e84f2a3d
Rollup merge of #113833 - WiktorPrzetacznik:master, r=dtolnay
`std::error::Error` -> Trait Implementations: lifetimes consistency improvement

This cleans up `std::error::Error` trait implementations lifetime inconsistency (`'static` -> `'a`)

**Reasoning:**

Trait implementations for `std::error::Error`, like:
`impl From<&str> for Box<dyn Error + 'static, Global>`
`impl<'a> From<&str> for Box<dyn Error + Sync + Send + 'a, Global>`
use different lifetime annotations misleadingly implying using different life annotations here is a conscious, nonaccidental decision.

[(Related forum discussion here)](https://users.rust-lang.org/t/confusing-std-error-source-code/97011/5?u=wiktor)
2024-02-05 11:07:25 +01:00
lcnr
9cd6c68033 cleanup effect var handling 2024-02-05 10:51:18 +01:00
bors
8c0b4f67c9 Auto merge of #120660 - matthiaskrgr:rollup-zuqljul, r=matthiaskrgr
Rollup of 9 pull requests

Successful merges:

 - #119481 (Clarify ambiguity in select_nth_unstable docs)
 - #119600 (Remove outdated references to librustc_middle)
 - #120458 (Document `&CStr` to `CString` conversion)
 - #120569 (coverage: Improve handling of function/closure spans)
 - #120572 (Update libc to 0.2.153)
 - #120587 (miri: normalize struct tail in ABI compat check)
 - #120607 (fix #120603 by adding a check in default_read_buf)
 - #120636 (Subtree update of `rust-analyzer`)
 - #120641 (rustdoc: trait.impl, type.impl: sort impls to make it not depend on serialization order)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-02-05 06:24:06 +00:00
WANG Xuerui
35dad14dfb
target: default to the medium code model on LoongArch targets
The Rust LoongArch targets have been using the default LLVM code model
so far, which is "small" in LLVM-speak and "normal" in LoongArch-speak.
As described in the "Code Model" section of LoongArch ELF psABI spec
v20231219 [1], one can only make function calls as far as ±128MiB with
the "normal" code model; this is insufficient for very large software
containing Rust components that needs to be linked into the big text
section, such as Chromium.

Because:

* we do not want to ask users to recompile std if they are to build
  such software,
* objects compiled with larger code models can be linked with those
  with smaller code models without problems, and
* the "medium" code model is comparable to the "small"/"normal" one
  performance-wise (same data access pattern; each function call
  becomes 2-insn long and indirect, but this may be relaxed back into
  the direct 1-insn form in a future LLVM version), but is able to
  perform function calls within ±128GiB,

it is better to just switch the targets to the "medium" code model,
which is also "medium" in LLVM-speak.

[1]: https://github.com/loongson/la-abi-specs/blob/v2.30/laelf.adoc#code-models
2024-02-05 13:38:50 +08:00
Matthias Krüger
a2d3eed58d
Rollup merge of #120641 - klensy:copypaste-me, r=notriddle
rustdoc: trait.impl, type.impl: sort impls to make it not depend on serialization order

Can be tested by running `cargo doc` with different rust versions on some crate and comparing `doc` folders: files in `trait.impl` and `type.impl` will sometimes have different order of impls.
2024-02-05 06:37:17 +01:00
Matthias Krüger
bc98f5795b
Rollup merge of #120636 - lnicola:sync-from-ra, r=lnicola
Subtree update of `rust-analyzer`

r? ghost
2024-02-05 06:37:17 +01:00
Matthias Krüger
d8e9ddc843
Rollup merge of #120607 - conradludgate:fix-120603, r=dtolnay
fix #120603 by adding a check in default_read_buf

Fixes #120603 by checking the returned read n is in-bounds of the cursor.

Interestingly, I noticed that `BorrowedBuf` side-steps this issue by using checked accesses. Maybe this can be switched to unchecked to mirror what BufReader does bf3c6c5bed/library/core/src/io/borrowed_buf.rs (L95)
2024-02-05 06:37:16 +01:00
Matthias Krüger
e348f0739d
Rollup merge of #120587 - lukas-code:miri-tail-normalize, r=RalfJung
miri: normalize struct tail in ABI compat check

fixes https://github.com/rust-lang/miri/issues/3282
extracted from https://github.com/rust-lang/rust/pull/120354, see https://github.com/rust-lang/rust/pull/120354#discussion_r1469154220 for context

r? ```@RalfJung```
2024-02-05 06:37:16 +01:00
Matthias Krüger
16200db7aa
Rollup merge of #120572 - pheki:update-libc, r=Mark-Simulacrum
Update libc to 0.2.153

Bumps libc dependency to 0.2.153, which includes this fix, required for building std for the vita: https://github.com/rust-lang/libc/pull/3552
2024-02-05 06:37:15 +01:00
Matthias Krüger
7294c15f41
Rollup merge of #120569 - Zalathar:fn-sig, r=oli-obk
coverage: Improve handling of function/closure spans

This is a combination of some loosely-related changes that touch the same code:

1. Make unexpansion of closure bodies more precise, by unexpanding back to the context of the closure declaration, instead of unexpanding all the way back to the top-level context. This preserves the way we handle async desugaring and closures containing a single bang-macro, while also giving better results for closures defined in macros.
2. Skip the normal span-refinement code when dealing with the trivial outer part of an async function.
3. Be more explicit about the fact that `fn_sig_span` has been extended to the start of the function body, and is not necessarily present.

---

`@rustbot` label +A-code-coverage
2024-02-05 06:37:15 +01:00
Matthias Krüger
9838e943f3
Rollup merge of #120458 - rytheo:cstr-conversion-doc, r=Mark-Simulacrum
Document `&CStr` to `CString` conversion

Related to #51430
2024-02-05 06:37:14 +01:00
Matthias Krüger
ca36ed27be
Rollup merge of #119600 - aDotInTheVoid:comment-fix, r=compiler-errors
Remove outdated references to librustc_middle

The relevant comment is now in 791a53f380/compiler/rustc_middle/src/tests.rs (L3-L13)
2024-02-05 06:37:14 +01:00
Matthias Krüger
7158b3d3fb
Rollup merge of #119481 - romanows:fix-doc-select-nth-unstable, r=Mark-Simulacrum
Clarify ambiguity in select_nth_unstable docs

Original docs for `select_nth_unstable` family of functions were ambiguous as to whether "the element at `index`" was the element at `index` before the function reordered the elements or after the function reordered the elements.

The most helpful change in this PR is to change the given examples to make this absolutely clear.  Before, "the element at `index`" was the same value before and after the reordering, so it didn't help disambiguate the meaning.  I've changed the example for `select_nth_unstable` and `select_nth_unstable_by` so that "the element at `index`" is different before and after the reordering, which clears up the ambiguity.  The function `select_nth_unstable_by_key` already had an example that was unambiguous.

In an attempt to clear up the ambiguity from the get-go, I've added a bit of redundancy to the text.  Now the docs refer to "the element at `index` *after the reordering*".
2024-02-05 06:37:13 +01:00
bors
0984becf01 Auto merge of #120508 - weihanglo:update-cargo, r=weihanglo
Update cargo

24 commits in 7bb7b539558dc88bea44cee4168b6269bf8177b0..cdf84b69d0416c57ac9dc3459af80dfb4883d27a
2024-01-20 00:15:32 +0000 to 2024-02-02 19:39:16 +0000
- Apply `-Zpanic-abort-tests` to doctests too (rust-lang/cargo#13388)
- Don't print rustdoc command lines on failure by default (rust-lang/cargo#13387)
- Ensure `nonzero_exit_code` test isn't affected by developers `RUST_BACKTRACE` setting (rust-lang/cargo#13385)
- Add `docsrs` cfg as a well known `--check-cfg` (rust-lang/cargo#13383)
- fix(new): Print a note, rather than a comment, for more information (rust-lang/cargo#13371)
- Change tests to support changes to suggestion (rust-lang/cargo#13382)
- chore(ci): enable m1 runner (rust-lang/cargo#13377)
- fix(toml): Improve map/sequence error message (rust-lang/cargo#13376)
- fix(diagnostic): Don't panic on empty spans (rust-lang/cargo#13375)
- doc: Hide `cargo-fetch` description in offline man page (rust-lang/cargo#13364)
- feat: stabilize lockfile v4 (rust-lang/cargo#12852)
- fix(new): Print a 'Creating', rather than 'Created' status (rust-lang/cargo#13367)
- fix: use spec id instead of name to match package (rust-lang/cargo#13335)
- refactor(shell): Use new fancy anstyle API (rust-lang/cargo#13368)
- feat(cargo-update): `--precise` to allow yanked versions (rust-lang/cargo#13333)
- refactor: remove unnecessary Option in `Freshness::Dirty` (rust-lang/cargo#13361)
- doc: Replace version with `latest` for jobserver link (rust-lang/cargo#13366)
- test: data layout fix for `x86_64-unknown-none-gnu` (rust-lang/cargo#13362)
- docs(ref): Try to improve reg auth docs (rust-lang/cargo#13351)
- fix typo of rustbuild, instead of rustuild (rust-lang/cargo#13357)
- fix(config): Deprecate non-extension files (rust-lang/cargo#13349)
- fix(cli): Improve errors related to cargo script (rust-lang/cargo#13346)
- fix list option description starting with uppercase (rust-lang/cargo#13344)
- Fix typo in test (rust-lang/cargo#13342)
2024-02-05 04:22:21 +00:00
bors
991a9dc3f7 Auto merge of #120497 - compiler-errors:modulize, r=lcnr
Move predicate, region, and const stuff into their own modules in middle

This PR mostly moves things around, and in a few cases adds some `ty::` to the beginning of names to avoid one-off imports.

I don't mean this to be the most *thorough* move/refactor. I just generally wanted to begin to split up `ty/mod.rs` and `ty/sty.rs` which are huge and hard to distinguish, and have a lot of non-ty stuff in them.

r? lcnr
2024-02-05 02:21:32 +00:00
r0cky
8266657338 Remove unused struct 2024-02-05 10:04:36 +08:00
Zalathar
a246b6be1d coverage: Make fn_sig_span optional, and note its quirks 2024-02-05 10:09:50 +11:00
Zalathar
fde1702db8 coverage: Hoist special handling of async function spans
This sidesteps the normal span refinement code in cases where we know that we
are only dealing with the special signature span that represents having called
an async function.
2024-02-05 10:09:50 +11:00
Zalathar
dd6d7f27e4 coverage: Make unexpansion of closure bodies more precise
This improves the coverage instrumentation of closures declared in macros, as
seen in `closure_macro.rs` and `closure_macro_async.rs`.
2024-02-05 10:09:46 +11:00
Zalathar
8dd2b37462 coverage: Add a test for #[coverage(..)] on closures 2024-02-05 10:07:19 +11:00
Zalathar
fe420dc46e coverage: Test for closure body that is a single bang-macro 2024-02-05 10:07:18 +11:00
Nicholas Nethercote
59e0bc2de7 Split Level::DelayedBug in two.
The two kinds of delayed bug have quite different semantics so a
stronger conceptual separation is nice. (`is_error` is a good example,
because the two kinds have different behaviour.)

The commit also moves the `DelayedBug` variant after `Error` in `Level`,
to reflect the fact that it's weaker than `Error` -- it might trigger an
error but also might not. (The pre-existing `downgrade_to_delayed_bug`
function also reflects the notion that delayed bugs are lower/after
normal errors.)

Plus it condenses some of the comments on `Level` into a table, for
easier reading, and introduces `can_be_top_or_sub` to indicate which
levels can be used in top-level diagnostics vs. subdiagnostics.

Finally, it renames `DiagCtxtInner::span_delayed_bugs` as
`DiagCtxtInner::delayed_bugs`. The `span_` prefix is unnecessary because
some delayed bugs don't have a span.
2024-02-05 10:03:01 +11:00
Nicholas Nethercote
c367386832 Refactor emit_diagnostic.
- Combine two different blocks involving
  `diagnostic.level.get_expectation_id()` into one.
- Combine several `if`s involving `diagnostic.level` into a single
  `match`.

This requires reordering some of the operations, but this has no
functional effect.
2024-02-05 10:02:26 +11:00
bors
4d87c4ad62 Auto merge of #120649 - matthiaskrgr:rollup-ek80j61, r=matthiaskrgr
Rollup of 8 pull requests

Successful merges:

 - #119759 (Add FileCheck annotations to dataflow-const-prop tests)
 - #120323 (On E0277 be clearer about implicit `Sized` bounds on type params and assoc types)
 - #120473 (Only suggest removal of `as_*` and `to_` conversion methods on E0308)
 - #120540 (add test for try-block-in-match-arm)
 - #120547 (`#![feature(inline_const_pat)]` is no longer incomplete)
 - #120552 (Correctly check `never_type` feature gating)
 - #120555 (put pnkfelix (me) back on the review queue.)
 - #120556 (Improve the diagnostics for unused generic parameters)

r? `@ghost`
`@rustbot` modify labels: rollup
2024-02-04 22:55:40 +00:00
Nicholas Nethercote
5dd0431386 Tighten the assertion in downgrade_to_delayed_bug.
I.e. `Bug` and `Fatal` level diagnostics are never downgraded.
2024-02-05 08:16:30 +11:00