rust/compiler/rustc_borrowck/src
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
..
constraints Reduce visibilities. 2024-11-04 15:43:45 +11:00
diagnostics rustc_borrowck: Convert suggest_ampmut() 4-tuple to struct for readability 2024-12-13 16:35:43 +01:00
polonius reduce false positives of tail-expr-drop-order from consumed values 2024-11-20 20:53:11 +08:00
region_infer small code cleanup 2024-12-03 14:07:04 +01:00
type_check (Re-)Implement impl_trait_in_bindings 2024-12-14 03:21:24 +00:00
util Add warn(unreachable_pub) to rustc_borrowck. 2024-08-16 08:46:57 +10:00
borrow_set.rs Reduce visibilities. 2024-11-04 15:43:45 +11:00
borrowck_errors.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
consumers.rs Avoid Rc in BodyWithBorrowckFacts. 2024-10-04 16:48:16 +10:00
dataflow.rs Rename some Analysis and ResultsVisitor methods. 2024-12-10 12:07:13 +11:00
def_use.rs Rollup merge of #126013 - nnethercote:unreachable_pub, r=Urgau 2024-08-27 00:41:57 +02:00
facts.rs Dogfood feature(file_buffered) 2024-09-24 14:25:16 -07:00
lib.rs Rename some Analysis and ResultsVisitor methods. 2024-12-10 12:07:13 +11:00
location.rs Remove #[macro_use] extern crate tracing from rustc_borrowck. 2024-08-30 17:14:53 +10:00
member_constraints.rs Remove #[macro_use] extern crate tracing from rustc_borrowck. 2024-08-30 17:14:53 +10:00
nll.rs Pass flow_inits by value. 2024-11-19 11:46:33 +11:00
path_utils.rs compiler: Replace rustc_target with _abi in _borrowck 2024-11-02 20:31:47 -07:00
place_ext.rs Remove #[macro_use] extern crate tracing from rustc_borrowck. 2024-08-30 17:14:53 +10:00
places_conflict.rs update rustc_borrowck::places_conflict doc-comment 2024-10-10 10:33:29 +03:00
prefixes.rs Remove unnecessary continue. 2024-11-04 17:36:25 +11:00
renumber.rs uplift fold_regions to rustc_type_ir 2024-11-28 10:40:58 +01:00
session_diagnostics.rs Reformat using the new identifier sorting from rustfmt 2024-09-22 19:11:29 -04:00
universal_regions.rs Rollup merge of #133545 - clubby789:symbol-intern-lit, r=jieyouxu 2024-12-03 17:27:06 +01:00
used_muts.rs Remove unnecessary lifetimes in dataflow structs. 2024-09-09 16:14:18 +10:00