From a30e2259daacb0075cb5d0ecdca63afd8016b607 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Thu, 7 Dec 2017 06:25:59 -0500 Subject: [PATCH] fix closure tests now that MIR typeck works properly These tests had FIXMEs for errors that were not previously being reported. --- .../nll/where_clauses_in_repeat_rvalue.rs | 4 +- src/test/compile-fail/regions-static-bound.rs | 5 +- .../propagate-approximated-ref.rs | 10 ++-- .../propagate-approximated-ref.stderr | 41 ++++++++++------ ...horter-to-static-comparing-against-free.rs | 4 +- ...er-to-static-comparing-against-free.stderr | 27 +++++++---- ...approximated-shorter-to-static-no-bound.rs | 5 +- ...oximated-shorter-to-static-no-bound.stderr | 47 +++++++++++++------ ...roximated-shorter-to-static-wrong-bound.rs | 3 +- ...mated-shorter-to-static-wrong-bound.stderr | 35 ++++++++++---- .../propagate-approximated-val.rs | 5 +- .../propagate-approximated-val.stderr | 41 ++++++++++------ 12 files changed, 145 insertions(+), 82 deletions(-) diff --git a/src/test/compile-fail/nll/where_clauses_in_repeat_rvalue.rs b/src/test/compile-fail/nll/where_clauses_in_repeat_rvalue.rs index aae0cd3fdb0..93c774e8996 100644 --- a/src/test/compile-fail/nll/where_clauses_in_repeat_rvalue.rs +++ b/src/test/compile-fail/nll/where_clauses_in_repeat_rvalue.rs @@ -27,7 +27,8 @@ fn main() { let mut x = 22; { - let p = &x; //~ ERROR borrowed value does not live long enough + let p = &x; + //~^ ERROR `x` does not live long enough let w = Foo { t: p }; let v = [w; 22]; @@ -36,4 +37,3 @@ fn main() { x += 1; //~^ ERROR cannot assign to `x` because it is borrowed [E0506] } -//~^ ERROR borrowed value does not live long enough [E0597] diff --git a/src/test/compile-fail/regions-static-bound.rs b/src/test/compile-fail/regions-static-bound.rs index 9de8ca196f8..678da45fce4 100644 --- a/src/test/compile-fail/regions-static-bound.rs +++ b/src/test/compile-fail/regions-static-bound.rs @@ -24,11 +24,10 @@ fn static_id_wrong_way<'a>(t: &'a ()) -> &'static () where 'static: 'a { fn error(u: &(), v: &()) { static_id(&u); //[ll]~ ERROR cannot infer an appropriate lifetime //[nll]~^ WARNING not reporting region error due to -Znll + //[nll]~| ERROR free region `'_#1r` does not outlive free region `'static` static_id_indirect(&v); //[ll]~ ERROR cannot infer an appropriate lifetime //[nll]~^ WARNING not reporting region error due to -Znll - - // FIXME(#45827) -- MIR type checker shortcomings mean we don't - // see these errors (yet) in nll mode. + //[nll]~| ERROR free region `'_#2r` does not outlive free region `'static` } fn main() {} diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-ref.rs b/src/test/ui/nll/closure-requirements/propagate-approximated-ref.rs index 006bdaf4c60..80a40581b89 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-ref.rs +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-ref.rs @@ -21,14 +21,8 @@ // // Note: the use of `Cell` here is to introduce invariance. One less // variable. -// -// FIXME(#45827): The `supply` function *ought* to generate an error, but it -// currently does not. This is I believe a shortcoming of the MIR type -// checker: the closure inference is expressing the correct -// requirement, as you can see from the `#[rustc_regions]` output. // compile-flags:-Znll -Zborrowck=mir -Zverbose -// must-compile-successfully #![feature(rustc_attrs)] @@ -57,8 +51,10 @@ fn demand_y<'x, 'y>(_cell_x: &Cell<&'x u32>, _cell_y: &Cell<&'y u32>, _y: &'y u3 #[rustc_regions] fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) { establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| { + //~^ ERROR free region `'_#1r` does not outlive free region `'_#2r` + // Only works if 'x: 'y: - demand_y(x, y, x.get()) + demand_y(x, y, x.get()) //~ WARNING not reporting region error due to -Znll }); } diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-ref.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-ref.stderr index 81eb90020cc..717cf481a01 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-ref.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-ref.stderr @@ -1,17 +1,19 @@ warning: not reporting region error due to -Znll - --> $DIR/propagate-approximated-ref.rs:61:9 + --> $DIR/propagate-approximated-ref.rs:57:9 | -61 | demand_y(x, y, x.get()) +57 | demand_y(x, y, x.get()) //~ WARNING not reporting region error due to -Znll | ^^^^^^^^^^^^^^^^^^^^^^^ note: External requirements - --> $DIR/propagate-approximated-ref.rs:59:47 + --> $DIR/propagate-approximated-ref.rs:53:47 | -59 | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| { +53 | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| { | _______________________________________________^ -60 | | // Only works if 'x: 'y: -61 | | demand_y(x, y, x.get()) -62 | | }); +54 | | //~^ ERROR free region `'_#1r` does not outlive free region `'_#2r` +55 | | +56 | | // Only works if 'x: 'y: +57 | | demand_y(x, y, x.get()) //~ WARNING not reporting region error due to -Znll +58 | | }); | |_____^ | = note: defining type: DefId(0/1:18 ~ propagate_approximated_ref[317d]::supply[0]::{{closure}}[0]) with closure substs [ @@ -21,16 +23,25 @@ note: External requirements = note: number of external vids: 3 = note: where '_#1r: '_#2r -note: No external requirements - --> $DIR/propagate-approximated-ref.rs:58:1 +error: free region `'_#1r` does not outlive free region `'_#2r` + --> $DIR/propagate-approximated-ref.rs:53:38 | -58 | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) { -59 | | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| { -60 | | // Only works if 'x: 'y: -61 | | demand_y(x, y, x.get()) -62 | | }); -63 | | } +53 | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| { + | ^^^^^^^ + +note: No external requirements + --> $DIR/propagate-approximated-ref.rs:52:1 + | +52 | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) { +53 | | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| { +54 | | //~^ ERROR free region `'_#1r` does not outlive free region `'_#2r` +55 | | +... | +58 | | }); +59 | | } | |_^ | = note: defining type: DefId(0/0:6 ~ propagate_approximated_ref[317d]::supply[0]) with substs [] +error: aborting due to previous error + diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.rs b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.rs index 0a47ee80256..244929d71db 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.rs +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.rs @@ -39,12 +39,10 @@ fn case1() { fn case2() { let a = 0; let cell = Cell::new(&a); + //~^ ERROR `a` does not live long enough // As you can see in the stderr output, this closure propoagates a // requirement that `'a: 'static'. - // - // FIXME(#45827) However, because of shortcomings in the MIR type - // checker, this does not result in errors later on (yet). foo(cell, |cell_a, cell_x| { cell_x.set(cell_a.get()); // forces 'a: 'x, implies 'a = 'static -> borrow error }) diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr index e2de72ffe93..b93c69dc13f 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-comparing-against-free.stderr @@ -42,12 +42,12 @@ note: No external requirements = note: defining type: DefId(0/0:5 ~ propagate_approximated_shorter_to_static_comparing_against_free[317d]::case1[0]) with substs [] note: External requirements - --> $DIR/propagate-approximated-shorter-to-static-comparing-against-free.rs:48:15 + --> $DIR/propagate-approximated-shorter-to-static-comparing-against-free.rs:46:15 | -48 | foo(cell, |cell_a, cell_x| { +46 | foo(cell, |cell_a, cell_x| { | _______________^ -49 | | cell_x.set(cell_a.get()); // forces 'a: 'x, implies 'a = 'static -> borrow error -50 | | }) +47 | | cell_x.set(cell_a.get()); // forces 'a: 'x, implies 'a = 'static -> borrow error +48 | | }) | |_____^ | = note: defining type: DefId(0/1:13 ~ propagate_approximated_shorter_to_static_comparing_against_free[317d]::case2[0]::{{closure}}[0]) with closure substs [ @@ -63,13 +63,24 @@ note: No external requirements 39 | / fn case2() { 40 | | let a = 0; 41 | | let cell = Cell::new(&a); -42 | | +42 | | //~^ ERROR `a` does not live long enough ... | -50 | | }) -51 | | } +48 | | }) +49 | | } | |_^ | = note: defining type: DefId(0/0:6 ~ propagate_approximated_shorter_to_static_comparing_against_free[317d]::case2[0]) with substs [] -error: aborting due to previous error +error[E0597]: `a` does not live long enough + --> $DIR/propagate-approximated-shorter-to-static-comparing-against-free.rs:41:26 + | +41 | let cell = Cell::new(&a); + | ^^ does not live long enough +... +49 | } + | - borrowed value only lives until here + | + = note: borrowed value must be valid for lifetime '_#1r... + +error: aborting due to 2 previous errors diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.rs b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.rs index 5bd170cc304..54007f0191d 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.rs +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.rs @@ -17,7 +17,6 @@ // these errors are not (yet) reported. // compile-flags:-Znll -Zborrowck=mir -Zverbose -// must-compile-successfully #![feature(rustc_attrs)] @@ -44,8 +43,10 @@ fn demand_y<'x, 'y>(_cell_x: &Cell<&'x u32>, _cell_y: &Cell<&'y u32>, _y: &'y u3 #[rustc_regions] fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) { establish_relationships(&cell_a, &cell_b, |_outlives, x, y| { + //~^ ERROR free region `'_#1r` does not outlive free region `ReStatic` + // Only works if 'x: 'y: - demand_y(x, y, x.get()) + demand_y(x, y, x.get()) //~ WARNING not reporting region error due to -Znll }); } diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr index 8fd6acbbe5d..86b9fecb80e 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr @@ -1,17 +1,19 @@ warning: not reporting region error due to -Znll - --> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:48:9 + --> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:49:9 | -48 | demand_y(x, y, x.get()) +49 | demand_y(x, y, x.get()) //~ WARNING not reporting region error due to -Znll | ^^^^^^^^^^^^^^^^^^^^^^^ note: External requirements - --> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:46:47 + --> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:45:47 | -46 | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| { +45 | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| { | _______________________________________________^ -47 | | // Only works if 'x: 'y: -48 | | demand_y(x, y, x.get()) -49 | | }); +46 | | //~^ ERROR free region `'_#1r` does not outlive free region `ReStatic` +47 | | +48 | | // Only works if 'x: 'y: +49 | | demand_y(x, y, x.get()) //~ WARNING not reporting region error due to -Znll +50 | | }); | |_____^ | = note: defining type: DefId(0/1:18 ~ propagate_approximated_shorter_to_static_no_bound[317d]::supply[0]::{{closure}}[0]) with closure substs [ @@ -21,16 +23,31 @@ note: External requirements = note: number of external vids: 2 = note: where '_#1r: '_#0r -note: No external requirements - --> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:45:1 +error: free region `'_#1r` does not outlive free region `ReStatic` + --> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:45:47 | -45 | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) { -46 | | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| { -47 | | // Only works if 'x: 'y: -48 | | demand_y(x, y, x.get()) -49 | | }); -50 | | } +45 | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| { + | _______________________________________________^ +46 | | //~^ ERROR free region `'_#1r` does not outlive free region `ReStatic` +47 | | +48 | | // Only works if 'x: 'y: +49 | | demand_y(x, y, x.get()) //~ WARNING not reporting region error due to -Znll +50 | | }); + | |_____^ + +note: No external requirements + --> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:44:1 + | +44 | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) { +45 | | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| { +46 | | //~^ ERROR free region `'_#1r` does not outlive free region `ReStatic` +47 | | +... | +50 | | }); +51 | | } | |_^ | = note: defining type: DefId(0/0:6 ~ propagate_approximated_shorter_to_static_no_bound[317d]::supply[0]) with substs [] +error: aborting due to previous error + diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.rs b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.rs index f4fdd4a8c17..68d51e2b7d1 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.rs +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.rs @@ -18,7 +18,6 @@ // these errors are not (yet) reported. // compile-flags:-Znll -Zborrowck=mir -Zverbose -// must-compile-successfully #![feature(rustc_attrs)] @@ -47,8 +46,10 @@ fn demand_y<'x, 'y>(_cell_x: &Cell<&'x u32>, _cell_y: &Cell<&'y u32>, _y: &'y u3 #[rustc_regions] fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) { establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| { + //~^ ERROR free region `'_#1r` does not outlive free region `ReStatic` // Only works if 'x: 'y: demand_y(x, y, x.get()) + //~^ WARNING not reporting region error due to -Znll }); } diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr index f189967244a..adc6b1ac595 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr @@ -5,13 +5,15 @@ warning: not reporting region error due to -Znll | ^^^^^^^^^^^^^^^^^^^^^^^ note: External requirements - --> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:49:47 + --> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:48:47 | -49 | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| { +48 | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| { | _______________________________________________^ +49 | | //~^ ERROR free region `'_#1r` does not outlive free region `ReStatic` 50 | | // Only works if 'x: 'y: 51 | | demand_y(x, y, x.get()) -52 | | }); +52 | | //~^ WARNING not reporting region error due to -Znll +53 | | }); | |_____^ | = note: defining type: DefId(0/1:18 ~ propagate_approximated_shorter_to_static_wrong_bound[317d]::supply[0]::{{closure}}[0]) with closure substs [ @@ -21,16 +23,31 @@ note: External requirements = note: number of external vids: 3 = note: where '_#1r: '_#0r -note: No external requirements - --> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:48:1 +error: free region `'_#1r` does not outlive free region `ReStatic` + --> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:48:47 | -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| { +48 | establish_relationships(&cell_a, &cell_b, |_outlives1, _outlives2, x, y| { + | _______________________________________________^ +49 | | //~^ ERROR free region `'_#1r` does not outlive free region `ReStatic` 50 | | // Only works if 'x: 'y: 51 | | demand_y(x, y, x.get()) -52 | | }); -53 | | } +52 | | //~^ WARNING not reporting region error due to -Znll +53 | | }); + | |_____^ + +note: No external requirements + --> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:47:1 + | +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 | | //~^ ERROR free region `'_#1r` does not outlive free region `ReStatic` +50 | | // Only works if 'x: 'y: +... | +53 | | }); +54 | | } | |_^ | = note: defining type: DefId(0/0:6 ~ propagate_approximated_shorter_to_static_wrong_bound[317d]::supply[0]) with substs [] +error: aborting due to previous error + diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-val.rs b/src/test/ui/nll/closure-requirements/propagate-approximated-val.rs index 97a15a36fdd..b4a759d5e70 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-val.rs +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-val.rs @@ -16,7 +16,6 @@ // anonymous regions as well. // compile-flags:-Znll -Zborrowck=mir -Zverbose -// must-compile-successfully #![feature(rustc_attrs)] @@ -45,8 +44,10 @@ fn demand_y<'x, 'y>(_outlives1: Cell<&&'x u32>, _outlives2: Cell<&'y &u32>, _y: #[rustc_regions] fn test<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) { establish_relationships(cell_a, cell_b, |outlives1, outlives2, x, y| { + //~^ ERROR free region `'_#1r` does not outlive free region `'_#2r` + // Only works if 'x: 'y: - demand_y(outlives1, outlives2, x.get()) + demand_y(outlives1, outlives2, x.get()) //~ WARNING not reporting region error due to -Znll }); } diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-val.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-val.stderr index 1577e34e0de..43464bfb2b9 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-val.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-val.stderr @@ -1,17 +1,19 @@ warning: not reporting region error due to -Znll - --> $DIR/propagate-approximated-val.rs:49:9 + --> $DIR/propagate-approximated-val.rs:50:9 | -49 | demand_y(outlives1, outlives2, x.get()) +50 | demand_y(outlives1, outlives2, x.get()) //~ WARNING not reporting region error due to -Znll | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ note: External requirements - --> $DIR/propagate-approximated-val.rs:47:45 + --> $DIR/propagate-approximated-val.rs:46:45 | -47 | establish_relationships(cell_a, cell_b, |outlives1, outlives2, x, y| { +46 | establish_relationships(cell_a, cell_b, |outlives1, outlives2, x, y| { | _____________________________________________^ -48 | | // Only works if 'x: 'y: -49 | | demand_y(outlives1, outlives2, x.get()) -50 | | }); +47 | | //~^ ERROR free region `'_#1r` does not outlive free region `'_#2r` +48 | | +49 | | // Only works if 'x: 'y: +50 | | demand_y(outlives1, outlives2, x.get()) //~ WARNING not reporting region error due to -Znll +51 | | }); | |_____^ | = note: defining type: DefId(0/1:18 ~ propagate_approximated_val[317d]::test[0]::{{closure}}[0]) with closure substs [ @@ -21,16 +23,25 @@ note: External requirements = note: number of external vids: 3 = note: where '_#1r: '_#2r -note: No external requirements - --> $DIR/propagate-approximated-val.rs:46:1 +error: free region `'_#1r` does not outlive free region `'_#2r` + --> $DIR/propagate-approximated-val.rs:46:37 | -46 | / fn test<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) { -47 | | establish_relationships(cell_a, cell_b, |outlives1, outlives2, x, y| { -48 | | // Only works if 'x: 'y: -49 | | demand_y(outlives1, outlives2, x.get()) -50 | | }); -51 | | } +46 | establish_relationships(cell_a, cell_b, |outlives1, outlives2, x, y| { + | ^^^^^^ + +note: No external requirements + --> $DIR/propagate-approximated-val.rs:45:1 + | +45 | / fn test<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) { +46 | | establish_relationships(cell_a, cell_b, |outlives1, outlives2, x, y| { +47 | | //~^ ERROR free region `'_#1r` does not outlive free region `'_#2r` +48 | | +... | +51 | | }); +52 | | } | |_^ | = note: defining type: DefId(0/0:6 ~ propagate_approximated_val[317d]::test[0]) with substs [] +error: aborting due to previous error +