<feed xmlns='http://www.w3.org/2005/Atom'>
<title>rust/compiler/rustc_pattern_analysis/src/rustc.rs, branch 1.77.2</title>
<subtitle>https://github.com/rust-lang/rust
</subtitle>
<id>http://git.dreamy.place/mirrors/rust/atom?h=1.77.2</id>
<link rel='self' href='http://git.dreamy.place/mirrors/rust/atom?h=1.77.2'/>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/'/>
<updated>2024-01-30T16:06:30+00:00</updated>
<entry>
<title>Limit the use of `PlaceCtxt`</title>
<updated>2024-01-30T16:06:30+00:00</updated>
<author>
<name>Nadrieril</name>
<email>nadrieril+git@gmail.com</email>
</author>
<published>2024-01-24T20:16:57+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=cb0e8c508c98590346f5943f1ebd0e901acf87f9'/>
<id>urn:sha1:cb0e8c508c98590346f5943f1ebd0e901acf87f9</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Make `PatternColumn` generic in `Cx`</title>
<updated>2024-01-30T15:57:44+00:00</updated>
<author>
<name>Nadrieril</name>
<email>nadrieril+git@gmail.com</email>
</author>
<published>2024-01-24T19:38:21+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=0b2579a1b617e83da98008bac9b93c36c43a8f4b'/>
<id>urn:sha1:0b2579a1b617e83da98008bac9b93c36c43a8f4b</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Stop using derivative in rustc_pattern_analysis</title>
<updated>2024-01-27T12:21:01+00:00</updated>
<author>
<name>Laurențiu Nicola</name>
<email>lnicola@dend.ro</email>
</author>
<published>2024-01-27T12:18:33+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=f5c78955c88ac37b7422bef6ee9ec993c0a5dad2'/>
<id>urn:sha1:f5c78955c88ac37b7422bef6ee9ec993c0a5dad2</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Rollup merge of #118803 - Nadrieril:min-exhaustive-patterns, r=compiler-errors</title>
<updated>2024-01-26T05:36:36+00:00</updated>
<author>
<name>Matthias Krüger</name>
<email>matthias.krueger@famsik.de</email>
</author>
<published>2024-01-26T05:36:36+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=a37fa372815d6049605b1fc68b4e603510b79f68'/>
<id>urn:sha1:a37fa372815d6049605b1fc68b4e603510b79f68</id>
<content type='text'>
Add the `min_exhaustive_patterns` feature gate

## Motivation

Pattern-matching on empty types is tricky around unsafe code. For that reason, current stable rust conservatively requires arms for empty types in all but the simplest case. It has long been the intention to allow omitting empty arms when it's safe to do so. The [`exhaustive_patterns`](https://github.com/rust-lang/rust/issues/51085) feature allows the omission of all empty arms, but hasn't been stabilized because that was deemed dangerous around unsafe code.

## Proposal

This feature aims to stabilize an uncontroversial subset of exhaustive_patterns. Namely: when `min_exhaustive_patterns` is enabled and the data we're matching on is guaranteed to be valid by rust's operational semantics, then we allow empty arms to be omitted. E.g.:

```rust
let x: Result&lt;T, !&gt; = foo();
match x { // ok
    Ok(y) =&gt; ...,
}
let Ok(y) = x; // ok
```

If the place is not guaranteed to hold valid data (namely ptr dereferences, ref dereferences (conservatively) and union field accesses), then we keep stable behavior i.e. we (usually) require arms for the empty cases.

```rust
unsafe {
    let ptr: *const Result&lt;u32, !&gt; = ...;
    match *ptr {
        Ok(x) =&gt; { ... }
        Err(_) =&gt; { ... } // still required
    }
}
let foo: Result&lt;u32, &amp;!&gt; = ...;
match foo {
    Ok(x) =&gt; { ... }
    Err(&amp;_) =&gt; { ... } // still required because of the dereference
}
unsafe {
    let ptr: *const ! = ...;
    match *ptr {} // already allowed on stable
}
```

Note that we conservatively consider that a valid reference can point to invalid data, hence we don't allow arms of type `&amp;!` and similar cases to be omitted. This could eventually change depending on [opsem decisions](https://github.com/rust-lang/unsafe-code-guidelines/issues/413). Whenever opsem is undecided on a case, we conservatively keep today's stable behavior.

