Commit Graph

4506 Commits

Author SHA1 Message Date
bors
f8fe517144 Auto merge of #116274 - RalfJung:soft_unstable, r=cjgillot
make soft_unstable show up in future breakage reports

If we want to break these in the future, let's warn users of affected crates.
2023-12-25 16:26:15 +00:00
bors
f2348fb29a Auto merge of #119122 - matthewjasper:if-let-guard-scoping, r=TaKO8Ki
Give temporaries in if let guards correct scopes

Temporaries in if-let guards have scopes that escape the match arm, this causes problems because the drops might be for temporaries that are not storage live. This PR changes the scope of temporaries in if-let guards to be limited to the arm:

```rust
_ if let Some(s) = std::convert::identity(&Some(String::new())) => {}
//                Temporary for Some(String::new()) is dropped here ^
```

We also now deduplicate temporaries between copies of the guard created for or-patterns:

```rust
// Only create a single Some(String::new()) temporary variable
_ | _ if let Some(s) = std::convert::identity(&Some(String::new())) => {}
```

This changes MIR building to pass around `ExprId`s rather than `Expr`s so that we have a way to index different expressions.

cc #51114
Closes #116079
2023-12-25 04:06:58 +00:00
bors
471dcbdb09 Auto merge of #119274 - RalfJung:raw-ptr-pattern-ice, r=compiler-errors
fix ICE when using raw ptr in a pattern

Fixes https://github.com/rust-lang/rust/issues/119270
2023-12-25 00:03:59 +00:00
bors
1a086e49f1 Auto merge of #118796 - Nadrieril:fix-exponential-id-match-2, r=cjgillot
Exhaustiveness: Improve complexity on some wide matches

https://github.com/rust-lang/rust/issues/118437 revealed an exponential case in exhaustiveness checking. While [exponential cases are unavoidable](https://compilercrim.es/rust-np/), this one only showed up after my https://github.com/rust-lang/rust/pull/117611 rewrite of the algorithm. I remember anticipating a case like this and dismissing it as unrealistic, but here we are :').

The tricky match is as follows:
```rust
match command {
    BaseCommand { field01: true, .. } => {}
    BaseCommand { field02: true, .. } => {}
    BaseCommand { field03: true, .. } => {}
    BaseCommand { field04: true, .. } => {}
    BaseCommand { field05: true, .. } => {}
    BaseCommand { field06: true, .. } => {}
    BaseCommand { field07: true, .. } => {}
    BaseCommand { field08: true, .. } => {}
    BaseCommand { field09: true, .. } => {}
    BaseCommand { field10: true, .. } => {}
    // ...20 more of the same

    _ => {}
}
```

To fix this, this PR formalizes a concept of "relevancy" (naming is hard) that was already used to decide what patterns to report. Now we track it for every row, which in wide matches like the above can drastically cut on the number of cases we explore. After this fix, the above match is checked with linear-many cases instead of exponentially-many.

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

r? `@cjgillot`
2023-12-24 14:40:36 +00:00
bors
08cc634f1a Auto merge of #117176 - bvanjoi:fix-116796, r=jackh726
mark ty::Const::Error when meet unsupport ty for const generic params

Close #116796
2023-12-24 10:28:25 +00:00
Ralf Jung
41020d1337 fix ICE when using raw ptr in a pattern 2023-12-24 11:10:38 +01:00
bors
cdd6374f16 Auto merge of #119218 - Nadrieril:nested-opaque-reveal, r=compiler-errors
Exhaustiveness: Reveal empty opaques in depth

Follow-up to https://github.com/rust-lang/rust/pull/116821. As noted [there](https://github.com/rust-lang/rust/pull/116821#discussion_r1376673420), the current implementation doesn't detect emptiness of opaques when the opaque is nested inside a type. This doesn't matter for stable behavior (which ignores nested empty types anyway) but does matter for the [`exhaustive_patterns`](https://github.com/rust-lang/rust/issues/51085)/[`min_exhaustive_patterns`](https://github.com/rust-lang/rust/pull/118803) features.

This PR fixes this behavior by adding `InhabitedPredicate::apply_reveal_opaque` that considers opaque types when determining inhabitedness.

