From 65e56616fc71744b20b02622200d42860561b20c Mon Sep 17 00:00:00 2001 From: Lenko Donchev Date: Sun, 26 Feb 2023 12:51:49 -0600 Subject: [PATCH] Don't trigger ICE for ReError when the other region is empty. --- .../src/infer/lexical_region_resolve/mod.rs | 12 +++++++-- tests/ui/lifetimes/issue-107988.rs | 13 +++++++++ tests/ui/lifetimes/issue-107988.stderr | 27 +++++++++++++++++++ 3 files changed, 50 insertions(+), 2 deletions(-) create mode 100644 tests/ui/lifetimes/issue-107988.rs create mode 100644 tests/ui/lifetimes/issue-107988.stderr diff --git a/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs b/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs index 335eb4c54062f..a499018d3a2b0 100644 --- a/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs +++ b/compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs @@ -438,7 +438,11 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> { } (VarValue::Value(a), VarValue::Empty(_)) => { match *a { - ReLateBound(..) | ReErased | ReError(_) => { + // this is always on an error path, + // so it doesn't really matter if it's shorter or longer than an empty region + ReError(_) => false, + + ReLateBound(..) | ReErased => { bug!("cannot relate region: {:?}", a); } @@ -467,7 +471,11 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> { } (VarValue::Empty(a_ui), VarValue::Value(b)) => { match *b { - ReLateBound(..) | ReErased | ReError(_) => { + // this is always on an error path, + // so it doesn't really matter if it's shorter or longer than an empty region + ReError(_) => false, + + ReLateBound(..) | ReErased => { bug!("cannot relate region: {:?}", b); } diff --git a/tests/ui/lifetimes/issue-107988.rs b/tests/ui/lifetimes/issue-107988.rs new file mode 100644 index 0000000000000..92cb60a06a2b0 --- /dev/null +++ b/tests/ui/lifetimes/issue-107988.rs @@ -0,0 +1,13 @@ +pub trait TraitEngine<'tcx>: 'tcx {} + +pub trait TraitEngineExt<'tcx> { + fn register_predicate_obligations(&mut self); +} + +impl> TraitEngineExt<'tcx> for T { + //~^ ERROR use of undeclared lifetime name `'tcx` + //~| ERROR use of undeclared lifetime name `'tcx` + fn register_predicate_obligations(&mut self) {} +} + +fn main() {} diff --git a/tests/ui/lifetimes/issue-107988.stderr b/tests/ui/lifetimes/issue-107988.stderr new file mode 100644 index 0000000000000..c2d8c7050e97f --- /dev/null +++ b/tests/ui/lifetimes/issue-107988.stderr @@ -0,0 +1,27 @@ +error[E0261]: use of undeclared lifetime name `'tcx` + --> $DIR/issue-107988.rs:7:52 + | +LL | impl> TraitEngineExt<'tcx> for T { + | - ^^^^ undeclared lifetime + | | + | help: consider introducing lifetime `'tcx` here: `'tcx,` + +error[E0261]: use of undeclared lifetime name `'tcx` + --> $DIR/issue-107988.rs:7:30 + | +LL | impl> TraitEngineExt<'tcx> for T { + | ^^^^ undeclared lifetime + | + = note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html +help: consider making the bound lifetime-generic with a new `'tcx` lifetime + | +LL | impl TraitEngine<'tcx>> TraitEngineExt<'tcx> for T { + | +++++++++ +help: consider introducing lifetime `'tcx` here + | +LL | impl<'tcx, T: ?Sized + TraitEngine<'tcx>> TraitEngineExt<'tcx> for T { + | +++++ + +error: aborting due to 2 previous errors + +For more information about this error, try `rustc --explain E0261`.