I proposed this behavior in the [`never_patterns`](https://github.com/rust-lang/rust/issues/118155) feature gate but it makes sense on its own and could be stabilized more quickly. The two proposals nicely complement each other.

## Unresolved Questions

Part of the question is whether this requires an RFC. I'd argue this doesn't need one since there is no design question beyond the intent to omit unreachable patterns, but I'm aware the problem can be framed in ways that require design (I'm thinking of the [original never patterns proposal](https://smallcultfollowing.com/babysteps/blog/2018/08/13/never-patterns-exhaustive-matching-and-uninhabited-types-oh-my/), which would frame this behavior as "auto-nevering" happening).

EDIT: I initially proposed a future-compatibility lint as part of this feature, I don't anymore.
</content>
</entry>
<entry>
<title>Rollup merge of #120318 - Nadrieril:share-debug-impl, r=compiler-errors</title>
<updated>2024-01-25T07:39:45+00:00</updated>
<author>
<name>Matthias Krüger</name>
<email>matthias.krueger@famsik.de</email>
</author>
<published>2024-01-25T07:39:45+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=a1ecced532ecffb288ca176cce56a8aa96f155ab'/>
<id>urn:sha1:a1ecced532ecffb288ca176cce56a8aa96f155ab</id>
<content type='text'>
pattern_analysis: Reuse most of the `DeconstructedPat` `Debug` impl

The `DeconstructedPat: Debug` is best-effort because we'd need `tcx` to get things like field names etc. Since rust-analyzer has a similar constraint, this PR moves most the impl to be shared between the two. While I was at it I also fixed a nit in the `IntRange: Debug` impl.

r? `@compiler-errors`
</content>
</entry>
<entry>
<title>Implement feature gate logic</title>
<updated>2024-01-24T23:12:32+00:00</updated>
<author>
<name>Nadrieril</name>
<email>nadrieril+git@gmail.com</email>
</author>
<published>2024-01-18T18:22:44+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=95a14d43d7aa4b37a8f45a0d97d109f91f9b079f'/>
<id>urn:sha1:95a14d43d7aa4b37a8f45a0d97d109f91f9b079f</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Most of the `DeconstructedPat` `Debug` impl is reusable</title>
<updated>2024-01-24T19:04:33+00:00</updated>
<author>
<name>Nadrieril</name>
<email>nadrieril+git@gmail.com</email>
</author>
<published>2024-01-24T19:04:33+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=bdab21399372bee9127b5e6641c8a54034005138'/>
<id>urn:sha1:bdab21399372bee9127b5e6641c8a54034005138</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Let `ctor_sub_tys` return any Iterator they want</title>
<updated>2024-01-24T15:55:26+00:00</updated>
<author>
<name>Nadrieril</name>
<email>nadrieril+git@gmail.com</email>
</author>
<published>2024-01-24T15:55:26+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=e088016f9d0dd8d69941a2ad2088ff2631706c1c'/>
<id>urn:sha1:e088016f9d0dd8d69941a2ad2088ff2631706c1c</id>
<content type='text'>
Since we always clone and allocate the types somewhere else ourselves,
no need to ask for `Cx` to do the allocation.
</content>
</entry>
<entry>
<title>Rename `TyCtxt::emit_spanned_lint` as `TyCtxt::emit_node_span_lint`.</title>
<updated>2024-01-22T21:09:05+00:00</updated>
<author>
<name>Nicholas Nethercote</name>
<email>n.nethercote@gmail.com</email>
</author>
<published>2024-01-16T05:27:02+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=e164cf30f8f96551cedece4ed199d7ecb5832648'/>
<id>urn:sha1:e164cf30f8f96551cedece4ed199d7ecb5832648</id>
<content type='text'>
</content>
</entry>
<entry>
<title>Remove Ty: Copy bound</title>
<updated>2024-01-20T14:22:14+00:00</updated>
<author>
<name>Nadrieril</name>
<email>nadrieril+git@gmail.com</email>
</author>
<published>2023-12-22T23:21:27+00:00</published>
<link rel='alternate' type='text/html' href='http://git.dreamy.place/mirrors/rust/commit/?id=796cdc590c0f6badb9629feb2a2b55873408cc0f'/>
<id>urn:sha1:796cdc590c0f6badb9629feb2a2b55873408cc0f</id>
<content type='text'>
</content>
</entry>
</feed>