r? `@compiler-errors`
2023-12-23 23:00:08 +00:00
bohan
0f814e3899 add test for #116796 2023-12-24 01:58:13 +08:00
Deadbeef
3006814404 add a test for ICE #112822 2023-12-23 15:09:55 +00:00
Nadrieril
34307ab7c5 Reveal empty opaques in depth 2023-12-23 14:59:12 +01:00
bors
edcbcc768a Auto merge of #119072 - fee1-dead-contrib:effects-fixes, r=compiler-errors
Clean up `check_consts` and misc fixes

1. Remove most of the logic around erroring with trait methods. I have kept the part resolving it to a concrete impl, as that is used for const stability checks.
2. Turning on `effects` causes ICE with generic args, due to `~const Tr` when `Tr` is not `#[const_trait]` tripping up expectation in code that handles generic args, more specifically here:
8681e077b8/compiler/rustc_hir_analysis/src/astconv/generics.rs (L377)

We set `arg_count.correct` to `Err` to correctly signal that an error has already been reported.

3. UI test blesses.

Edit(fmease): Fixes #117244 (UI test is in #119099 for now).

r? compiler-errors
2023-12-23 12:26:22 +00:00
Nadrieril
71e83347bb Improve performance on wide matches 2023-12-23 13:11:38 +01: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
7dd095598b
Rollup merge of #119077 - tmiasko:lint, r=cjgillot
Separate MIR lints from validation

Add a MIR lint pass, enabled with -Zlint-mir, which identifies undefined or
likely erroneous behaviour.

The initial implementation mostly migrates existing checks of this nature from
MIR validator, where they did not belong (those checks have false positives and
there is nothing inherently invalid about MIR with undefined behaviour).

Fixes #104736
Fixes #104843
Fixes #116079
Fixes #116736
Fixes #118990
2023-12-22 21:41:03 -05:00
bors
d6d7a93866 Auto merge of #118824 - aliemjay:perf-region-cons, r=compiler-errors
use Vec for region constraints instead of BTreeMap

~1% perf gain

Diagnostic regressions need more investigation.

r? `@ghost`
2023-12-22 20:28:48 +00:00
Eric Holk
aaa3e7642b
Update test outputs 2023-12-22 11:01:07 -08:00
Matthias Krüger
b24e8784de
Rollup merge of #119215 - mu001999:fix/119209, r=Nilstrieb
Emits error if has bound regions

Fixes #119209
2023-12-22 19:01:28 +01:00
r0cky
d3f466a3a7 Update test 2023-12-23 00:09:37 +08:00
r0cky
4830325a14 Emits error if has bound regions 2023-12-22 23:25:54 +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
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
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
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
Matthew Jasper
d437a111f5 Give temporaries in if let guards correct scopes
- Make temporaries in if-let guards be the same variable in MIR when
  the guard is duplicated due to or-patterns.
- Change the "destruction scope" for match arms to be the arm scope rather
  than the arm body scope.
- Add tests.
2023-12-21 13:35:56 +00:00
surechen
4897d5eccf Simple modification of diagnostic information
fixes #119067
2023-12-21 10:17:11 +08: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
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
León Orell Valerian Liehr
5e4f12b41a
Refactor AST trait bound modifiers 2023-12-20 19:39:46 +01:00
Vadim Petrochenkov
006e0ef18d resolve: Stop feeding visibilities for import list stems 2023-12-20 20:27:10 +03:00
Nadrieril
2a87bae48d Reveal opaque types in exhaustiveness checking 2023-12-20 14:43:00 +01:00
Nadrieril
7e4924b55d Add tests 2023-12-20 14:43:00 +01:00
bors
f9d52dc594 Auto merge of #119134 - petrochenkov:feedvis2, r=compiler-errors
resolve: Feed visibilities for unresolved trait impl items

Fixes https://github.com/rust-lang/rust/issues/119073
2023-12-20 11:13:22 +00:00
Matthias Krüger
16a231d8eb
Rollup merge of #119071 - lcnr:overflowo, r=compiler-errors
-Znext-solver: adapt overflow rules to avoid breakage

Do not erase overflow constraints if they are from equating the impl header when normalizing[^1].

This should be the minimal change to not break crates depending on the old project behavior of "apply impl constraints while only lazily evaluating any nested goals".

Fixes https://github.com/rust-lang/trait-system-refactor-initiative/issues/70, see https://hackmd.io/ATf4hN0NRY-w2LIVgeFsVg for the reasoning behind this.

