rust/src/test
bors 900cf5e890 Auto merge of #88804 - Mark-Simulacrum:never-algo-v2, r=nikomatsakis,jackh726
Revise never type fallback algorithm

This is a rebase of https://github.com/rust-lang/rust/pull/84573, but dropping the stabilization of never type (and the accompanying large test diff).

Each commit builds & has tests updated alongside it, and could be reviewed in a more or less standalone fashion. But it may make more sense to review the PR as a whole, I'm not sure. It should be noted that tests being updated isn't really a good indicator of final behavior -- never_type_fallback is not enabled by default in this PR, so we can't really see the full effects of the commits here.

This combines the work by Niko, which is [documented in this gist](https://gist.github.com/nikomatsakis/7a07b265dc12f5c3b3bd0422018fa660), with some additional rules largely derived to target specific known patterns that regress with the algorithm solely derived by Niko. We build these from an intuition that:

* In general, fallback to `()` is *sound* in all cases
* But, in general, we *prefer* fallback to `!` as it accepts more code, particularly that written to intentionally use `!` (e.g., Result's with a Infallible/! variant).

When evaluating Niko's proposed algorithm, we find that there are certain cases where fallback to `!` leads to compilation failures in real-world code, and fallback to `()` fixes those errors. In order to allow for stabilization, we need to fix a good portion of these patterns.

The final rule set this PR proposes is that, by default, we fallback from `?T` to `!`, with the following exceptions:

1. `?T: Foo` and `Bar::Baz = ?T` and `(): Foo`, then fallback to `()`
2. Per [Niko's algorithm](https://gist.github.com/nikomatsakis/7a07b265dc12f5c3b3bd0422018fa660#proposal-fallback-chooses-between--and--based-on-the-coercion-graph), the "live" `?T` also fallback to `()`.

The first rule is necessary to address a fairly common pattern which boils down to something like the snippet below. Without rule 1, we do not see the closure's return type as needing a () fallback, which leads to compilation failure.

```rust
#![feature(never_type_fallback)]

trait Bar { }
impl Bar for () {  }
impl Bar for u32 {  }

fn foo<R: Bar>(_: impl Fn() -> R) {}

fn main() {
    foo(|| panic!());
}
```

r? `@jackh726`
2021-09-23 22:45:22 +00:00
..
assembly rustc_codegen_llvm: make sse4.2 imply crc32 for LLVM 14 2021-09-20 11:31:55 -04:00
auxiliary
codegen rustc_codegen_llvm: make sse4.2 imply crc32 for LLVM 14 2021-09-20 11:31:55 -04:00
codegen-units
debuginfo Rollup merge of #89127 - wesleywiser:reenable_mutex_debuginfo_test, r=ehuss 2021-09-22 19:03:23 +02:00
incremental Bless incremental tests. 2021-09-20 08:32:21 +02:00
mir-opt ./x.py test --bless 2021-09-18 00:00:00 +00:00
pretty Use ZST for fmt unsafety 2021-09-21 10:04:44 -05:00
run-make Auto merge of #88161 - michaelwoerister:fix-whole-archive-no-bundle, r=petrochenkov 2021-09-07 12:31:11 +00:00
run-make-fulldeps Fix test 2021-09-22 11:48:01 -05:00
run-pass-valgrind
rustdoc Add test for primitive in "jump to definition" feature 2021-09-13 17:44:39 +02:00
rustdoc-gui Rollup merge of #88896 - GuillaumeGomez:flakyness, r=camelid 2021-09-13 21:20:43 +02:00
rustdoc-js fix(rustdoc): generics search 2021-07-01 06:40:27 -07:00
rustdoc-js-std Fix linkcheck issues 2021-09-12 02:30:24 +00:00
rustdoc-json rustdoc: Clean up handling of lifetime bounds 2021-09-02 14:27:59 -07:00
rustdoc-ui Don't lint about missing code examples in derived traits 2021-09-17 00:39:15 +02:00
ui Auto merge of #88804 - Mark-Simulacrum:never-algo-v2, r=nikomatsakis,jackh726 2021-09-23 22:45:22 +00:00
ui-fulldeps Detect bare blocks with type ascription that were meant to be a struct literal 2021-09-03 14:43:04 +00:00
COMPILER_TESTS.md