Skip to content

Commit 2a17b93

Browse files
committed
test more failure cases for approximating the "longer" side
as suggested by arielb1
1 parent ca60826 commit 2a17b93

5 files changed

+157
-48
lines changed

src/test/ui/nll/closure-requirements/propagate-approximated-to-empty.stderr

Lines changed: 0 additions & 46 deletions
This file was deleted.

src/test/ui/nll/closure-requirements/propagate-approximated-to-empty.rs renamed to src/test/ui/nll/closure-requirements/propagate-fail-to-approximate-longer-no-bounds.rs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,14 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// Test a case where we fail to approximate one of the regions and
12-
// hence report an error while checking the closure.
11+
// Similarly to escape-argument-callee, a test case where the closure
12+
// requires a relationship between 2 unrelated higher-ranked regions,
13+
// with no helpful relations between the HRRs and free regions.
14+
//
15+
// In this case, the error is reported by the closure itself. This is
16+
// because it is unable to approximate the higher-ranked region `'x`,
17+
// as it knows of no relationships between `'x` and any
18+
// non-higher-ranked regions.
1319

1420
// compile-flags:-Znll -Zborrowck=mir -Zverbose
1521

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
warning: not reporting region error due to -Znll
2+
--> $DIR/propagate-fail-to-approximate-longer-no-bounds.rs:47:9
3+
|
4+
47 | demand_y(x, y, x.get())
5+
| ^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: free region `'_#6r` does not outlive free region `'_#4r`
8+
--> $DIR/propagate-fail-to-approximate-longer-no-bounds.rs:47:21
9+
|
10+
47 | demand_y(x, y, x.get())
11+
| ^
12+
13+
note: External requirements
14+
--> $DIR/propagate-fail-to-approximate-longer-no-bounds.rs:45:47
15+
|
16+
45 | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
17+
| _______________________________________________^
18+
46 | | // Only works if 'x: 'y:
19+
47 | | demand_y(x, y, x.get())
20+
48 | | //~^ WARN not reporting region error due to -Znll
21+
49 | | //~| ERROR free region `'_#6r` does not outlive free region `'_#4r`
22+
50 | | });
23+
| |_____^
24+
|
25+
= note: defining type: DefId(0/1:18 ~ propagate_fail_to_approximate_longer_no_bounds[317d]::supply[0]::{{closure}}[0]) with closure substs [
26+
i16,
27+
for<'r, 's, 't0, 't1, 't2> extern "rust-call" fn((&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 'r)) std::cell::Cell<&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 's)) &'_#1r u32>, &ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't0)) std::cell::Cell<&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't1)) u32>, &ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't2)) std::cell::Cell<&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 's)) u32>))
28+
]
29+
= note: number of external vids: 2
30+
31+
note: No external requirements
32+
--> $DIR/propagate-fail-to-approximate-longer-no-bounds.rs:44:1
33+
|
34+
44 | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
35+
45 | | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
36+
46 | | // Only works if 'x: 'y:
37+
47 | | demand_y(x, y, x.get())
38+
... |
39+
50 | | });
40+
51 | | }
41+
| |_^
42+
|
43+
= note: defining type: DefId(0/0:6 ~ propagate_fail_to_approximate_longer_no_bounds[317d]::supply[0]) with substs []
44+
45+
error: aborting due to previous error
46+
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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+
// Similarly to escape-argument-callee, a test case where the closure
12+
// requires a relationship between 2 unrelated higher-ranked regions,
13+
// with no helpful relations between the HRRs and free regions.
14+
//
15+
// In this case, the error is reported by the closure itself. This is
16+
// because it is unable to approximate the higher-ranked region `'x`,
17+
// as it only knows of regions that `'x` is outlived by, and none that
18+
// `'x` outlives.
19+
20+
// compile-flags:-Znll -Zborrowck=mir -Zverbose
21+
22+
#![feature(rustc_attrs)]
23+
24+
use std::cell::Cell;
25+
26+
// Callee knows that:
27+
//
28+
// 'a: 'x
29+
// 'b: 'y
30+
//
31+
// but this doesn't really help us in proving that `'x: 'y`, so
32+
// closure gets an error. In particular, we would need to know that
33+
// `'x: 'a`, so that we could approximate `'x` "downwards" to `'a`.
34+
fn establish_relationships<'a, 'b, F>(_cell_a: &Cell<&'a u32>, _cell_b: &Cell<&'b u32>, _closure: F)
35+
where
36+
F: for<'x, 'y> FnMut(
37+
&Cell<&'x &'a u32>, // shows that 'a: 'x
38+
&Cell<&'y &'b u32>, // shows that 'b: 'y
39+
&Cell<&'x u32>,
40+
&Cell<&'y u32>,
41+
),
42+
{
43+
}
44+
45+
fn demand_y<'x, 'y>(_cell_x: &Cell<&'x u32>, _cell_y: &Cell<&'y u32>, _y: &'y u32) {}
46+
47+
#[rustc_regions]
48+
fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
49+
establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
50+
// Only works if 'x: 'y:
51+
demand_y(x, y, x.get())
52+
//~^ WARN not reporting region error due to -Znll
53+
//~| ERROR free region `'_#5r` does not outlive free region `'_#7r`
54+
});
55+
}
56+
57+
fn main() {}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
warning: not reporting region error due to -Znll
2+
--> $DIR/propagate-fail-to-approximate-longer-wrong-bounds.rs:51:9
3+
|
4+
51 | demand_y(x, y, x.get())
5+
| ^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: free region `'_#5r` does not outlive free region `'_#7r`
8+
--> $DIR/propagate-fail-to-approximate-longer-wrong-bounds.rs:51:21
9+
|
10+
51 | demand_y(x, y, x.get())
11+
| ^
12+
13+
note: External requirements
14+
--> $DIR/propagate-fail-to-approximate-longer-wrong-bounds.rs:49:47
15+
|
16+
49 | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
17+
| _______________________________________________^
18+
50 | | // Only works if 'x: 'y:
19+
51 | | demand_y(x, y, x.get())
20+
52 | | //~^ WARN not reporting region error due to -Znll
21+
53 | | //~| ERROR free region `'_#5r` does not outlive free region `'_#7r`
22+
54 | | });
23+
| |_____^
24+
|
25+
= note: defining type: DefId(0/1:18 ~ propagate_fail_to_approximate_longer_wrong_bounds[317d]::supply[0]::{{closure}}[0]) with closure substs [
26+
i16,
27+
for<'r, 's, 't0, 't1, 't2, 't3> extern "rust-call" fn((&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 'r)) std::cell::Cell<&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 's)) &'_#1r u32>, &ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't0)) std::cell::Cell<&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't1)) &'_#2r u32>, &ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't2)) std::cell::Cell<&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 's)) u32>, &ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't3)) std::cell::Cell<&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't1)) u32>))
28+
]
29+
= note: number of external vids: 3
30+
31+
note: No external requirements
32+
--> $DIR/propagate-fail-to-approximate-longer-wrong-bounds.rs:48:1
33+
|
34+
48 | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
35+
49 | | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
36+
50 | | // Only works if 'x: 'y:
37+
51 | | demand_y(x, y, x.get())
38+
... |
39+
54 | | });
40+
55 | | }
41+
| |_^
42+
|
43+
= note: defining type: DefId(0/0:6 ~ propagate_fail_to_approximate_longer_wrong_bounds[317d]::supply[0]) with substs []
44+
45+
error: aborting due to previous error
46+

0 commit comments

Comments
 (0)