diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2021-12-13 18:15:16 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-12-13 18:15:16 +0100 |
| commit | 84878336b05f1dcdff6f2a55b6b66d5fa6f2e82e (patch) | |
| tree | 922205b28a71aaf72812e55e06c181001d88d113 /src | |
| parent | f8de2f56e8628ec830d2bfd77a30f681f27bb46a (diff) | |
| parent | 48974158f1ce88dca7edd66c7bae81e759c2679d (diff) | |
| download | rust-84878336b05f1dcdff6f2a55b6b66d5fa6f2e82e.tar.gz rust-84878336b05f1dcdff6f2a55b6b66d5fa6f2e82e.zip | |
Rollup merge of #91849 - jackh726:gats-outlives-lint-part2, r=nikomatsakis
GATs outlives lint: Try to prove bounds Fixes #91036 Fixes #90888 Fixes #91348 (better error + documentation to be added to linked issue) Instead of checking for bounds directly, try to prove them in the associated type environment. Also, add a bit of extra information to the error, including a link to the relevant discussion issue (#87479). That should be edited to include a brief summary of the current state of the outlives lint, including a brief background. It also might or might not be worth it to bump this to a full error code at some point. r? ``@nikomatsakis``
Diffstat (limited to 'src')
4 files changed, 109 insertions, 40 deletions
diff --git a/src/test/ui/generic-associated-types/issue-86787.rs b/src/test/ui/generic-associated-types/issue-86787.rs index 0f62f83e256..5863bac2f9d 100644 --- a/src/test/ui/generic-associated-types/issue-86787.rs +++ b/src/test/ui/generic-associated-types/issue-86787.rs @@ -9,7 +9,7 @@ enum Either<L, R> { pub trait HasChildrenOf { type T; type TRef<'a>; - //~^ Missing required bounds + //~^ missing required fn ref_children<'a>(&'a self) -> Vec<Self::TRef<'a>>; fn take_children(self) -> Vec<Self::T>; diff --git a/src/test/ui/generic-associated-types/issue-86787.stderr b/src/test/ui/generic-associated-types/issue-86787.stderr index 87dcd875de7..d4b2267d3dd 100644 --- a/src/test/ui/generic-associated-types/issue-86787.stderr +++ b/src/test/ui/generic-associated-types/issue-86787.stderr @@ -1,10 +1,13 @@ -error: Missing required bounds on TRef +error: missing required bound on `TRef` --> $DIR/issue-86787.rs:11:5 | LL | type TRef<'a>; | ^^^^^^^^^^^^^- | | - | help: add the required where clauses: `where Self: '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 previous error 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 af90d158855..37b3a6155d5 100644 --- a/src/test/ui/generic-associated-types/self-outlives-lint.rs +++ b/src/test/ui/generic-associated-types/self-outlives-lint.rs @@ -7,7 +7,7 @@ use std::fmt::Debug; // We have a `&'a self`, so we need a `Self: 'a` trait Iterable { type Item<'x>; - //~^ Missing required bounds + //~^ missing required fn iter<'a>(&'a self) -> Self::Item<'a>; } @@ -23,7 +23,7 @@ impl<T> Iterable for T { // We have a `&'a T`, so we need a `T: 'x` trait Deserializer<T> { type Out<'x>; - //~^ Missing required bounds + //~^ missing required fn deserialize<'a>(&self, input: &'a T) -> Self::Out<'a>; } @@ -37,14 +37,14 @@ impl<T> Deserializer<T> for () { // We have a `&'b T` and a `'b: 'a`, so it is implied that `T: 'a`. Therefore, we need a `T: 'x` trait Deserializer2<T> { type Out<'x>; - //~^ Missing required bounds + //~^ missing required fn deserialize2<'a, 'b: 'a>(&self, input1: &'b T) -> Self::Out<'a>; } // We have a `&'a T` and a `&'b U`, so we need a `T: 'x` and a `U: 'y` trait Deserializer3<T, U> { type Out<'x, 'y>; - //~^ Missing required bounds + //~^ missing required fn deserialize2<'a, 'b>(&self, input: &'a T, input2: &'b U) -> Self::Out<'a, 'b>; } @@ -59,7 +59,7 @@ struct Wrap<T>(T); // We pass `Wrap<T>` and we see `&'z Wrap<T>`, so we require `D: 'x` trait Des { type Out<'x, D>; - //~^ Missing required bounds + //~^ missing required fn des<'z, T>(&self, data: &'z Wrap<T>) -> Self::Out<'z, Wrap<T>>; } /* @@ -75,7 +75,7 @@ impl Des for () { // implied bound that `T: 'z`, so we require `D: 'x` trait Des2 { type Out<'x, D>; - //~^ Missing required bounds + //~^ missing required fn des<'z, T>(&self, data: &'z Wrap<T>) -> Self::Out<'z, T>; } /* @@ -90,7 +90,7 @@ impl Des2 for () { // We see `&'z T`, so we require `D: 'x` trait Des3 { type Out<'x, D>; - //~^ Missing required bounds + //~^ missing required fn des<'z, T>(&self, data: &'z T) -> Self::Out<'z, T>; } /* @@ -112,7 +112,7 @@ trait NoGat<'a> { // FIXME: we require two bounds (`where Self: 'a, Self: 'b`) when we should only require one trait TraitLifetime<'a> { type Bar<'b>; - //~^ Missing required bounds + //~^ missing required fn method(&'a self) -> Self::Bar<'a>; } @@ -120,14 +120,14 @@ trait TraitLifetime<'a> { // FIXME: we require two bounds (`where Self: 'a, Self: 'b`) when we should only require one trait TraitLifetimeWhere<'a> where Self: 'a { type Bar<'b>; - //~^ Missing required bounds + //~^ missing required fn method(&'a self) -> Self::Bar<'a>; } // Explicit bound instead of implicit; we want to still error trait ExplicitBound { type Bar<'b>; - //~^ Missing required bounds + //~^ missing required fn method<'b>(&self, token: &'b ()) -> Self::Bar<'b> where Self: 'b; } @@ -141,14 +141,15 @@ trait NotInReturn { trait IterableTwo { type Item<'a>; type Iterator<'a>: Iterator<Item = Self::Item<'a>>; - //~^ Missing required bounds + //~^ missing required fn iter<'a>(&'a self) -> Self::Iterator<'a>; } -// We also should report region outlives clauses +// We also should report region outlives clauses. Here, we know that `'y: 'x`, +// because of `&'x &'y`, so we require that `'b: 'a`. trait RegionOutlives { type Bar<'a, 'b>; - //~^ Missing required bounds + //~^ missing required fn foo<'x, 'y>(&self, input: &'x &'y ()) -> Self::Bar<'x, 'y>; } @@ -161,6 +162,17 @@ impl Foo for () { } */ +// Similar to the above, except with explicit bounds +trait ExplicitRegionOutlives<'ctx> { + type Fut<'out>; + //~^ missing required + + fn test<'out>(ctx: &'ctx i32) -> Self::Fut<'out> + where + 'ctx: 'out; +} + + // If there are multiple methods that return the GAT, require a set of clauses // that can be satisfied by *all* methods trait MultipleMethods { @@ -170,4 +182,11 @@ trait MultipleMethods { fn gimme_default(&self) -> Self::Bar<'static>; } +// We would normally require `Self: 'a`, but we can prove that `Self: 'static` +// because of the the bounds on the trait, so the bound is proven +trait Trait: 'static { + type Assoc<'a>; + fn make_assoc(_: &u32) -> Self::Assoc<'_>; +} + 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 bf85780f69f..3b9146ad875 100644 --- a/src/test/ui/generic-associated-types/self-outlives-lint.stderr +++ b/src/test/ui/generic-associated-types/self-outlives-lint.stderr @@ -1,98 +1,145 @@ -error: Missing required bounds on Item +error: missing required bound on `Item` --> $DIR/self-outlives-lint.rs:9:5 | LL | type Item<'x>; | ^^^^^^^^^^^^^- | | - | help: add the required where clauses: `where Self: 'x` + | help: add the required where clause: `where Self: 'x` + | + = 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: Missing required bounds on Out +error: missing required bound on `Out` --> $DIR/self-outlives-lint.rs:25:5 | LL | type Out<'x>; | ^^^^^^^^^^^^- | | - | help: add the required where clauses: `where T: 'x` + | help: add the required where clause: `where T: 'x` + | + = 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: Missing required bounds on Out +error: missing required bound on `Out` --> $DIR/self-outlives-lint.rs:39:5 | LL | type Out<'x>; | ^^^^^^^^^^^^- | | - | help: add the required where clauses: `where T: 'x` + | help: add the required where clause: `where T: 'x` + | + = 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: Missing required bounds on Out +error: missing required bounds on `Out` --> $DIR/self-outlives-lint.rs:46:5 | LL | type Out<'x, 'y>; | ^^^^^^^^^^^^^^^^- | | | help: add the required where clauses: `where T: 'x, U: 'y` + | + = note: these bounds are 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: Missing required bounds on Out +error: missing required bound on `Out` --> $DIR/self-outlives-lint.rs:61:5 | LL | type Out<'x, D>; | ^^^^^^^^^^^^^^^- | | - | help: add the required where clauses: `where D: 'x` + | help: add the required where clause: `where D: 'x` + | + = 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: Missing required bounds on Out +error: missing required bound on `Out` --> $DIR/self-outlives-lint.rs:77:5 | LL | type Out<'x, D>; | ^^^^^^^^^^^^^^^- | | - | help: add the required where clauses: `where D: 'x` + | help: add the required where clause: `where D: 'x` + | + = 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: Missing required bounds on Out +error: missing required bound on `Out` --> $DIR/self-outlives-lint.rs:92:5 | LL | type Out<'x, D>; | ^^^^^^^^^^^^^^^- | | - | help: add the required where clauses: `where D: 'x` + | help: add the required where clause: `where D: 'x` + | + = 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: Missing required bounds on Bar +error: missing required bounds on `Bar` --> $DIR/self-outlives-lint.rs:114:5 | LL | type Bar<'b>; | ^^^^^^^^^^^^- | | | help: add the required where clauses: `where Self: 'a, Self: 'b` + | + = note: these bounds are 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: Missing required bounds on Bar +error: missing required bound on `Bar` --> $DIR/self-outlives-lint.rs:122:5 | LL | type Bar<'b>; | ^^^^^^^^^^^^- | | - | help: add the required where clauses: `where Self: 'a, Self: 'b` + | help: add the required where clause: `where Self: 'b` + | + = 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: Missing required bounds on Bar +error: missing required bound on `Bar` --> $DIR/self-outlives-lint.rs:129:5 | LL | type Bar<'b>; | ^^^^^^^^^^^^- | | - | help: add the required where clauses: `where Self: 'b` + | help: add the required where clause: `where Self: 'b` + | + = 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: Missing required bounds on Iterator +error: missing required bound on `Iterator` --> $DIR/self-outlives-lint.rs:143:5 | LL | type Iterator<'a>: Iterator<Item = Self::Item<'a>>; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^- | | - | help: add the required where clauses: `where Self: '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: Missing required bounds on Bar - --> $DIR/self-outlives-lint.rs:150:5 +error: missing required bound on `Bar` + --> $DIR/self-outlives-lint.rs:151:5 | LL | type Bar<'a, 'b>; | ^^^^^^^^^^^^^^^^- | | - | help: add the required where clauses: `where 'a: 'b` + | help: add the required where clause: `where 'b: '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: missing required bound on `Fut` + --> $DIR/self-outlives-lint.rs:167:5 + | +LL | type Fut<'out>; + | ^^^^^^^^^^^^^^- + | | + | help: add the required where clause: `where 'ctx: '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 12 previous errors +error: aborting due to 13 previous errors |
