Commit Graph

241868 Commits

Author SHA1 Message Date
bors
208dd2032b Auto merge of #118847 - eholk:for-await, r=compiler-errors
Add support for `for await` loops

This adds support for `for await` loops. This includes parsing, desugaring in AST->HIR lowering, and adding some support functions to the library.

Given a loop like:
```rust
for await i in iter {
    ...
}
```
this is desugared to something like:
```rust
let mut iter = iter.into_async_iter();
while let Some(i) = loop {
    match core::pin::Pin::new(&mut iter).poll_next(cx) {
        Poll::Ready(i) => break i,
        Poll::Pending => yield,
    }
} {
    ...
}
```

This PR also adds a basic `IntoAsyncIterator` trait. This is partly for symmetry with the way `Iterator` and `IntoIterator` work. The other reason is that for async iterators it's helpful to have a place apart from the data structure being iterated over to store state. `IntoAsyncIterator` gives us a good place to do this.

I've gated this feature behind `async_for_loop` and opened #118898 as the feature tracking issue.

r? `@compiler-errors`
2023-12-22 14:17:10 +00:00
León Orell Valerian Liehr
b09889b959
Rid the AST & HIR pretty printers of syntactic cruft 2023-12-22 14:32:40 +01:00
bors
c1fc1d18cd Auto merge of #116821 - Nadrieril:fix-opaque-ice, r=compiler-errors
Exhaustiveness: reveal opaque types properly

Previously, exhaustiveness had no clear policy around opaque types. In this PR I propose the following policy: within the body of an item that defines the hidden type of some opaque type, exhaustiveness checking on a value of that opaque type is performed using the concrete hidden type inferred in this body.

I'm not sure how consistent this is with other operations allowed on opaque types; I believe this will require FCP.

From what I can tell, this doesn't change anything for non-empty types.

The observable changes are:
- when the real type is uninhabited, matches within the defining scopes can now rely on that for exhaustiveness, e.g.:

```rust
#[derive(Copy, Clone)]
enum Void {}
fn return_never_rpit(x: Void) -> impl Copy {
    if false {
        match return_never_rpit(x) {}
    }
    x
}
```
- this properly fixes ICEs like https://github.com/rust-lang/rust/issues/117100 that occurred because a same match could have some patterns where the type is revealed and some where it is not.

Bonus subtle point: if `x` is opaque, a match like `match x { ("", "") => {} ... }` will constrain its type ([playground](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=901d715330eac40339b4016ac566d6c3)). This is not the case for `match x {}`: this will not constain the type, and will only compile if something else constrains the type to be empty.

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

r? `@oli-obk`

Edited for precision of the wording

