rust/compiler
bors f132bcf3bd Auto merge of #94081 - oli-obk:lazy_tait_take_two, r=nikomatsakis
Lazy type-alias-impl-trait take two

### user visible change 1: RPIT inference from recursive call sites

Lazy TAIT has an insta-stable change. The following snippet now compiles, because opaque types can now have their hidden type set from wherever the opaque type is mentioned.

```rust
fn bar(b: bool) -> impl std::fmt::Debug {
    if b {
        return 42
    }
    let x: u32 = bar(false); // this errors on stable
    99
}
```

The return type of `bar` stays opaque, you can't do `bar(false) + 42`, you need to actually mention the hidden type.

### user visible change 2: divergence between RPIT and TAIT in return statements

Note that `return` statements and the trailing return expression are special with RPIT (but not TAIT). So

```rust
#![feature(type_alias_impl_trait)]
type Foo = impl std::fmt::Debug;

fn foo(b: bool) -> Foo {
    if b {
        return vec![42];
    }
    std::iter::empty().collect() //~ ERROR `Foo` cannot be built from an iterator
}

fn bar(b: bool) -> impl std::fmt::Debug {
    if b {
        return vec![42]
    }
    std::iter::empty().collect() // Works, magic (accidentally stabilized, not intended)
}
```

But when we are working with the return value of a recursive call, the behavior of RPIT and TAIT is the same:

```rust
type Foo = impl std::fmt::Debug;

fn foo(b: bool) -> Foo {
    if b {
        return vec![];
    }
    let mut x = foo(false);
    x = std::iter::empty().collect(); //~ ERROR `Foo` cannot be built from an iterator
    vec![]
}

fn bar(b: bool) -> impl std::fmt::Debug {
    if b {
        return vec![];
    }
    let mut x = bar(false);
    x = std::iter::empty().collect(); //~ ERROR `impl Debug` cannot be built from an iterator
    vec![]
}
```

### user visible change 3: TAIT does not merge types across branches

In contrast to RPIT, TAIT does not merge types across branches, so the following does not compile.

```rust
type Foo = impl std::fmt::Debug;

fn foo(b: bool) -> Foo {
    if b {
        vec![42_i32]
    } else {
        std::iter::empty().collect()
        //~^ ERROR `Foo` cannot be built from an iterator over elements of type `_`
    }
}
```

