rust/compiler
bors f5079d00e6 Auto merge of #134185 - compiler-errors:impl-trait-in-bindings, r=oli-obk
(Re-)Implement `impl_trait_in_bindings`

This reimplements the `impl_trait_in_bindings` feature for local bindings.

"`impl Trait` in bindings" serve as a form of *trait* ascription, where the type basically functions as an infer var but additionally registering the `impl Trait`'s trait bounds for the infer type. These trait bounds can be used to enforce that predicates hold, and can guide inference (e.g. for closure signature inference):

```rust
let _: impl Fn(&u8) -> &u8 = |x| x;
```

They are implemented as an additional set of bounds that are registered when the type is lowered during typeck, and then these bounds are tied to a given `CanonicalUserTypeAscription` for borrowck. We enforce these `CanonicalUserTypeAscription` bounds during borrowck to make sure that the `impl Trait` types are sensitive to lifetimes:

```rust
trait Static: 'static {}
impl<T> Static for T where T: 'static {}

let local = 1;
let x: impl Static = &local;
//~^ ERROR `local` does not live long enough
```

r? oli-obk

cc #63065

---

Why can't we just use TAIT inference or something? Well, TAITs in bodies have the problem that they cannot reference lifetimes local to a body. For example:

```rust
type TAIT = impl Display;
let local = 0;
let x: TAIT = &local;
//~^ ERROR `local` does not live long enough
```

That's because TAITs requires us to do *opaque type inference* which is pretty strict, since we need to remap all of the lifetimes of the hidden type to universal regions. This is simply not possible here.

---

