From 2a3177a8bcc4c5a5285dc2908a0f1ce98e9a6377 Mon Sep 17 00:00:00 2001 From: Ali MJ Al-Nasrawy Date: Sun, 26 Mar 2023 14:37:24 +0300 Subject: [PATCH] tolerate region vars in implied bounds See https://github.com/rust-lang/rust/issues/109628. --- .../rustc_infer/src/infer/outlives/env.rs | 5 +++- .../implied-bounds/ice-unbound-region-vars.rs | 24 +++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 tests/ui/implied-bounds/ice-unbound-region-vars.rs diff --git a/compiler/rustc_infer/src/infer/outlives/env.rs b/compiler/rustc_infer/src/infer/outlives/env.rs index a480ee5429eec..47e3dd762b08b 100644 --- a/compiler/rustc_infer/src/infer/outlives/env.rs +++ b/compiler/rustc_infer/src/infer/outlives/env.rs @@ -142,7 +142,10 @@ impl<'tcx> OutlivesEnvironmentBuilder<'tcx> { ty::ReStatic | ty::ReEarlyBound(_) | ty::ReFree(_), ) => self.region_relation.add(r_a, r_b), (ty::ReError(_), _) | (_, ty::ReError(_)) => {} - _ => bug!("add_outlives_bounds: unexpected regions"), + // FIXME(#109628): We shouldn't have existential variables in implied bounds. + // Panic here once the linked issue is resolved! + (ty::ReVar(_), _) | (_, ty::ReVar(_)) => {} + _ => bug!("add_outlives_bounds: unexpected regions: ({r_a:?}, {r_b:?})"), }, } } diff --git a/tests/ui/implied-bounds/ice-unbound-region-vars.rs b/tests/ui/implied-bounds/ice-unbound-region-vars.rs new file mode 100644 index 0000000000000..9e1e3feaeec9f --- /dev/null +++ b/tests/ui/implied-bounds/ice-unbound-region-vars.rs @@ -0,0 +1,24 @@ +// Because of #109628, we can have unbounded region vars in implied bounds. +// Make sure we don't ICE in this case! +// +// check-pass + +pub trait MapAccess { + type Error; + fn next_key_seed(&mut self) -> Option; +} + +struct Access<'a> { + _marker: std::marker::PhantomData<&'a ()>, +} + +// implied_bounds(Option) = ['?1: 'a, ] +// where '?1 is a fresh region var. +impl<'a, 'b: 'a> MapAccess for Access<'a> { + type Error = (); + fn next_key_seed(&mut self) -> Option { + unimplemented!() + } +} + +fn main() {}