From ca60826110dcba2014f439605c2100ae0b095394 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Wed, 6 Dec 2017 16:25:10 -0500 Subject: [PATCH] test approximations of the "shorter side" that resort to `'static` This includes the additional case suggested by arielb1. --- ...pproximated-shorter-to-static-no-bound.rs} | 9 +++- ...ximated-shorter-to-static-no-bound.stderr} | 32 +++++------ ...roximated-shorter-to-static-wrong-bound.rs | 54 +++++++++++++++++++ ...mated-shorter-to-static-wrong-bound.stderr | 36 +++++++++++++ 4 files changed, 113 insertions(+), 18 deletions(-) rename src/test/ui/nll/closure-requirements/{propagate-approximated-to-static.rs => propagate-approximated-shorter-to-static-no-bound.rs} (76%) rename src/test/ui/nll/closure-requirements/{propagate-approximated-to-static.stderr => propagate-approximated-shorter-to-static-no-bound.stderr} (55%) create mode 100644 src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.rs create mode 100644 src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-to-static.rs b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.rs similarity index 76% rename from src/test/ui/nll/closure-requirements/propagate-approximated-to-static.rs rename to src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.rs index 5e669b3d3c1..f776ddc8b15 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-to-static.rs +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.rs @@ -8,8 +8,13 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -// Test a case where we are forced to approximate one end-point with -// `'static`. Note that `'static` shows up in the stderr output as `'0`. +// Test a case where we are trying to prove `'x: 'y` and are forced to +// approximate the shorter end-point (`'y`) to with `'static`. This is +// because `'y` is higher-ranked but we know of no relations to other +// regions. Note that `'static` shows up in the stderr output as `'0`. +// +// FIXME(#45827) Because of shortcomings in the MIR type checker, +// these errors are not (yet) reported. // compile-flags:-Znll -Zborrowck=mir -Zverbose diff --git a/src/test/ui/nll/closure-requirements/propagate-approximated-to-static.stderr b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr similarity index 55% rename from src/test/ui/nll/closure-requirements/propagate-approximated-to-static.stderr rename to src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr index c23d2a8eca3..8d1b9a94ea6 100644 --- a/src/test/ui/nll/closure-requirements/propagate-approximated-to-static.stderr +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-no-bound.stderr @@ -1,20 +1,20 @@ warning: not reporting region error due to -Znll - --> $DIR/propagate-approximated-to-static.rs:42:9 + --> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:47:9 | -42 | demand_y(x, y, x.get()) +47 | demand_y(x, y, x.get()) | ^^^^^^^^^^^^^^^^^^^^^^^ note: External requirements - --> $DIR/propagate-approximated-to-static.rs:40:47 + --> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:45:47 | -40 | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| { +45 | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| { | _______________________________________________^ -41 | | // Only works if 'x: 'y: -42 | | demand_y(x, y, x.get()) -43 | | }); +46 | | // Only works if 'x: 'y: +47 | | demand_y(x, y, x.get()) +48 | | }); | |_____^ | - = note: defining type: DefId(0/1:18 ~ propagate_approximated_to_static[317d]::supply[0]::{{closure}}[0]) with closure substs [ + = note: defining type: DefId(0/1:18 ~ propagate_approximated_shorter_to_static_no_bound[317d]::supply[0]::{{closure}}[0]) with closure substs [ i16, 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>)) ] @@ -22,15 +22,15 @@ note: External requirements = note: where '_#1r: '_#0r note: No external requirements - --> $DIR/propagate-approximated-to-static.rs:39:1 + --> $DIR/propagate-approximated-shorter-to-static-no-bound.rs:44:1 | -39 | / fn supply<'a, 'b>(cell_a: Cell<&'a u32>, cell_b: Cell<&'b u32>) { -40 | | establish_relationships(&cell_a, &cell_b, |_outlives, x, y| { -41 | | // Only works if 'x: 'y: -42 | | demand_y(x, y, x.get()) -43 | | }); -44 | | } +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 | | // Only works if 'x: 'y: +47 | | demand_y(x, y, x.get()) +48 | | }); +49 | | } | |_^ | - = note: defining type: DefId(0/0:6 ~ propagate_approximated_to_static[317d]::supply[0]) with substs [] + = note: defining type: DefId(0/0:6 ~ propagate_approximated_shorter_to_static_no_bound[317d]::supply[0]) with substs [] 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 new file mode 100644 index 00000000000..54b501c9ab6 --- /dev/null +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.rs @@ -0,0 +1,54 @@ +// 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 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// Test a case where we are trying to prove `'x: 'y` and are forced to +// approximate the shorter end-point (`'y`) to with `'static`. This is +// because `'y` is higher-ranked but we know of only irrelevant +// relations to other regions. Note that `'static` shows up in the +// stderr output as `'0`. +// +// FIXME(#45827) Because of shortcomings in the MIR type checker, +// these errors are not (yet) reported. + +// compile-flags:-Znll -Zborrowck=mir -Zverbose + +#![feature(rustc_attrs)] + +use std::cell::Cell; + +// Callee knows that: +// +// 'x: 'a +// 'y: 'b +// +// so the only way we can ensure that `'x: 'y` is to show that +// `'a: 'static`. +fn establish_relationships<'a, 'b, F>(_cell_a: &Cell<&'a u32>, _cell_b: &Cell<&'b u32>, _closure: F) +where + F: for<'x, 'y> FnMut( + &Cell<&'a &'x u32>, // shows that 'x: 'a + &Cell<&'b &'y u32>, // shows that 'y: 'b + &Cell<&'x u32>, + &Cell<&'y u32>, + ), +{ +} + +fn demand_y<'x, 'y>(_cell_x: &Cell<&'x u32>, _cell_y: &Cell<&'y u32>, _y: &'y u32) {} + +#[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| { + // Only works if 'x: 'y: + demand_y(x, y, x.get()) + }); +} + +fn main() {} 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 new file mode 100644 index 00000000000..9d318a63d8f --- /dev/null +++ b/src/test/ui/nll/closure-requirements/propagate-approximated-shorter-to-static-wrong-bound.stderr @@ -0,0 +1,36 @@ +warning: not reporting region error due to -Znll + --> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:50:9 + | +50 | demand_y(x, y, x.get()) + | ^^^^^^^^^^^^^^^^^^^^^^^ + +note: External requirements + --> $DIR/propagate-approximated-shorter-to-static-wrong-bound.rs:48:47 + | +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 | | }); + | |_____^ + | + = note: defining type: DefId(0/1:18 ~ propagate_approximated_shorter_to_static_wrong_bound[317d]::supply[0]::{{closure}}[0]) with closure substs [ + i16, + 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>)) + ] + = note: number of external vids: 3 + = note: where '_#1r: '_#0r + +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 | | // Only works if 'x: 'y: +50 | | demand_y(x, y, x.get()) +51 | | }); +52 | | } + | |_^ + | + = note: defining type: DefId(0/0:6 ~ propagate_approximated_shorter_to_static_wrong_bound[317d]::supply[0]) with substs [] +