Skip to content

Commit ca60826

Browse files
committed
test approximations of the "shorter side" that resort to 'static
This includes the additional case suggested by arielb1.
1 parent 3c42f18 commit ca60826

4 files changed

+113
-18
lines changed

src/test/ui/nll/closure-requirements/propagate-approximated-to-static.rs renamed to src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.rs

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

11-
// Test a case where we are forced to approximate one end-point with
12-
// `'static`. Note that `'static` shows up in the stderr output as `'0`.
11+
// Test a case where we are trying to prove `'x: 'y` and are forced to
12+
// approximate the shorter end-point (`'y`) to with `'static`. This is
13+
// because `'y` is higher-ranked but we know of no relations to other
14+
// regions. Note that `'static` shows up in the stderr output as `'0`.
15+
//
16+
// FIXME(#45827) Because of shortcomings in the MIR type checker,
17+
// these errors are not (yet) reported.
1318

1419
// compile-flags:-Znll -Zborrowck=mir -Zverbose
1520

Original file line numberDiff line numberDiff line change
@@ -1,36 +1,36 @@
11
warning: not reporting region error due to -Znll
2-
--> $DIR/propagate-approximated-to-static.rs:42:9
2+
--> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:47:9
33
|
4-
42 | demand_y(x, y, x.get())
4+
47 | demand_y(x, y, x.get())
55
| ^^^^^^^^^^^^^^^^^^^^^^^
66

77
note: External requirements
8-
--> $DIR/propagate-approximated-to-static.rs:40:47
8+
--> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:45:47
99
|
10-
40 | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
10+
45 | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
1111
| _______________________________________________^
12-
41 | | // Only works if 'x: 'y:
13-
42 | | demand_y(x, y, x.get())
14-
43 | | });
12+
46 | | // Only works if 'x: 'y:
13+
47 | | demand_y(x, y, x.get())
14+
48 | | });
1515
| |_____^
1616
|
17-
= note: defining type: DefId(0/1:18 ~ propagate_approximated_to_static[317d]::supply[0]::{{closure}}[0]) with closure substs [
17+
= note: defining type: DefId(0/1:18 ~ propagate_approximated_shorter_to_static_no_bound[317d]::supply[0]::{{closure}}[0]) with closure substs [
1818
i16,
1919
for<'r, 's, 't0, 't1, 't2> extern "rust-call" fn((&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 'r)) std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 's)) u32>, &ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't0)) std::cell::Cell<&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 's)) u32>, &ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't1)) std::cell::Cell<&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't2)) u32>))
2020
]
2121
= note: number of external vids: 2
2222
= note: where '_#1r: '_#0r
2323

2424
note: No external requirements
25-
--> $DIR/propagate-approximated-to-static.rs:39:1
25+
--> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:44:1
2626
|
27-
39 | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
28-
40 | | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
29-
41 | | // Only works if 'x: 'y:
30-
42 | | demand_y(x, y, x.get())
31-
43 | | });
32-
44 | | }
27+
44 | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
28+
45 | | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| {
29+
46 | | // Only works if 'x: 'y:
30+
47 | | demand_y(x, y, x.get())
31+
48 | | });
32+
49 | | }
3333
| |_^
3434
|
35-
= note: defining type: DefId(0/0:6 ~ propagate_approximated_to_static[317d]::supply[0]) with substs []
35+
= note: defining type: DefId(0/0:6 ~ propagate_approximated_shorter_to_static_no_bound[317d]::supply[0]) with substs []
3636

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
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 a case where we are trying to prove `'x: 'y` and are forced to
12+
// approximate the shorter end-point (`'y`) to with `'static`. This is
13+
// because `'y` is higher-ranked but we know of only irrelevant
14+
// relations to other regions. Note that `'static` shows up in the
15+
// stderr output as `'0`.
16+
//
17+
// FIXME(#45827) Because of shortcomings in the MIR type checker,
18+
// these errors are not (yet) reported.
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+
// 'x: 'a
29+
// 'y: 'b
30+
//
31+
// so the only way we can ensure that `'x: 'y` is to show that
32+
// `'a: 'static`.
33+
fn establish_relationships<'a, 'b, F>(_cell_a: &Cell<&'a u32>, _cell_b: &Cell<&'b u32>, _closure: F)
34+
where
35+
F: for<'x, 'y> FnMut(
36+
&Cell<&'a &'x u32>, // shows that 'x: 'a
37+
&Cell<&'b &'y u32>, // shows that 'y: 'b
38+
&Cell<&'x u32>,
39+
&Cell<&'y u32>,
40+
),
41+
{
42+
}
43+
44+
fn demand_y<'x, 'y>(_cell_x: &Cell<&'x u32>, _cell_y: &Cell<&'y u32>, _y: &'y u32) {}
45+
46+
#[rustc_regions]
47+
fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
48+
establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
49+
// Only works if 'x: 'y:
50+
demand_y(x, y, x.get())
51+
});
52+
}
53+
54+
fn main() {}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
warning: not reporting region error due to -Znll
2+
--> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:50:9
3+
|
4+
50 | demand_y(x, y, x.get())
5+
| ^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
note: External requirements
8+
--> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:48:47
9+
|
10+
48 | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
11+
| _______________________________________________^
12+
49 | | // Only works if 'x: 'y:
13+
50 | | demand_y(x, y, x.get())
14+
51 | | });
15+
| |_____^
16+
|
17+
= note: defining type: DefId(0/1:18 ~ propagate_approximated_shorter_to_static_wrong_bound[317d]::supply[0]::{{closure}}[0]) with closure substs [
18+
i16,
19+
for<'r, 's, 't0, 't1, 't2, 't3> extern "rust-call" fn((&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 'r)) std::cell::Cell<&'_#1r &ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 's)) u32>, &ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't0)) std::cell::Cell<&'_#2r &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>, &ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't3)) std::cell::Cell<&ReLateBound(DebruijnIndex { depth: 1 }, BrNamed(crate0:DefIndex(0:0), 't1)) u32>))
20+
]
21+
= note: number of external vids: 3
22+
= note: where '_#1r: '_#0r
23+
24+
note: No external requirements
25+
--> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:47:1
26+
|
27+
47 | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) {
28+
48 | | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| {
29+
49 | | // Only works if 'x: 'y:
30+
50 | | demand_y(x, y, x.get())
31+
51 | | });
32+
52 | | }
33+
| |_^
34+
|
35+
= note: defining type: DefId(0/0:6 ~ propagate_approximated_shorter_to_static_wrong_bound[317d]::supply[0]) with substs []
36+

0 commit comments

Comments
 (0)