diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2022-08-23 06:55:23 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-08-23 06:55:23 +0200 |
| commit | e568cb45fefd580cb22f3ae0ed45f8598ba7cda1 (patch) | |
| tree | f881e39272d65e2f54b48ed9f58329e6a12d9818 | |
| parent | 8818b00b634ee48e7617d9beb48c4d7bc6967f06 (diff) | |
| parent | e087871915a46943db670b3e16bd12f25a1d11a2 (diff) | |
| download | rust-e568cb45fefd580cb22f3ae0ed45f8598ba7cda1.tar.gz rust-e568cb45fefd580cb22f3ae0ed45f8598ba7cda1.zip | |
Rollup merge of #100382 - jackh726:gat-self-outlives-input, r=compiler-errors
Make the GATS self outlives error take into GATs in the inputs
Before, the reasoning was that outlives should factor in to the outlives error, because that value is produced and inputs aren't. However, this is potentially confusing, and we can just require this for now and relax it later if we need. GATs in where clauses still don't count for the self outlives error, and I've added a test for that.
This now errors:
```rust
trait Input {
type Item<'a>;
//~^ missing required
fn takes_item<'a>(&'a self, item: Self::Item<'a>);
}
```
I've also added a test that this does not:
```rust
trait WhereClause {
type Item<'a>;
fn takes_item<'a>(&'a self) where Self::Item<'a>: ;
}
```
r? ``@compiler-errors``
| -rw-r--r-- | compiler/rustc_typeck/src/check/wfcheck.rs | 2 | ||||
| -rw-r--r-- | src/test/ui/generic-associated-types/self-outlives-lint.rs | 13 | ||||
| -rw-r--r-- | src/test/ui/generic-associated-types/self-outlives-lint.stderr | 13 |
3 files changed, 26 insertions, 2 deletions
diff --git a/compiler/rustc_typeck/src/check/wfcheck.rs b/compiler/rustc_typeck/src/check/wfcheck.rs index ed653f0f9c8..e8243d666b6 100644 --- a/compiler/rustc_typeck/src/check/wfcheck.rs +++ b/compiler/rustc_typeck/src/check/wfcheck.rs @@ -387,7 +387,7 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, associated_items: &[hir::TraitItemRe tcx, param_env, item_hir_id, - sig.output(), + sig.inputs_and_output, // We also assume that all of the function signature's parameter types // are well formed. &sig.inputs().iter().copied().collect(), diff --git a/src/test/ui/generic-associated-types/self-outlives-lint.rs b/src/test/ui/generic-associated-types/self-outlives-lint.rs index 300907adbfc..9bb42d4ff1c 100644 --- a/src/test/ui/generic-associated-types/self-outlives-lint.rs +++ b/src/test/ui/generic-associated-types/self-outlives-lint.rs @@ -210,4 +210,17 @@ trait StaticReturnAndTakes<'a> { fn bar<'b>(&self, arg: Self::Y<'b>); } +// We require bounds when the GAT appears in the inputs +trait Input { + type Item<'a>; + //~^ missing required + fn takes_item<'a>(&'a self, item: Self::Item<'a>); +} + +// We don't require bounds when the GAT appears in the where clauses +trait WhereClause { + type Item<'a>; + fn takes_item<'a>(&'a self) where Self::Item<'a>: ; +} + fn main() {} diff --git a/src/test/ui/generic-associated-types/self-outlives-lint.stderr b/src/test/ui/generic-associated-types/self-outlives-lint.stderr index fdb1f50a776..a43b35bd79c 100644 --- a/src/test/ui/generic-associated-types/self-outlives-lint.stderr +++ b/src/test/ui/generic-associated-types/self-outlives-lint.stderr @@ -163,5 +163,16 @@ LL | type Fut<'out>; = note: this bound is currently required to ensure that impls have maximum flexibility = note: we are soliciting feedback, see issue #87479 <https://github.com/rust-lang/rust/issues/87479> for more information -error: aborting due to 15 previous errors +error: missing required bound on `Item` + --> $DIR/self-outlives-lint.rs:215:5 + | +LL | type Item<'a>; + | ^^^^^^^^^^^^^- + | | + | help: add the required where clause: `where Self: 'a` + | + = note: this bound is currently required to ensure that impls have maximum flexibility + = note: we are soliciting feedback, see issue #87479 <https://github.com/rust-lang/rust/issues/87479> for more information + +error: aborting due to 16 previous errors |
