rust/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
..
bootstrap Rollup merge of #134240 - cuviper:dist-llvm-tools, r=jieyouxu 2024-12-14 03:54:34 +01:00
build_helper move src/tools/build_helper into src/build_helper 2024-11-11 11:19:11 +03:00
ci Bump Fuchsia 2024-12-11 16:35:43 -08:00
doc Rollup merge of #133930 - chriskrycho:mdbook-trpl-package, r=ehuss 2024-12-06 09:27:40 +01:00
etc Auto merge of #133134 - Walnut356:synth_prov, r=Mark-Simulacrum 2024-12-08 19:30:33 +00:00
gcc@fd3498bff0 Update GCC version 2024-09-06 16:01:46 +02:00
librustdoc Auto merge of #134185 - compiler-errors:impl-trait-in-bindings, r=oli-obk 2024-12-14 10:22:43 +00:00
llvm-project@1268e87bdb Update LLVM to 19.1.5 2024-12-03 21:12:47 +08:00
rustc-std-workspace update rustc-std-workspace crates 2024-11-04 07:45:15 +01:00
rustdoc-json-types rustdoc-json: Include safety of statics 2024-12-01 21:39:58 +00:00
tools Auto merge of #134185 - compiler-errors:impl-trait-in-bindings, r=oli-obk 2024-12-14 10:22:43 +00:00
README.md
stage0 bump stage0 2024-11-27 12:12:23 +00:00
version Bump to 1.85 2024-11-22 11:08:33 +00:00

This directory contains some source code for the Rust project, including:

  • The bootstrapping build system
  • Various submodules for tools, like cargo, tidy, etc.

For more information on how various parts of the compiler work, see the rustc dev guide.