Skip to content

Commit e568cb4

Browse files
authored
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``
2 parents 8818b00 + e087871 commit e568cb4

File tree

3 files changed

+26
-2
lines changed

3 files changed

+26
-2
lines changed

compiler/rustc_typeck/src/check/wfcheck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,7 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, associated_items: &[hir::TraitItemRe
387387
tcx,
388388
param_env,
389389
item_hir_id,
390-
sig.output(),
390+
sig.inputs_and_output,
391391
// We also assume that all of the function signature's parameter types
392392
// are well formed.
393393
&sig.inputs().iter().copied().collect(),

src/test/ui/generic-associated-types/self-outlives-lint.rs

+13
Original file line numberDiff line numberDiff line change
@@ -210,4 +210,17 @@ trait StaticReturnAndTakes<'a> {
210210
fn bar<'b>(&self, arg: Self::Y<'b>);
211211
}
212212

213+
// We require bounds when the GAT appears in the inputs
214+
trait Input {
215+
type Item<'a>;
216+
//~^ missing required
217+
fn takes_item<'a>(&'a self, item: Self::Item<'a>);
218+
}
219+
220+
// We don't require bounds when the GAT appears in the where clauses
221+
trait WhereClause {
222+
type Item<'a>;
223+
fn takes_item<'a>(&'a self) where Self::Item<'a>: ;
224+
}
225+
213226
fn main() {}

src/test/ui/generic-associated-types/self-outlives-lint.stderr

+12-1
Original file line numberDiff line numberDiff line change
@@ -163,5 +163,16 @@ LL | type Fut<'out>;
163163
= note: this bound is currently required to ensure that impls have maximum flexibility
164164
= note: we are soliciting feedback, see issue #87479 <https://github.com/rust-lang/rust/issues/87479> for more information
165165

166-
error: aborting due to 15 previous errors
166+
error: missing required bound on `Item`
167+
--> $DIR/self-outlives-lint.rs:215:5
168+
|
169+
LL | type Item<'a>;
170+
| ^^^^^^^^^^^^^-
171+
| |
172+
| help: add the required where clause: `where Self: 'a`
173+
|
174+
= note: this bound is currently required to ensure that impls have maximum flexibility
175+
= note: we are soliciting feedback, see issue #87479 <https://github.com/rust-lang/rust/issues/87479> for more information
176+
177+
error: aborting due to 16 previous errors
167178

0 commit comments

Comments
 (0)