add a test regarding relating closure and fn generics

Turns out this works but we had no test targeting it.
This commit is contained in:
Niko Matsakis 2017-12-06 04:56:03 -05:00
parent e9824c50ed
commit a118afe7ca
2 changed files with 119 additions and 0 deletions

View File

@ -0,0 +1,59 @@
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT
// file at the top-level directory of this distribution and at
// http://rust-lang.org/COPYRIGHT.
//
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
// option. This file may not be copied, modified, or distributed
// except according to those terms.
// Test that regions which appear only in the closure's generics (in
// this case, `'a`) are properly mapped to the creator's generics. In
// this case, the closure constrains its type parameter `T` to outlive
// the same `'a` for which it implements `Trait`, which can only be the `'a`
// from the function definition.
// compile-flags:-Znll -Zborrowck=mir -Zverbose
#![feature(rustc_attrs)]
#![allow(dead_code)]
trait Trait<'a> {}
fn establish_relationships<T, F>(value: T, closure: F)
where
F: FnOnce(T),
{
closure(value)
}
fn require<'a, T>(t: T)
where
T: Trait<'a> + 'a,
{
}
#[rustc_regions]
fn supply<'a, T>(value: T)
where
T: Trait<'a>,
{
establish_relationships(value, |value| {
// This function call requires that
//
// (a) T: Trait<'a>
//
// and
//
// (b) T: 'a
//
// The latter does not hold.
require(value);
//~^ WARNING not reporting region error due to -Znll
//~| ERROR failed type test
});
}
fn main() {}

View File

@ -0,0 +1,60 @@
warning: not reporting region error due to -Znll
--> $DIR/propagate-from-trait-match.rs:53:9
|
53 | require(value);
| ^^^^^^^
note: External requirements
--> $DIR/propagate-from-trait-match.rs:42:36
|
42 | establish_relationships(value, |value| {
| ____________________________________^
43 | | // This function call requires that
44 | | //
45 | | // (a) T: Trait<'a>
... |
55 | | //~| ERROR failed type test
56 | | });
| |_____^
|
= note: defining type: DefId(0/1:16 ~ propagate_from_trait_match[317d]::supply[0]::{{closure}}[0]) with closure substs [
'_#1r,
T,
i32,
extern "rust-call" fn((T,))
]
= note: number of external vids: 2
= note: where T: '_#1r
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]) }
--> $DIR/propagate-from-trait-match.rs:42:36
|
42 | establish_relationships(value, |value| {
| ____________________________________^
43 | | // This function call requires that
44 | | //
45 | | // (a) T: Trait<'a>
... |
55 | | //~| ERROR failed type test
56 | | });
| |_____^
note: No external requirements
--> $DIR/propagate-from-trait-match.rs:38:1
|
38 | / fn supply<'a, T>(value: T)
39 | | where
40 | | T: Trait<'a>,
41 | | {
... |
56 | | });
57 | | }
| |_^
|
= note: defining type: DefId(0/0:6 ~ propagate_from_trait_match[317d]::supply[0]) with substs [
'_#1r,
T
]
error: aborting due to previous error