Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't trigger error for ReError when other region is empty. #108502

Merged
merged 1 commit into from
Feb 27, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs
Original file line number Diff line number Diff line change
@@ -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);
}

13 changes: 13 additions & 0 deletions tests/ui/lifetimes/issue-107988.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
pub trait TraitEngine<'tcx>: 'tcx {}

pub trait TraitEngineExt<'tcx> {
fn register_predicate_obligations(&mut self);
}

impl<T: ?Sized + TraitEngine<'tcx>> 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() {}
27 changes: 27 additions & 0 deletions tests/ui/lifetimes/issue-107988.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
error[E0261]: use of undeclared lifetime name `'tcx`
--> $DIR/issue-107988.rs:7:52
|
LL | impl<T: ?Sized + TraitEngine<'tcx>> 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<T: ?Sized + TraitEngine<'tcx>> 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<T: ?Sized + for<'tcx> 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`.