Commit Graph

1112 Commits

Author SHA1 Message Date
León Orell Valerian Liehr
3acc5a0da3
effects: support ~const in assoc fns in trait impls 2024-01-07 18:22:47 +01:00
Matthias Krüger
f4335a419f
Rollup merge of #119540 - fmease:no-effect-args-inside-dyn-trait, r=compiler-errors
Don't synthesize host effect args inside trait object types

While we were indeed emitting an error for `~const` & `const` trait bounds in trait object types, we were still synthesizing host effect args for them.

Since we don't record the original trait bound modifiers for dyn-Trait in `hir::TyKind::TraitObject` (unlike we do for let's say impl-Trait, `hir::TyKind::OpaqueTy`), AstConv just assumes `ty::BoundConstness::NotConst` in `conv_object_ty_poly_trait_ref` which given `<host> dyn ~const NonConstTrait` resulted in us not realizing that `~const` was used on a non-const trait which lead to a failed assertion in the end.

Instead of updating `hir::TyKind::TraitObject` to track this kind of information, just strip the user-provided constness (similar to #119505).

Fixes #119524.
2024-01-04 08:33:26 +01:00
León Orell Valerian Liehr
8bce6fc35e
Rollup merge of #119505 - fmease:no-host-param-for-trait-fns, r=fee1-dead
Don't synthesize host effect params for trait associated functions marked const

Fixes #113378.

r? fee1-dead or compiler
2024-01-03 16:08:30 +01:00
León Orell Valerian Liehr
b5618bc222
Rollup merge of #119494 - fmease:deny-hr-param-defaults, r=compiler-errors
Deny defaults for higher-ranked generic parameters

Fixes #119489 (incl. https://github.com/rust-lang/rust/issues/119489#issuecomment-1873399208).
Partially reverts #119042.

cc ```@bvanjoi```
r? ```@compiler-errors``` or compiler
2024-01-03 16:08:29 +01:00
León Orell Valerian Liehr
695a02e0d8
Don't synthesize host effect args inside trait object types 2024-01-03 09:25:27 +01:00
León Orell Valerian Liehr
ba860344e1
Don't synthesize host effect params for trait assoc fns marked const 2024-01-02 13:49:47 +01:00
León Orell Valerian Liehr
3d0297a1e1
Deny defaults for higher-ranked generic parameters 2024-01-01 21:58:25 +01:00
bors
d868bc2842 Auto merge of #119284 - Nadrieril:fix-bodiless-arm-parse, r=cjgillot
Don't drop a hir node after lowering

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

It seems that all hir nodes that get allocated an id must be placed within the hir on pain of ICEs. In https://github.com/rust-lang/rust/pull/118527 I dropped guards on never patterns since they're not useful, which caused the ICE.
2023-12-30 22:44:33 +00:00
Arpad Borsos
2480a0f3f6
Merge Coroutine lowering functions
Instead of having separate `make_async/etc_expr` functions, this merges them them into one, reducing code duplication a bit.
2023-12-28 21:24:24 +01:00
bors
88d69b72b4 Auto merge of #119099 - fmease:always-const-trait-bounds, r=fee1-dead
Introduce `const Trait` (always-const trait bounds)

Feature `const_trait_impl` currently lacks a way to express “always const” trait bounds. This makes it impossible to define generic items like fns or structs which contain types that depend on const method calls (\*). While the final design and esp. the syntax of effects / keyword generics isn't set in stone, some version of “always const” trait bounds will very likely form a part of it. Further, their implementation is trivial thanks to the `effects` backbone.

Not sure if this needs t-lang sign-off though.

(\*):

```rs
#![feature(const_trait_impl, effects, generic_const_exprs)]

fn compute<T: const Trait>() -> Type<{ T::generate() }> { /*…*/ }

struct Store<T: const Trait>
where
    Type<{ T::generate() }>:,
{
    field: Type<{ T::generate() }>,
}
```

Lastly, “always const” trait bounds are a perfect fit for `generic_const_items`.

```rs
#![feature(const_trait_impl, effects, generic_const_items)]

const DEFAULT<T: const Default>: T = T::default();
```

Previously, we (oli, fee1-dead and I) wanted to reinterpret `~const Trait` as `const Trait` in generic const items which would've been quite surprising and not very generalizable.
Supersedes #117530.

---

cc `@oli-obk`

As discussed
r? fee1-dead (or compiler)
2023-12-27 19:24:31 +00:00
León Orell Valerian Liehr
3eb48a35c8
Introduce const Trait (always-const trait bounds) 2023-12-27 12:51:32 +01:00
bors
deace71034 Auto merge of #119324 - compiler-errors:rollup-c6eqcg9, r=compiler-errors
Rollup of 5 pull requests

Successful merges:

 - #119235 (Add missing feature gate for sanitizer CFI cfgs)
 - #119240 (Make some non-diagnostic-affecting `QPath::LangItem` into regular `QPath`s)
 - #119297 (Pass DeadItem and lint as consistent group in dead-code.)
 - #119307 (Clean up some lifetimes in `rustc_pattern_analysis`)
 - #119323 (add test for coercing never to infinite type)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-12-26 19:28:49 +00:00
Michael Goulet
e7bd402a38
Rollup merge of #119240 - compiler-errors:lang-item-more, r=petrochenkov
Make some non-diagnostic-affecting `QPath::LangItem` into regular `QPath`s

The rest of 'em affect diagnostics, so leave them alone... for now.

cc #115178
2023-12-26 13:29:13 -05:00
Nadrieril
d5b2d88a1a Don't drop a hir node after lowering 2023-12-26 09:45:54 +01:00
bohan
e16efbd23a fallback default to None during ast-loweing for lifetime binder 2023-12-26 16:10:29 +08:00
bors
1ab783112a Auto merge of #119258 - compiler-errors:closure-kind, r=eholk
Make closures carry their own ClosureKind

Right now, we use the "`movability`" field of `hir::Closure` to distinguish a closure and a coroutine. This is paired together with the `CoroutineKind`, which is located not in the `hir::Closure`, but the `hir::Body`. This is strange and redundant.

This PR introduces `ClosureKind` with two variants -- `Closure` and `Coroutine`, which is put into `hir::Closure`. The `CoroutineKind` is thus removed from `hir::Body`, and `Option<Movability>` no longer needs to be a stand-in for "is this a closure or a coroutine".

r? eholk
2023-12-26 04:25:53 +00:00
Michael Goulet
7e00e9736d Make some non-diagnostic-affecting QPath::LangItem into regular qpaths 2023-12-26 04:07:38 +00:00
Michael Goulet
3320c09eab Only regular coroutines have movability 2023-12-25 21:13:41 +00:00
Michael Goulet
909dd864f1 Make closures carry their own ClosureKind, rather than deducing what it is from movability 2023-12-25 16:29:15 +00:00
Nicholas Nethercote
99472c7049 Remove Session methods that duplicate DiagCtxt methods.
Also add some `dcx` methods to types that wrap `TyCtxt`, for easier
access.
2023-12-24 08:05:28 +11:00
Matthias Krüger
bdc4480914
Rollup merge of #119231 - aDotInTheVoid:PatKind-struct-bool-docs, r=compiler-errors
Clairify `ast::PatKind::Struct` presese of `..` by using an enum instead of a bool

The bool is mainly used for when a `..` is present, but it is also set on recovery to avoid errors. The doc comment not describes both of these cases.

See cee794ee98/compiler/rustc_parse/src/parser/pat.rs (L890-L897) for the only place this is constructed.

r? ``@compiler-errors``
2023-12-23 16:23:54 +01:00
Alona Enraght-Moony
1349d86c72 bool->enum for ast::PatKind::Struct presence of ..
See cee794ee98/compiler/rustc_parse/src/parser/pat.rs (L890-L897) for the only place this is constructed.
2023-12-23 02:50:31 +00:00
Michael Goulet
eef023c806
Rollup merge of #119222 - eholk:into-async-iterator, r=compiler-errors,dtolnay
Add `IntoAsyncIterator`

This introduces the `IntoAsyncIterator` trait and uses it in the desugaring of the unstable `for await` loop syntax. This is mostly added for symmetry with `Iterator` and `IntoIterator`.

r? `@compiler-errors`

cc `@rust-lang/libs-api,` `@rust-lang/wg-async`
2023-12-22 21:41:04 -05:00
Michael Goulet
004450506e Split coroutine desugaring kind from source 2023-12-22 23:58:29 +00:00
Eric Holk
acb6f17adf
Use IntoAsyncIterator in for await loop desugaring 2023-12-22 11:01:06 -08:00
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
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
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
León Orell Valerian Liehr
5e4f12b41a
Refactor AST trait bound modifiers 2023-12-20 19:39:46 +01:00
Vadim Petrochenkov
5e5d82e803 resolve: Eagerly feed closure visibilities
Also factor out all tcx-dependent operations performed for every created definition into `TyCtxt::create_def`
2023-12-20 13:42:58 +03:00
Alona Enraght-Moony
11337805fb Give VariantData::Struct named fields, to clairfy recovered. 2023-12-20 00:07:34 +00:00
Eric Holk
97df0d3657
Desugar for await loops 2023-12-19 12:26:27 -08:00
Eric Holk
27d6539a46
Plumb awaitness of for loops 2023-12-19 12:26:20 -08:00
bors
32f5db9890 Auto merge of #119093 - michaelwoerister:mcp533-18, r=petrochenkov
Replace some instances of FxHashMap/FxHashSet with stable alternatives (mostly in rustc_hir and rustc_ast_lowering)

Part of https://github.com/rust-lang/compiler-team/issues/533. We should be getting close to being able to remove the HashStable impl of HashMap.
2023-12-19 08:46:02 +00:00
bors
59096cdad0 Auto merge of #119061 - compiler-errors:async-gen-abi, r=wesleywiser
Desugar `yield` in `async gen` correctly, ensure `gen` always returns unit

1. Ensure `async gen` blocks desugar `yield $expr` to `task_context = yield async_gen_ready($expr)`. Previously we were not assigning the `task_context` correctly, meaning that `yield` expressions in async generators returned type `ResumeTy` instead of `()`, and that we were not storing the `task_context`  (which is probably unsound if we were reading the old task-context which has an invalidated borrow or something...)
2. Ensure that all `(async?) gen` blocks and `(async?) gen` fns return unit. Previously we were only checking this for `gen fn`, meaning that `gen {}` and `async gen {}` and `async gen fn` were allowed to return values that weren't unit. This is why #119058 was an ICE rather than an E0308.

Fixes #119058.
2023-12-19 00:42:50 +00:00
Michael Woerister
115885ba7e Replace some instances of FxHashMap/FxHashSet with stable alternatives (mostly in rustc_hir and rustc_ast_lowering)
Part of https://github.com/rust-lang/compiler-team/issues/533
2023-12-18 21:03:32 +01:00
bors
e004adb556 Auto merge of #119069 - matthiaskrgr:rollup-xxk4m30, r=matthiaskrgr
Rollup of 5 pull requests

Successful merges:

 - #118852 (coverage: Skip instrumenting a function if no spans were extracted from MIR)
 - #118905 ([AIX] Fix XCOFF metadata)
 - #118967 (Add better ICE messages for some undescriptive panics)
 - #119051 (Replace `FileAllocationInfo` with `FileEndOfFileInfo`)
 - #119059 (Deny `~const` trait bounds in inherent impl headers)

r? `@ghost`
`@rustbot` modify labels: rollup
2023-12-18 08:03:22 +00:00
Matthias Krüger
578a7dd35e
Rollup merge of #118967 - RossSmyth:panic-messages, r=TaKO8Ki
Add better ICE messages for some undescriptive panics

Add some better messages at some panics

re: #118955

I took a look at some others but either was not able to figure out what they did, or it was unclear what they should say instead. For example in the query system whether each time a poisoned value is matched upon if they should all just call `FatalError.raise()`
2023-12-18 08:08:23 +01:00
Nicholas Nethercote
09af8a667c Rename Session::span_diagnostic as Session::dcx. 2023-12-18 16:06:21 +11:00
Michael Goulet
454bff7682 Ensure yield expressions desugar correctly in async generators 2023-12-18 01:42:19 +00:00
Vadim Petrochenkov
be321aa473 resolve: Replace visibility table in resolver outputs with query feeding
Also feed missing visibilities for import stems and trait impl items, which were previously evaluated lazily.
2023-12-18 02:26:55 +03:00
Jubilee
c5a3d98cc6
Rollup merge of #119004 - matthiaskrgr:conv, r=compiler-errors
NFC don't convert types to identical types
2023-12-15 21:33:00 -08:00
Matthias Krüger
8479945c08 NFC don't convert types to identical types 2023-12-15 23:56:24 +01:00
Jubilee
1d54949765
Rollup merge of #118396 - compiler-errors:ast-lang-items, r=cjgillot
Collect lang items from AST, get rid of `GenericBound::LangItemTrait`

r? `@cjgillot`
cc #115178

Looking forward, the work to remove `QPath::LangItem` will also be significantly more difficult, but I plan on doing it as well. Specifically, we have to change:
1. A lot of `rustc_ast_lowering` for things like expr `..`
2. A lot of astconv, since we actually instantiate lang and non-lang paths quite differently.
3. A ton of diagnostics and clippy lints that are special-cased via `QPath::LangItem`

Meanwhile, it was pretty easy to remove `GenericBound::LangItemTrait`, so I just did that here.
2023-12-15 14:08:15 -08:00
Michael Goulet
fc010de26b banish hir::GenericBound::LangItemTrait 2023-12-15 16:17:27 +00:00
Michael Goulet
ad00641b74 Collect lang items from AST 2023-12-15 16:12:27 +00:00
Michael Goulet
1cc0d7d56c Annotate some more bugs 2023-12-15 14:45:06 +00:00
Ross Smyth
663bea5a96 Add better ICE messages for some undescriptive panics 2023-12-15 00:50:55 -05:00
Matthias Krüger
dbc6ec6636
Rollup merge of #118759 - compiler-errors:bare-unit-structs, r=petrochenkov
Support bare unit structs in destructuring assignments

We should be allowed to use destructuring assignments on *bare* unit structs, not just unit structs that are located within other pattern constructors.

Fixes #118753

r? petrochenkov since you reviewed #95380, reassign if you're busy or don't want to review this.
2023-12-13 18:03:33 +01:00
Nadrieril
e274372689 Correctly gate the parsing of match arms without body 2023-12-12 14:42:04 +01:00