Skip to content

Commit bade556

Browse files
authored
Rollup merge of #108502 - lenko-d:cannot_relate_region, r=compiler-errors
Don't trigger error for ReError when other region is empty. Fixes [#107988](#107988)
2 parents 37338b8 + 65e5661 commit bade556

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

compiler/rustc_infer/src/infer/lexical_region_resolve/mod.rs

+10-2
Original file line numberDiff line numberDiff line change
@@ -438,7 +438,11 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
438438
}
439439
(VarValue::Value(a), VarValue::Empty(_)) => {
440440
match *a {
441-
ReLateBound(..) | ReErased | ReError(_) => {
441+
// this is always on an error path,
442+
// so it doesn't really matter if it's shorter or longer than an empty region
443+
ReError(_) => false,
444+
445+
ReLateBound(..) | ReErased => {
442446
bug!("cannot relate region: {:?}", a);
443447
}
444448

@@ -467,7 +471,11 @@ impl<'cx, 'tcx> LexicalResolver<'cx, 'tcx> {
467471
}
468472
(VarValue::Empty(a_ui), VarValue::Value(b)) => {
469473
match *b {
470-
ReLateBound(..) | ReErased | ReError(_) => {
474+
// this is always on an error path,
475+
// so it doesn't really matter if it's shorter or longer than an empty region
476+
ReError(_) => false,
477+
478+
ReLateBound(..) | ReErased => {
471479
bug!("cannot relate region: {:?}", b);
472480
}
473481

tests/ui/lifetimes/issue-107988.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
pub trait TraitEngine<'tcx>: 'tcx {}
2+
3+
pub trait TraitEngineExt<'tcx> {
4+
fn register_predicate_obligations(&mut self);
5+
}
6+
7+
impl<T: ?Sized + TraitEngine<'tcx>> TraitEngineExt<'tcx> for T {
8+
//~^ ERROR use of undeclared lifetime name `'tcx`
9+
//~| ERROR use of undeclared lifetime name `'tcx`
10+
fn register_predicate_obligations(&mut self) {}
11+
}
12+
13+
fn main() {}
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
error[E0261]: use of undeclared lifetime name `'tcx`
2+
--> $DIR/issue-107988.rs:7:52
3+
|
4+
LL | impl<T: ?Sized + TraitEngine<'tcx>> TraitEngineExt<'tcx> for T {
5+
| - ^^^^ undeclared lifetime
6+
| |
7+
| help: consider introducing lifetime `'tcx` here: `'tcx,`
8+
9+
error[E0261]: use of undeclared lifetime name `'tcx`
10+
--> $DIR/issue-107988.rs:7:30
11+
|
12+
LL | impl<T: ?Sized + TraitEngine<'tcx>> TraitEngineExt<'tcx> for T {
13+
| ^^^^ undeclared lifetime
14+
|
15+
= note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
16+
help: consider making the bound lifetime-generic with a new `'tcx` lifetime
17+
|
18+
LL | impl<T: ?Sized + for<'tcx> TraitEngine<'tcx>> TraitEngineExt<'tcx> for T {
19+
| +++++++++
20+
help: consider introducing lifetime `'tcx` here
21+
|
22+
LL | impl<'tcx, T: ?Sized + TraitEngine<'tcx>> TraitEngineExt<'tcx> for T {
23+
| +++++
24+
25+
error: aborting due to 2 previous errors
26+
27+
For more information about this error, try `rustc --explain E0261`.

0 commit comments

Comments
 (0)