Skip to content

Commit 248adc9

Browse files
committed
Update impl trait tests and add failing run-pass region test
1 parent 42351b4 commit 248adc9

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

src/test/compile-fail/impl-trait/lifetimes.rs

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,28 +13,20 @@
1313
// Helper creating a fake borrow, captured by the impl Trait.
1414
fn borrow<'a, T>(_: &'a mut T) -> impl Copy { () }
1515

16-
fn stack() -> impl Copy {
17-
//~^ ERROR only named lifetimes are allowed in `impl Trait`
18-
let x = 0;
19-
&x
20-
}
21-
2216
fn late_bound(x: &i32) -> impl Copy {
23-
//~^ ERROR only named lifetimes are allowed in `impl Trait`
2417
x
18+
//~^ cannot infer an appropriate lifetime
2519
}
2620

27-
// FIXME(#34511) Should work but doesn't at the moment,
28-
// region-checking needs an overhault to support this.
2921
fn early_bound<'a>(x: &'a i32) -> impl Copy {
30-
//~^ ERROR only named lifetimes are allowed in `impl Trait`
3122
x
23+
//~^ cannot infer an appropriate lifetime
3224
}
3325

3426
fn ambiguous<'a, 'b>(x: &'a [u32], y: &'b [u32]) -> impl Iterator<Item=u32> {
35-
//~^ ERROR only named lifetimes are allowed in `impl Trait`
3627
if x.len() < y.len() {
3728
x.iter().cloned()
29+
//~^ cannot infer an appropriate lifetime
3830
} else {
3931
y.iter().cloned()
4032
}

src/test/compile-fail/impl-trait/more_lifetimes.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,20 @@
1212

1313
use std::fmt::Debug;
1414

15-
fn foo<'a>(x: &'a i32) -> impl Debug + 'a {
16-
x
17-
}
18-
19-
fn foo_not_static() -> impl Debug + 'static {
20-
let mut x = 5;
21-
x += 5;
22-
foo(&x)
23-
//~^ ERROR `x` does not live long enough
24-
}
25-
2615
trait Any {}
2716
impl<T> Any for T {}
2817

2918
// Check that type parameters are captured and not considered 'static
3019
fn whatever<T>(x: T) -> impl Any + 'static {
31-
x
3220
//~^ ERROR the parameter type `T` may not live long enough
21+
x
3322
}
3423

3524
fn move_lifetime_into_fn<'a, 'b>(x: &'a u32, y: &'b u32) -> impl Fn(&'a u32) {
25+
//~^ ERROR lifetime mismatch
26+
//~^^ ERROR only named lifetimes are allowed in `impl Trait`, but `'b` was found
27+
//~^^^ ERROR only named lifetimes are allowed in `impl Trait`, but `'b` was found
28+
// TODO^ remove the above duplicate errors
3629
move |_| println!("{}", y)
3730
}
3831

src/test/run-pass/impl-trait/lifetimes.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
// except according to those terms.
1010

1111
#![feature(conservative_impl_trait)]
12+
#![allow(warnings)]
1213

1314
use std::fmt::Debug;
1415

@@ -35,4 +36,18 @@ fn mixed_lifetimes<'a>() -> impl for<'b: 'a> Fn(&'b u32) { |_| () }
3536

3637
fn mixed_as_static() -> impl Fn(&'static u32) { mixed_lifetimes() }
3738

39+
trait MultiRegion<'a, 'b> {}
40+
struct MultiRegionStruct<'a, 'b>(&'a u32, &'b u32);
41+
impl<'a, 'b> MultiRegion<'a, 'b> for MultiRegionStruct<'a, 'b> {}
42+
43+
fn finds_least_region<'a: 'b, 'b>(x: &'a u32, y: &'b u32) -> impl MultiRegion<'a, 'b>
44+
{
45+
MultiRegionStruct(x, y)
46+
}
47+
48+
fn explicit_bound<'a: 'b, 'b>(x: &'a u32, y: &'b u32) -> impl MultiRegion<'a, 'b> + 'b
49+
{
50+
MultiRegionStruct(x, y)
51+
}
52+
3853
fn main() {}

0 commit comments

Comments
 (0)