Only keeping constraints on overflow for `normalize-to` goals as that's the only thing needed for backcompat. It also allows us to not track the origin of root obligations. The issue with root goals would be something like the following:

```rust
trait Foo {}
trait Bar {}

trait FooBar {}
impl<T: Foo + Bar> FooBar for T {}

// These two should behave the same, rn we can drop constraints for both,
// but if we don't drop `Misc` goals we would only drop the constraints for
// `FooBar` unless we track origins of root obligations.
fn func1<T: Foo + Bar>() {}
fn func2<T: FooBaz>() {}
```

[^1]: mostly, the actual rules are slightly different

r? ``@compiler-errors``
2023-12-20 09:46:11 +01:00
Matthias Krüger
f3f9b3043e
Rollup merge of #118691 - chfogelman:improve-cstr-error, r=fmease
Add check for possible CStr literals in pre-2021

Fixes [#118654](https://github.com/rust-lang/rust/issues/118654)

Adds information to errors caused by possible CStr literals in pre-2021.

The lexer separates `c"str"` into two tokens if the edition is less than 2021, which later causes an error when parsing. This error now has a more helpful message that directs them to information about editions. However, the user might also have written `c "str"` in a later edition, so to not confuse people who _are_ using a recent edition, I also added a note about whitespace.

We could probably figure out exactly which scenario has been encountered by examining spans and editions, but I figured it would be better not to overcomplicate the creation of the error too much.

This is my first code PR and I tried to follow existing conventions as much as possible, but I probably missed something, so let me know!
2023-12-20 09:46:10 +01:00
bors
51c0db6a91 Auto merge of #106790 - the8472:rawvec-niche, r=scottmcm
add more niches to rawvec

Previously RawVec only had a single niche in its `NonNull` pointer. With this change it now has `isize::MAX` niches since half the value-space of the capacity field is never needed, we can't have a capacity larger than isize::MAX.
2023-12-20 02:19:10 +00:00
Eric Holk
397f4a15bb
Add additional tests and update existing tests 2023-12-19 16:12:17 -08:00
Carter Hunt Fogelman
2c96025874 Improve compiler error for c-strings in pre-2021 2023-12-19 13:28:48 -08: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
Vadim Petrochenkov
7571f6f685 resolve: Feed visibilities for unresolved trait impl items 2023-12-19 22:33:26 +03:00
Nicholas Nethercote
286329870d De-weirdify fatally_break_rust.
The easter egg ICE on `break rust` is weird: it's the one ICE in the
entire compiler that doesn't immediately abort, which makes it
annoyingly inconsistent.

This commit changes it to abort. As part of this, the extra notes are
now appended onto the bug dignostic, rather than being printed as
individual note diagnostics, which changes the output format a bit.
These changes don't interferes with the joke, but they do help with my
ongoing cleanups to error handling.
2023-12-19 20:58:45 +11:00
Matthias Krüger
1333632ae9
Rollup merge of #119098 - compiler-errors:hangs, r=lcnr
Adjust the ignore-compare-mode-next-solver for hangs

Some new tests hang, some old tests don't hang.

r? lcnr or anyone in `@rust-lang/initiative-trait-system-refactor`
2023-12-19 10:50:09 +01:00
Matthias Krüger
9a72b7d04f
Rollup merge of #119091 - compiler-errors:alias-eq-in-structural-normalize, r=lcnr
Use alias-eq in structural normalization

We don't need to register repeated normalizes-to goals in a loop in structural normalize, but instead we can piggyback on the fact that alias-eq will already normalize aliases until they are rigid.

This fixes rust-lang/trait-system-refactor-initiative#78.

r? lcnr
2023-12-19 10:50:08 +01:00
Deadbeef
e4f237d39e bless ui tests 2023-12-19 04:28:21 +00:00
bors
e999d8b6e1 Auto merge of #119047 - mu001999:fix/118772, r=wesleywiser
Check generic params after sigature for main-fn-ty

Fixes #118772
2023-12-19 02:41:58 +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 Goulet
0f10acf768 Add a test demonstrating that RFC's note on diverging returns is subsumed by just inferring unit as ret type 2023-12-18 23:56:44 +00:00
Michael Goulet
e1c03e9bda Adjust the ignore-compare-mode-next-solver for hangs 2023-12-18 23:55:47 +00:00