[Included](https://github.com/rust-lang/rust/pull/116821#issuecomment-1813171764) in the FCP on this PR is this rule:

> Within the body of an item that defines the hidden type of some opaque type, exhaustiveness checking on a value of that opaque type is performed using the concrete hidden type inferred in this body.
2023-12-22 12:12:12 +00:00
Pietro Albini
f9f5840eb4
update cfg(bootstrap)s 2023-12-22 11:14:11 +01:00
Pietro Albini
bcdaa0d194
bump stage0 2023-12-22 11:04:31 +01:00
Pietro Albini
c00486c9bb
update version placeholders 2023-12-22 11:01:42 +01:00
bors
ef1b78eabe Auto merge of #119173 - compiler-errors:direct-coro-kind, r=TaKO8Ki
Encode `CoroutineKind` directly

Probably a quick optimization?

r? `@ghost`
2023-12-22 04:07:40 +00:00
bors
aaef5fe497 Auto merge of #119163 - fmease:refactor-ast-trait-bound-modifiers, r=compiler-errors
Refactor AST trait bound modifiers

Instead of having two types to represent trait bound modifiers in the parser / the AST (`parser::ty::BoundModifiers` & `ast::TraitBoundModifier`), only to map one to the other later, just use `parser::ty::BoundModifiers` (moved & renamed to `ast::TraitBoundModifiers`).

The struct type is more extensible and easier to deal with (see [here](https://github.com/rust-lang/rust/pull/119099/files#r1430749981) and [here](https://github.com/rust-lang/rust/pull/119099/files#r1430752116) for context) since it more closely models what it represents: A compound of two kinds of modifiers, constness and polarity. Modeling this as an enum (the now removed `ast::TraitBoundModifier`) meant one had to add a new variant per *combination* of modifier kind, which simply isn't scalable and which lead to a lot of explicit non-DRY matches.

NB: `hir::TraitBoundModifier` being an enum is fine since HIR doesn't need to worry representing invalid modifier kind combinations as those get rejected during AST validation thereby immensely cutting down the number of possibilities.
2023-12-22 02:00:55 +00:00
bors
cee794ee98 Auto merge of #119097 - nnethercote:fix-EmissionGuarantee, r=compiler-errors
Fix `EmissionGuarantee`

There are some problems with the `DiagCtxt` API related to `EmissionGuarantee`. This PR fixes them.

r? `@compiler-errors`
2023-12-22 00:03:57 +00:00
Augie Fackler
58fdbd1479 tests: fix overaligned-constant to not over-specify getelementptr instr
On LLVM 18 we get slightly different arguments here, so it's easier to
just regex those away. The important details are all still asserted as I
understand things.

Fixes #119193.

@rustbot label: +llvm-main
2023-12-21 15:53:28 -05:00
bors
3d0e6bed60 Auto merge of #119190 - matthiaskrgr:rollup-jvl8vkj, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #118729 (Add release notes for 1.75.0)
 - #119124 (don't build `rust-analyzer-proc-macro-srv` on def config )
 - #119154 (Simple modification of `non_lifetime_binders`'s diagnostic information to adapt to type binders)
 - #119176 (Fix name error in aarch64_apple_watchos tier 3 target)
 - #119182 (Update sysinfo version to 0.30.0)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-12-21 20:50:46 +00:00
Brian Cain
cc34942f12 Add support for hexagon-unknown-none-elf as target
Signed-off-by: Brian Cain <bcain@quicinc.com>
2023-12-21 09:34:29 -08:00
Pietro Albini
12b06ad51b
run fuchsia tests only on nightly 2023-12-21 18:27:24 +01:00
Matthias Krüger
6516e595c0
Rollup merge of #119182 - GuillaumeGomez:update-sysinfo, r=onur-ozkan
Update sysinfo version to 0.30.0

Following last `sysinfo` update. Nothing much needs to be changed here apparently.

r? `@onur-ozkan`
2023-12-21 16:43:08 +01:00
Matthias Krüger
81e5ca4d97
Rollup merge of #119176 - leohowell:fix-apple-watchos-target-name-error, r=lqd
Fix name error in aarch64_apple_watchos tier 3 target

fix llvm_target wrong name `aarch-apple-watchos` to `aarch64-apple-watchos`, sorry for my mistake.

previous pr: https://github.com/rust-lang/rust/pull/119074

r? compiler-team
2023-12-21 16:43:08 +01:00
Matthias Krüger
2b48e7dbcb
Rollup merge of #119154 - surechen:fix_119067, r=fmease
Simple modification of `non_lifetime_binders`'s diagnostic information to adapt to type binders

fixes #119067

Replace diagnostic information "lifetime bounds cannot be used in this context" to "bounds cannot be used in this context".

```rust
#![allow(incomplete_features)]
#![feature(non_lifetime_binders)]

trait Trait {}

trait Trait2
    where for <T: Trait> ():{}
//~^ ERROR bounds cannot be used in this context
```
2023-12-21 16:43:07 +01:00
Matthias Krüger
c644d00285
Rollup merge of #119124 - onur-ozkan:help-118861, r=Mark-Simulacrum
don't build `rust-analyzer-proc-macro-srv` on def config

Should be very easy to understand when reviewing commit-by-commit.

Blocker for #118861
2023-12-21 16:43:07 +01:00
Matthias Krüger
1871f2b4a0
Rollup merge of #118729 - cuviper:relnotes-1.75.0, r=pietroalbini
Add release notes for 1.75.0

cc `@rust-lang/release`
r? `@Mark-Simulacrum`
2023-12-21 16:43:06 +01:00
onur-ozkan
1f141dc0b8 add a new change in change-tracker
Signed-off-by: onur-ozkan <work@onurozkan.dev>
2023-12-21 16:08:14 +03:00
Pietro Albini
73cd2df422
apply last suggestions from code review 2023-12-21 13:26:15 +01:00
Guillaume Gomez
c3ede70d35 Update sysinfo version to 0.30.0 2023-12-21 12:17:49 +01:00
bors
767453eb7c Auto merge of #119181 - pietroalbini:pa-1.77, r=pietroalbini
Bump version number to 1.77.0
2023-12-21 10:02:26 +00:00
Pietro Albini
a55698a1ac
bump version number to 1.77.0 2023-12-21 10:58:56 +01:00
Leo Howell
d9842a2060
Fix name error in aarch64_apple_watchos tier 3 target 2023-12-21 13:53:11 +08:00
bors
920e0051cf Auto merge of #119056 - cjgillot:codegen-overalign, r=wesleywiser
Tolerate overaligned MIR constants for codegen.

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

cc `@saethlin`
2023-12-21 04:01:36 +00:00
surechen
4897d5eccf Simple modification of diagnostic information
fixes #119067
2023-12-21 10:17:11 +08:00
Michael Goulet
828272ad37 Encode CoroutineKind directly 2023-12-21 01:43:31 +00:00
bors
3694a6b20a Auto merge of #119170 - matthiaskrgr:rollup-nllgdf2, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #119135 (Fix crash due to `CrateItem::kind()` not handling constructors)
 - #119141 (Add method to get instance instantiation arguments)
 - #119145 (Give `VariantData::Struct`  named fields, to clairfy `recovered`.)
 - #119167 (E0761: module directory has .rs suffix)
 - #119168 (resolve: Stop feeding visibilities for import list stems)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-12-21 01:43:07 +00:00
Tomasz Miąsko
ba430a36c0 Enable -Zlint-mir by default for mir-opt tests 2023-12-21 00:00:00 +00:00
Tomasz Miąsko
532080cfcc Stricter check for a use of locals without storage 2023-12-21 12:58:39 +01:00
Tomasz Miąsko
b4877753c3 Don't require owned data in MaybeStorageDead 2023-12-21 12:58:39 +01:00
Tomasz Miąsko
1d36e3ae03 Lint missing StorageDead when returning from functions 2023-12-21 12:58:39 +01:00
Tomasz Miąsko
7a246ddd8e Add pass to identify undefined or erroneous behaviour 2023-12-21 12:58:39 +01:00
Matthias Krüger
c36bb5dbb1
Rollup merge of #119168 - petrochenkov:feedvis4, r=compiler-errors
resolve: Stop feeding visibilities for import list stems

Fixes https://github.com/rust-lang/rust/issues/119126
2023-12-20 21:19:00 +01:00
Matthias Krüger
906606d5a3
Rollup merge of #119167 - alef:patch-1, r=compiler-errors
E0761: module directory has .rs suffix

`rustc --explain E0761` example seems wrong.
2023-12-20 21:19:00 +01:00
Matthias Krüger
d0d814ff48
Rollup merge of #119145 - aDotInTheVoid:variantdata-struct-struct, r=compiler-errors
Give `VariantData::Struct`  named fields, to clairfy `recovered`.

Implements https://github.com/rust-lang/rust/pull/119121#discussion_r1431467066. Supersedes #119121

This way, it's clear what the bool fields means, instead of having to find where it's generated. Changes both ast and hir.

r? `@compiler-errors`
2023-12-20 21:18:59 +01:00
Matthias Krüger
f6a04f693b
Rollup merge of #119141 - celinval:smir-instance-args, r=compiler-errors
Add method to get instance instantiation arguments

Add a method to get the instance instantiation arguments, and include that information in the instance debug.
2023-12-20 21:18:59 +01:00
Matthias Krüger
b55887dc7a
Rollup merge of #119135 - celinval:smir-small-changes, r=compiler-errors
Fix crash due to `CrateItem::kind()` not handling constructors

Also add a method to get the instance instantiation arguments, and include that information in the instance debug.
2023-12-20 21:18:58 +01:00
Celina G. Val
e0a4693294 Add method to get instance instantiation arguments 2023-12-20 11:07:06 -08:00
Celina G. Val
7ab38b80eb Add ItemKind::Ctor to stable mir 2023-12-20 10:53:40 -08:00
Celina G. Val
48c7cc2090 Add a small test for the case that was crashing 2023-12-20 10:50:40 -08:00
Celina G. Val
a8556da672 Fix crash for CrateItem::kind() with constructors
Change how we classify item kind for DefKind::Ctor
2023-12-20 10:50:40 -08:00
León Orell Valerian Liehr
5e4f12b41a
Refactor AST trait bound modifiers 2023-12-20 19:39:46 +01:00
bors
5ac4c8a63e Auto merge of #119037 - RalfJung:repr-c-abi-mismatch, r=scottmcm
do not allow ABI mismatches inside repr(C) types

In https://github.com/rust-lang/rust/pull/115476 we allowed ABI mismatches inside `repr(C)` types. This wasn't really discussed much; I added it because from how I understand calling conventions, this should actually be safe in practice. However I entirely forgot to actually allow this in Miri, and in the mean time I have learned that too much ABI compatibility can be a problem for CFI (it can reject fewer calls so that gives an attacker more room to play with).

So I propose we take back that part about ABI compatibility in `repr(C)`. It is anyway something that C and C++ do not allow, as far as I understand.

In the future we might want to introduce a class of ABI compatibilities where we say "this is a bug and it may lead to aborting the process, but it won't lead to arbitrary misbehavior -- worst case it'll just transmute the arguments from the caller type to the callee type". That would give CFI leeway to reject such calls without introducing the risk of arbitrary UB. (The UB can still happen if the transmute leads to bad results, of course, but it wouldn't be due to ABI weirdness.)

#115476 hasn't reached beta yet so if we land this before Dec 22nd we can just pretend this all never happened. ;)  Otherwise we should do a beta backport (of the docs change at least).

Cc `@rust-lang/opsem` `@rust-lang/types`
2023-12-20 18:04:40 +00:00
Vadim Petrochenkov
006e0ef18d resolve: Stop feeding visibilities for import list stems 2023-12-20 20:27:10 +03:00
alef
821fddeba5
E0761: module directory has .rs suffix 2023-12-20 17:05:56 +01:00
bors
92ad4b433a Auto merge of #119166 - GuillaumeGomez:rollup-qfgj76w, r=GuillaumeGomez
Rollup of 3 pull requests

Successful merges:

 - #119115 (Update documentation for `--env` compilation flag)
 - #119155 (coverage: Check for `async fn` explicitly, without needing a heuristic)
 - #119159 (Update LLVM submodule)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-12-20 16:01:46 +00:00
Guillaume Gomez
c76841928d
Rollup merge of #119159 - petrochenkov:llvmup, r=nikic
Update LLVM submodule

to pick up "[M68k] Fix ODR violation in GISel code (#72797)" https://github.com/rust-lang/llvm-project/pull/159.

Fixes https://github.com/rust-lang/rust/issues/107668
2023-12-20 16:29:55 +01:00
Guillaume Gomez
5906d8f0cf
Rollup merge of #119155 - Zalathar:async-fn, r=compiler-errors
coverage: Check for `async fn` explicitly, without needing a heuristic

The old code used a heuristic to detect async functions and adjust their coverage spans to produce better output. But there's no need to resort to a heuristic when we can just look back at the original definition and check whether the current function is actually an `async fn`.

In addition to being generally nicer, this also gets rid of the one piece of code that specifically cares about `CoverageSpan::is_closure` representing an actual closure. All remaining code that inspects that field just uses it as an indication that the span is a hole that should be carved out of other spans, and then discarded.

That opens up the possibility of introducing other kinds of “hole” spans, e.g. for nested functions/types/macros, and having them all behave uniformly.

---

`@rustbot` label +A-code-coverage
2023-12-20 16:29:55 +01:00
Guillaume Gomez
0bbcdb2aa3
Rollup merge of #119115 - GuillaumeGomez:env-docs, r=Nilstrieb
Update documentation for `--env` compilation flag

Part of https://github.com/rust-lang/rust/issues/80792.
As mentioned in https://github.com/rust-lang/rust/pull/118830.

It adds a mention to `tracked_env::var` and also clarifies what triggers a new compilation.

r? `@Nilstrieb`
2023-12-20 16:29:54 +01:00