remove old error and add an explanation

This commit is contained in:
Niko Matsakis 2019-06-10 17:17:56 -04:00
parent ec48b4ebe2
commit cc581bfa0e
2 changed files with 13 additions and 49 deletions

View File

@ -1,10 +1,22 @@
// run-pass
use std::fmt::Debug;
trait MultiRegionTrait<'a, 'b> {}
impl<'a, 'b> MultiRegionTrait<'a, 'b> for (&'a u32, &'b u32) {}
fn no_least_region<'a, 'b>(x: &'a u32, y: &'b u32) -> impl MultiRegionTrait<'a, 'b> {
//~^ ERROR ambiguous lifetime bound
// Here we have a constraint that:
//
// (x, y) has type (&'0 u32, &'1 u32)
//
// where
//
// 'a: '0
//
// then we require that `('0 u32, &'1 u32): MultiRegionTrait<'a,
// 'b>`, which winds up imposing a requirement that `'0 = 'a` and
// `'1 = 'b`.
(x, y)
}

View File

@ -1,48 +0,0 @@
error: impl Trait captures unexpected lifetime
--> $DIR/needs_least_region_or_bound.rs:6:55
|
LL | fn no_least_region<'a, 'b>(x: &'a u32, y: &'b u32) -> impl MultiRegionTrait<'a, 'b> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ only lifetimes that appear in the impl Trait bounds may be captured
|
note: hidden type captures the lifetime 'a as defined on the function body at 6:20
--> $DIR/needs_least_region_or_bound.rs:6:20
|
LL | fn no_least_region<'a, 'b>(x: &'a u32, y: &'b u32) -> impl MultiRegionTrait<'a, 'b> {
| ^^
note: hidden type would be allowed to capture the lifetime 'a as defined on the function body at 6:20
--> $DIR/needs_least_region_or_bound.rs:6:20
|
LL | fn no_least_region<'a, 'b>(x: &'a u32, y: &'b u32) -> impl MultiRegionTrait<'a, 'b> {
| ^^
note: hidden type would be allowed to capture the lifetime 'b as defined on the function body at 6:24
--> $DIR/needs_least_region_or_bound.rs:6:24
|
LL | fn no_least_region<'a, 'b>(x: &'a u32, y: &'b u32) -> impl MultiRegionTrait<'a, 'b> {
| ^^
= note: hidden type would be allowed to capture the static lifetime
error: impl Trait captures unexpected lifetime
--> $DIR/needs_least_region_or_bound.rs:6:55
|
LL | fn no_least_region<'a, 'b>(x: &'a u32, y: &'b u32) -> impl MultiRegionTrait<'a, 'b> {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ only lifetimes that appear in the impl Trait bounds may be captured
|
note: hidden type captures the lifetime 'b as defined on the function body at 6:24
--> $DIR/needs_least_region_or_bound.rs:6:24
|
LL | fn no_least_region<'a, 'b>(x: &'a u32, y: &'b u32) -> impl MultiRegionTrait<'a, 'b> {
| ^^
note: hidden type would be allowed to capture the lifetime 'a as defined on the function body at 6:20
--> $DIR/needs_least_region_or_bound.rs:6:20
|
LL | fn no_least_region<'a, 'b>(x: &'a u32, y: &'b u32) -> impl MultiRegionTrait<'a, 'b> {
| ^^
note: hidden type would be allowed to capture the lifetime 'b as defined on the function body at 6:24
--> $DIR/needs_least_region_or_bound.rs:6:24
|
LL | fn no_least_region<'a, 'b>(x: &'a u32, y: &'b u32) -> impl MultiRegionTrait<'a, 'b> {
| ^^
= note: hidden type would be allowed to capture the static lifetime
error: aborting due to 2 previous errors