rust/src/test
bors 9d39f6ab7d Auto merge of #89970 - jackh726:gats_diagnostics, r=nikomatsakis
Implementation of GATs outlives lint

See #87479 for background. Closes #87479

The basic premise of this lint/error is to require the user to write where clauses on a GAT when those bounds can be implied or proven from any function on the trait returning that GAT.

## Intuitive Explanation (Attempt) ##
Let's take this trait definition as an example:
```rust
trait Iterable {
    type Item<'x>;
    fn iter<'a>(&'a self) -> Self::Item<'a>;
}
```
Let's focus on the `iter` function. The first thing to realize is that we know that `Self: 'a` because of `&'a self`. If an impl wants `Self::Item` to contain any data with references, then those references must be derived from `&'a self`. Thus, they must live only as long as `'a`. Furthermore, because of the `Self: 'a` implied bound, they must live only as long as `Self`. Since it's `'a` is used in place of `'x`, it is reasonable to assume that any value of `Self::Item<'x>`, and thus `'x`, will only be able to live as long as `Self`. Therefore, we require this bound on `Item` in the trait.

As another example:
```rust
trait Deserializer<T> {
    type Out<'x>;
    fn deserialize<'a>(&self, input: &'a T) -> Self::Out<'a>;
}
```
The intuition is similar here, except rather than a `Self: 'a` implied bound, we have a `T: 'a` implied bound. Thus, the data on `Self::Out<'a>` is derived from `&'a T`, and thus it is reasonable to expect that the lifetime `'x` will always be less than `T`.

## Implementation Algorithm ##
* Given a GAT `<P0 as Trait<P1..Pi>>::G<Pi...Pn>` declared as `trait T<A1..Ai> for A0 { type G<Ai...An>; }` used in return type of one associated function `F`
* Given env `E` (including implied bounds) for `F`
* For each lifetime parameter `'a` in `P0...Pn`:
    * For each other type parameter `Pi != 'a` in `P0...Pn`: // FIXME: this include of lifetime parameters too
        * If `E => (P: 'a)`:
            * Require where clause `Ai: 'a`

## Follow-up questions ##
* What should we do when we don't pass params exactly?
For this example:
```rust
trait Des {
    type Out<'x, D>;
    fn des<'z, T>(&self, data: &'z Wrap<T>) -> Self::Out<'z, Wrap<T>>;
}
```
Should we be requiring a `D: 'x` clause? We pass `Wrap<T>` as `D` and `'z` as `'x`, and should be able to prove that `Wrap<T>: 'z`.

r? `@nikomatsakis`
2021-11-06 04:15:22 +00:00
..
assembly Update the minimum external LLVM to 12 2021-10-22 10:50:07 -07:00
auxiliary
codegen Auto merge of #89652 - rcvalle:rust-cfi, r=nagisa 2021-10-27 09:19:42 +00:00
codegen-units Collect panic/panic_bounds_check during monomorphization 2021-10-30 18:21:44 +01:00
debuginfo Fix function-names test for GDB 10.1 2021-10-11 17:20:45 +02:00
incremental Rollup merge of #89895 - camsteffen:for-loop-head-span, r=davidtwco 2021-10-22 19:42:45 +09:00
mir-opt Ignore wasm32 in test. 2021-10-17 16:35:04 +02:00
pretty Use ZST for fmt unsafety 2021-09-21 10:04:44 -05:00
run-make Move rustdoc-scrape-examples-macros test to run-make-fulldeps 2021-11-04 18:52:59 -07:00
run-make-fulldeps Fix rustdoc-scrape-examples-macros test not being cross-platform 2021-11-05 09:32:04 -07:00
run-pass-valgrind
rustdoc Split doc_cfg and doc_auto_cfg features 2021-11-02 16:55:50 +01:00
rustdoc-gui Fix missing bottom border for headings in sidebar 2021-11-04 20:07:24 +01:00
rustdoc-js Fix invalid handling of generics 2021-10-29 20:54:15 +02:00
rustdoc-js-std Fix linkcheck issues 2021-09-12 02:30:24 +00:00
rustdoc-json Add regression test for #89852 2021-10-14 02:12:18 +02:00
rustdoc-ui Rollup merge of #90183 - GuillaumeGomez:recurse-deref, r=jyn514 2021-10-30 20:30:26 +02:00
ui Auto merge of #89970 - jackh726:gats_diagnostics, r=nikomatsakis 2021-11-06 04:15:22 +00:00
ui-fulldeps Revert "Add rustc lint, warning when iterating over hashmaps" 2021-10-28 11:01:42 -04:00
COMPILER_TESTS.md