I consider this part of the "impl trait everywhere" experiment. I'm not certain if this needs yet another lang team experiment.
2024-12-14 10:22:43 +00:00
..
rustc switch jemalloc-sys back to tikv-jemalloc-sys, and update to 0.6.0 2024-12-03 08:56:33 +00:00
rustc_abi fix safe-transmute handling of enums 2024-12-01 18:28:04 +01:00
rustc_arena move strict provenance lints to new feature gate, remove old feature gates 2024-10-21 15:22:17 +01:00
rustc_ast Rollup merge of #134140 - compiler-errors:unsafe-binders-ast, r=oli-obk 2024-12-13 17:25:31 +01:00
rustc_ast_ir Add sugar for &pin (const|mut) types 2024-10-07 11:15:04 -07:00
rustc_ast_lowering (Re-)Implement impl_trait_in_bindings 2024-12-14 03:21:24 +00:00
rustc_ast_passes Rollup merge of #134140 - compiler-errors:unsafe-binders-ast, r=oli-obk 2024-12-13 17:25:31 +01:00
rustc_ast_pretty Add unwrap_unsafe_binder and wrap_unsafe_binder macro operators 2024-12-12 16:29:40 +00:00
rustc_attr ensure that all publicly reachable const fn have const stability info 2024-11-10 10:16:26 +01:00
rustc_baked_icu_data Delete the cfg(not(parallel)) serial compiler 2024-11-12 13:38:58 +00:00
rustc_borrowck Auto merge of #134185 - compiler-errors:impl-trait-in-bindings, r=oli-obk 2024-12-14 10:22:43 +00:00
rustc_builtin_macros Rollup merge of #134140 - compiler-errors:unsafe-binders-ast, r=oli-obk 2024-12-13 17:25:31 +01:00
rustc_codegen_cranelift Rollup merge of #134251 - bjorn3:various_cleanups2, r=oli-obk 2024-12-14 03:54:35 +01:00
rustc_codegen_gcc Auto merge of #133099 - RalfJung:forbidden-hardfloat-features, r=workingjubilee 2024-12-13 19:43:00 +00:00
rustc_codegen_llvm Auto merge of #133099 - RalfJung:forbidden-hardfloat-features, r=workingjubilee 2024-12-13 19:43:00 +00:00
rustc_codegen_ssa Rollup merge of #134251 - bjorn3:various_cleanups2, r=oli-obk 2024-12-14 03:54:35 +01:00
rustc_const_eval Auto merge of #134269 - matthiaskrgr:rollup-fkshwux, r=matthiaskrgr 2024-12-13 23:09:16 +00:00
rustc_data_structures Remove jobserver from Session 2024-12-13 10:21:22 +00:00
rustc_driver Use tidy to sort crate attributes for all compiler crates. 2024-06-12 15:49:10 +10:00
rustc_driver_impl Rollup merge of #134251 - bjorn3:various_cleanups2, r=oli-obk 2024-12-14 03:54:35 +01:00
rustc_error_codes Auto merge of #132706 - compiler-errors:async-closures, r=oli-obk 2024-12-13 00:37:51 +00:00
rustc_error_messages Delete the cfg(not(parallel)) serial compiler 2024-11-12 13:38:58 +00:00
rustc_errors Rollup merge of #134181 - estebank:trim-render, r=oli-obk 2024-12-14 03:54:31 +01:00
rustc_expand Keep track of parse errors in mods and don't emit resolve errors for paths involving them 2024-12-10 18:17:24 +00:00
rustc_feature (Re-)Implement impl_trait_in_bindings 2024-12-14 03:21:24 +00:00
rustc_fluent_macro use tracked_path in rustc_fluent_macro 2024-10-19 22:32:38 +08:00
rustc_fs_util Couple of changes to make it easier to compile rustc for wasm 2024-09-26 19:51:14 +00:00
rustc_graphviz Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
rustc_hir (Re-)Implement impl_trait_in_bindings 2024-12-14 03:21:24 +00:00
rustc_hir_analysis Auto merge of #134185 - compiler-errors:impl-trait-in-bindings, r=oli-obk 2024-12-14 10:22:43 +00:00
rustc_hir_pretty (Re-)Implement impl_trait_in_bindings 2024-12-14 03:21:24 +00:00
rustc_hir_typeck (Re-)Implement impl_trait_in_bindings 2024-12-14 03:21:24 +00:00
rustc_incremental Remove all threading through of ErrorGuaranteed from the driver 2024-12-06 18:42:31 +00:00
rustc_index Use BitSet in SparseBitMatrix. 2024-12-09 08:53:33 +11:00
rustc_index_macros Auto merge of #130867 - michirakara:steps_between, r=dtolnay 2024-11-22 10:54:22 +00:00
rustc_infer Assert that obligations are empty before deeply normalizing 2024-12-02 22:51:18 +00:00
rustc_interface Rollup merge of #134251 - bjorn3:various_cleanups2, r=oli-obk 2024-12-14 03:54:35 +01:00
rustc_lexer Add test to check unicode identifier version 2024-12-09 06:23:59 -08:00
rustc_lint Rollup merge of #134140 - compiler-errors:unsafe-binders-ast, r=oli-obk 2024-12-13 17:25:31 +01:00
rustc_lint_defs Actually walk into lifetimes and attrs in EarlyContextAndPass 2024-12-07 02:08:40 +00:00
rustc_llvm Auto merge of #129181 - beetrees:asm-spans, r=pnkfelix,compiler-errors 2024-12-12 02:34:06 +00:00
rustc_log Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
rustc_macros give a better error for tuple structs in derive(Diagnostic) 2024-10-27 21:23:28 -04:00
rustc_metadata Rollup merge of #134251 - bjorn3:various_cleanups2, r=oli-obk 2024-12-14 03:54:35 +01:00
rustc_middle Auto merge of #134185 - compiler-errors:impl-trait-in-bindings, r=oli-obk 2024-12-14 10:22:43 +00:00
rustc_mir_build Split UserTypeAnnotation to have a kind 2024-12-14 03:20:50 +00:00
rustc_mir_dataflow Rollup merge of #133938 - nnethercote:rustc_mir_dataflow-renamings, r=oli-obk 2024-12-13 17:25:29 +01:00
rustc_mir_transform Rollup merge of #133938 - nnethercote:rustc_mir_dataflow-renamings, r=oli-obk 2024-12-13 17:25:29 +01:00
rustc_monomorphize Implement projection and shim for AFIDT 2024-12-10 16:52:20 +00:00
rustc_next_trait_solver Rename projection_def_id to item_def_id 2024-12-11 00:59:43 +00:00
rustc_parse Rollup merge of #134140 - compiler-errors:unsafe-binders-ast, r=oli-obk 2024-12-13 17:25:31 +01:00
rustc_parse_format Remove 'apostrophes' from rustc_parse_format 2024-10-14 23:22:51 +02:00
rustc_passes (Re-)Implement impl_trait_in_bindings 2024-12-14 03:21:24 +00:00
rustc_pattern_analysis no more Reveal :( 2024-11-23 13:52:54 +01:00
rustc_privacy Introduce default_field_values feature 2024-12-09 21:55:01 +00:00
rustc_query_impl Rename ty_def_id so people will stop using it by accident 2024-12-13 16:36:38 +00:00
rustc_query_system Rename ty_def_id so people will stop using it by accident 2024-12-13 16:36:38 +00:00
rustc_resolve Rollup merge of #134140 - compiler-errors:unsafe-binders-ast, r=oli-obk 2024-12-13 17:25:31 +01:00
rustc_sanitizers Remove more traces of anonymous ADTs 2024-12-10 19:50:47 +00:00
rustc_serialize Fix explicit_iter_loop in rustc_serialize 2024-10-16 15:44:16 +02:00
rustc_session Rollup merge of #134251 - bjorn3:various_cleanups2, r=oli-obk 2024-12-14 03:54:35 +01:00
rustc_smir Fix ui-fulldep tests 2024-12-06 18:42:31 +00:00
rustc_span Auto merge of #134269 - matthiaskrgr:rollup-fkshwux, r=matthiaskrgr 2024-12-13 23:09:16 +00:00
rustc_symbol_mangling Remove more traces of anonymous ADTs 2024-12-10 19:50:47 +00:00
rustc_target Auto merge of #133099 - RalfJung:forbidden-hardfloat-features, r=workingjubilee 2024-12-13 19:43:00 +00:00
rustc_trait_selection (Re-)Implement impl_trait_in_bindings 2024-12-14 03:21:24 +00:00
rustc_traits Delay a bug when encountering an impl with unconstrained generics in codegen_select 2024-11-23 05:27:45 +00:00
rustc_transmute fix safe-transmute handling of enums 2024-12-01 18:28:04 +01:00
rustc_ty_utils Implement projection and shim for AFIDT 2024-12-10 16:52:20 +00:00
rustc_type_ir Rename projection_def_id to item_def_id 2024-12-11 00:59:43 +00:00
rustc_type_ir_macros do not relate Abi and Safety 2024-10-22 23:13:04 +02:00
stable_mir Rollup merge of #132161 - celinval:smir-fix-indent, r=compiler-errors 2024-11-08 18:51:28 +11:00