It is easy to support, but we should make an explicit decision to include the additional complexity in the implementation (it's not much, see a721052457cf513487fb4266e3ade65c29b272d2 which needs to be reverted to enable this).

### PR formalities

previous attempt: #92007

This PR also includes #92306 and #93783, as they were reverted along with #92007 in #93893

fixes #93411
fixes #88236
fixes #89312
fixes #87340
fixes #86800
fixes #86719
fixes #84073
fixes #83919
fixes #82139
fixes #77987
fixes #74282
fixes #67830
fixes #62742
fixes #54895
2022-03-30 05:04:45 +00:00
..
rustc Propagate parallel_compiler feature through rustc crates. Turned off feature gives change of builded crates: 238 -> 224. 2022-03-28 08:41:12 +03:00
rustc_apfloat Stabilize iter::zip. 2021-12-14 18:50:31 -04:00
rustc_arena Remove unused dep from rustc_arena 2022-02-02 17:37:14 +01:00
rustc_ast Remove Nonterminal::NtTT. 2022-03-28 10:03:02 +11:00
rustc_ast_lowering Rollup merge of #94960 - codehorseman:master, r=oli-obk 2022-03-17 22:55:05 +01:00
rustc_ast_passes Minor let_chains modification 2022-03-25 18:50:52 -03:00
rustc_ast_pretty Remove Nonterminal::NtTT. 2022-03-28 10:03:02 +11:00
rustc_attr Rollup merge of #94948 - jhpratt:rustc_deprecated, r=Dylan-DPC 2022-03-20 09:14:59 +01:00
rustc_borrowck Auto merge of #94081 - oli-obk:lazy_tait_take_two, r=nikomatsakis 2022-03-30 05:04:45 +00:00
rustc_builtin_macros Move resolve_path to rustc_builtin_macros and make it private 2022-03-26 16:47:13 +01:00
rustc_codegen_cranelift Don't declare test_variadic_fnptr with two conflicting signatures 2022-03-20 21:09:35 +01:00
rustc_codegen_gcc Merge commit '39683d8eb7' into sync_cg_gcc-2022-03-26 2022-03-26 18:29:37 +01:00
rustc_codegen_llvm Auto merge of #95300 - workingjubilee:less-bitsets, r=eddyb 2022-03-28 05:48:25 +00:00
rustc_codegen_ssa Rollup merge of #95328 - DrMeepster:box_gep_err, r=oli-obk 2022-03-28 20:41:51 +02:00
rustc_const_eval Normalize all projections in mir validation again 2022-03-28 16:30:16 +00:00
rustc_data_structures Auto merge of #94081 - oli-obk:lazy_tait_take_two, r=nikomatsakis 2022-03-30 05:04:45 +00:00
rustc_driver Propagate parallel_compiler feature through rustc crates. Turned off feature gives change of builded crates: 238 -> 224. 2022-03-28 08:41:12 +03:00
rustc_error_codes Add long error explanation for E0667 2022-03-27 14:09:52 +02:00
rustc_errors Make fatal DiagnosticBuilder yield never 2022-03-27 22:25:32 -07:00
rustc_expand Rollup merge of #95390 - nnethercote:allow-doc-comments-in-macros, r=petrochenkov 2022-03-28 16:08:11 +02:00
rustc_feature move adt_const_params to its own tracking issue 2022-03-21 16:33:42 +01:00
rustc_fs_util Migrate to 2021 2021-09-20 22:21:42 -04:00
rustc_graphviz eplace usages of vec![].into_iter with [].into_iter 2022-01-09 14:09:25 +11:00
rustc_hir Rename ~const Drop to ~const Destruct 2022-03-21 17:04:03 +11:00
rustc_hir_pretty resolve: Fix incorrect results of opt_def_kind query for some built-in macros 2022-02-24 22:54:36 +03:00
rustc_incremental incr. comp.: Let compiler retry finalizing session directory a few times. 2022-03-25 14:14:26 +01:00
rustc_index Fix small typo in FIXME 2022-03-15 12:04:23 +01:00
rustc_infer Auto merge of #94081 - oli-obk:lazy_tait_take_two, r=nikomatsakis 2022-03-30 05:04:45 +00:00
rustc_interface Propagate parallel_compiler feature through rustc crates. Turned off feature gives change of builded crates: 238 -> 224. 2022-03-28 08:41:12 +03:00
rustc_lexer Add test for >65535 hashes in lexing raw string 2022-03-16 06:37:41 +01:00
rustc_lint Remove opaque type obligation and just register opaque types as they are encountered. 2022-03-28 16:57:45 +00:00
rustc_lint_defs resolve the conflict in compiler/rustc_session/src/parse.rs 2022-03-16 20:12:30 +08:00
rustc_llvm RustWrapper: add missing include 2022-03-10 11:16:33 -05:00
rustc_log Make rustc_log doc test runnable 2022-01-03 22:31:56 -08:00
rustc_macros add #[rustc_pass_by_value] to more types 2022-03-08 15:39:52 +01:00
rustc_metadata rustc_error: make ErrorReported impossible to construct 2022-03-16 10:35:24 -05:00
rustc_middle Auto merge of #94081 - oli-obk:lazy_tait_take_two, r=nikomatsakis 2022-03-30 05:04:45 +00:00
rustc_mir_build Revert "Auto merge of #93893 - oli-obk:sad_revert, r=oli-obk" 2022-03-28 16:27:14 +00:00
rustc_mir_dataflow Nit 2022-03-27 10:58:55 -07:00
rustc_mir_transform Auto merge of #95149 - cjgillot:once-diag, r=estebank 2022-03-26 00:54:54 +00:00
rustc_monomorphize Make fatal DiagnosticBuilder yield never 2022-03-27 22:25:32 -07:00
rustc_parse Rollup merge of #95318 - rust-lang:notriddle/issue-95208, r=wesleywiser 2022-03-28 20:41:50 +02:00
rustc_parse_format Correctly mark the span of captured arguments in format_args!() 2022-02-16 07:34:06 +00:00
rustc_passes use format-args-capture and remove unnecessary nested if blocks in some parts of rustc_passes 2022-03-22 00:02:18 +09:00
rustc_plugin_impl replace dynamic library module with libloading 2021-12-06 12:03:47 -05:00
rustc_privacy rustc_error: make ErrorReported impossible to construct 2022-03-16 10:35:24 -05:00
rustc_query_impl Propagate parallel_compiler feature through rustc crates. Turned off feature gives change of builded crates: 238 -> 224. 2022-03-28 08:41:12 +03:00
rustc_query_system Auto merge of #94081 - oli-obk:lazy_tait_take_two, r=nikomatsakis 2022-03-30 05:04:45 +00:00
rustc_resolve resolve: Simplify some diagnostic code to avoid an ICE 2022-03-27 02:43:29 +03:00
rustc_save_analysis Improve AdtDef interning. 2022-03-11 13:31:24 +11:00
rustc_serialize Delete Decoder::read_unit 2022-02-22 18:14:51 -05:00
rustc_session Make fatal DiagnosticBuilder yield never 2022-03-27 22:25:32 -07:00
rustc_span Make fatal DiagnosticBuilder yield never 2022-03-27 22:25:32 -07:00
rustc_symbol_mangling resolve the conflict in compiler/rustc_session/src/parse.rs 2022-03-16 20:12:30 +08:00
rustc_target Rollup merge of #95341 - Meziu:armv6k-3ds-target, r=nagisa 2022-03-27 05:36:11 +02:00
rustc_trait_selection Also use the RPIT back compat hack in trait projection 2022-03-28 17:09:00 +00:00
rustc_traits Remove opaque type obligation and just register opaque types as they are encountered. 2022-03-28 16:57:45 +00:00
rustc_ty_utils Rename ~const Drop to ~const Destruct 2022-03-21 17:04:03 +11:00
rustc_type_ir Revert "Auto merge of #93893 - oli-obk:sad_revert, r=oli-obk" 2022-03-28 16:27:14 +00:00
rustc_typeck Auto merge of #94081 - oli-obk:lazy_tait_take_two, r=nikomatsakis 2022-03-30 05:04:45 +00:00