Skip to content

Commit a118afe

Browse files
committed
add a test regarding relating closure and fn generics
Turns out this works but we had no test targeting it.
1 parent e9824c5 commit a118afe

File tree

2 files changed

+119
-0
lines changed

2 files changed

+119
-0
lines changed
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// Test that regions which appear only in the closure's generics (in
12+
// this case, `'a`) are properly mapped to the creator's generics. In
13+
// this case, the closure constrains its type parameter `T` to outlive
14+
// the same `'a` for which it implements `Trait`, which can only be the `'a`
15+
// from the function definition.
16+
17+
// compile-flags:-Znll -Zborrowck=mir -Zverbose
18+
19+
#![feature(rustc_attrs)]
20+
#![allow(dead_code)]
21+
22+
trait Trait<'a> {}
23+
24+
fn establish_relationships<T, F>(value: T, closure: F)
25+
where
26+
F: FnOnce(T),
27+
{
28+
closure(value)
29+
}
30+
31+
fn require<'a, T>(t: T)
32+
where
33+
T: Trait<'a> + 'a,
34+
{
35+
}
36+
37+
#[rustc_regions]
38+
fn supply<'a, T>(value: T)
39+
where
40+
T: Trait<'a>,
41+
{
42+
establish_relationships(value, |value| {
43+
// This function call requires that
44+
//
45+
// (a) T: Trait<'a>
46+
//
47+
// and
48+
//
49+
// (b) T: 'a
50+
//
51+
// The latter does not hold.
52+
53+
require(value);
54+
//~^ WARNING not reporting region error due to -Znll
55+
//~| ERROR failed type test
56+
});
57+
}
58+
59+
fn main() {}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
warning: not reporting region error due to -Znll
2+
--> $DIR/propagate-from-trait-match.rs:53:9
3+
|
4+
53 | require(value);
5+
| ^^^^^^^
6+
7+
note: External requirements
8+
--> $DIR/propagate-from-trait-match.rs:42:36
9+
|
10+
42 | establish_relationships(value, |value| {
11+
| ____________________________________^
12+
43 | | // This function call requires that
13+
44 | | //
14+
45 | | // (a) T: Trait<'a>
15+
... |
16+
55 | | //~| ERROR failed type test
17+
56 | | });
18+
| |_____^
19+
|
20+
= note: defining type: DefId(0/1:16 ~ propagate_from_trait_match[317d]::supply[0]::{{closure}}[0]) with closure substs [
21+
'_#1r,
22+
T,
23+
i32,
24+
extern "rust-call" fn((T,))
25+
]
26+
= note: number of external vids: 2
27+
= note: where T: '_#1r
28+
29+
error: failed type test: TypeTest { generic_kind: T/#1, lower_bound: '_#3r, point: bb0[3], span: $DIR/propagate-from-trait-match.rs:42:36: 56:6, test: IsOutlivedByAnyRegionIn(['_#2r]) }
30+
--> $DIR/propagate-from-trait-match.rs:42:36
31+
|
32+
42 | establish_relationships(value, |value| {
33+
| ____________________________________^
34+
43 | | // This function call requires that
35+
44 | | //
36+
45 | | // (a) T: Trait<'a>
37+
... |
38+
55 | | //~| ERROR failed type test
39+
56 | | });
40+
| |_____^
41+
42+
note: No external requirements
43+
--> $DIR/propagate-from-trait-match.rs:38:1
44+
|
45+
38 | / fn supply<'a, T>(value: T)
46+
39 | | where
47+
40 | | T: Trait<'a>,
48+
41 | | {
49+
... |
50+
56 | | });
51+
57 | | }
52+
| |_^
53+
|
54+
= note: defining type: DefId(0/0:6 ~ propagate_from_trait_match[317d]::supply[0]) with substs [
55+
'_#1r,
56+
T
57+
]
58+
59+
error: aborting due to previous error
60+

0 commit comments

Comments
 (0)