From 4de99600b0ca8dafd5310f900def87bbcbf0aae6 Mon Sep 17 00:00:00 2001 From: Niko Matsakis Date: Wed, 12 Jun 2019 11:16:59 -0400 Subject: [PATCH] add a FIXME related to the non-free-region case I don't think it would actually be harmful to just ignore such cases but I'm inclined not to take chances. --- .../borrow_check/nll/region_infer/mod.rs | 19 ++++++++++--- .../ordinary-bounds-pick-original-elided.rs | 27 +++++++++++++++++++ 2 files changed, 43 insertions(+), 3 deletions(-) create mode 100644 src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-pick-original-elided.rs diff --git a/src/librustc_mir/borrow_check/nll/region_infer/mod.rs b/src/librustc_mir/borrow_check/nll/region_infer/mod.rs index 39818de23108..822c7b76b8fd 100644 --- a/src/librustc_mir/borrow_check/nll/region_infer/mod.rs +++ b/src/librustc_mir/borrow_check/nll/region_infer/mod.rs @@ -550,7 +550,11 @@ impl<'tcx> RegionInferenceContext<'tcx> { // Now take pick constraints into account let pick_constraints = self.pick_constraints.clone(); for p_c_i in pick_constraints.indices(scc_a) { - self.apply_pick_constraint(scc_a, pick_constraints.option_regions(p_c_i)); + self.apply_pick_constraint( + scc_a, + pick_constraints[p_c_i].opaque_type_def_id, + pick_constraints.option_regions(p_c_i), + ); } debug!( @@ -574,6 +578,7 @@ impl<'tcx> RegionInferenceContext<'tcx> { fn apply_pick_constraint( &mut self, scc: ConstraintSccIndex, + opaque_type_def_id: DefId, option_regions: &[ty::RegionVid], ) -> bool { debug!("apply_pick_constraint(scc={:?}, option_regions={:#?})", scc, option_regions,); @@ -581,8 +586,16 @@ impl<'tcx> RegionInferenceContext<'tcx> { if let Some(uh_oh) = option_regions.iter().find(|&&r| !self.universal_regions.is_universal_region(r)) { - debug!("apply_pick_constraint: option region `{:?}` is not a universal region", uh_oh); - return false; + // FIXME(#61773): This case can only occur with + // `impl_trait_in_bindings`, I believe, and we are just + // opting not to handle it for now. See #61773 for + // details. + bug!( + "pick constraint for `{:?}` has an option region `{:?}` \ + that is not a universal region", + opaque_type_def_id, + uh_oh, + ); } // Create a mutable vector of the options. We'll try to winnow diff --git a/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-pick-original-elided.rs b/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-pick-original-elided.rs new file mode 100644 index 000000000000..23981d92562d --- /dev/null +++ b/src/test/ui/impl-trait/multiple-lifetimes/ordinary-bounds-pick-original-elided.rs @@ -0,0 +1,27 @@ +// edition:2018 +// run-pass +// revisions: migrate mir +//[mir]compile-flags: -Z borrowck=mir + +trait Trait<'a, 'b> { } +impl Trait<'_, '_> for T { } + +// Test case where we have elision in the impl trait and we have to +// pick the right region. + +// Ultimately `Trait<'x, 'static>`. +fn upper_bounds1(a: &u8) -> impl Trait<'_, 'static> { + (a, a) +} + +// Ultimately `Trait<'x, 'x>`, so not really multiple bounds. +fn upper_bounds2(a: &u8) -> impl Trait<'_, '_> { + (a, a) +} + +// Kind of a weird annoying case. +fn upper_bounds3<'b>(a: &u8) -> impl Trait<'_, 'b> { + (a, a) +} + +fn main() { }