Skip to content

Commit ed16ae8

Browse files
Do not freshen ReError
1 parent b63223c commit ed16ae8

File tree

4 files changed

+60
-18
lines changed

4 files changed

+60
-18
lines changed

compiler/rustc_infer/src/infer/freshen.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,16 @@ impl<'a, 'tcx> TypeFolder<TyCtxt<'tcx>> for TypeFreshener<'a, 'tcx> {
110110

111111
fn fold_region(&mut self, r: ty::Region<'tcx>) -> ty::Region<'tcx> {
112112
match r.kind() {
113-
ty::ReBound(..) => {
114-
// leave bound regions alone
115-
r
116-
}
113+
// Leave bound regions alone, since they affect selection via the leak check.
114+
ty::ReBound(..) => r,
115+
// Leave error regions alone, since they affect selection b/c of incompleteness.
116+
ty::ReError(_) => r,
117117

118118
ty::ReEarlyParam(..)
119119
| ty::ReLateParam(_)
120120
| ty::ReVar(_)
121121
| ty::RePlaceholder(..)
122122
| ty::ReStatic
123-
| ty::ReError(_)
124123
| ty::ReErased => self.cx().lifetimes.re_erased,
125124
}
126125
}

tests/crashes/132882.rs

Lines changed: 0 additions & 13 deletions
This file was deleted.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// Regression test for #132882.
2+
3+
use std::ops::Add;
4+
5+
pub trait Numoid: Sized
6+
where
7+
&'missing Self: Add<Self>,
8+
//~^ ERROR use of undeclared lifetime name `'missing`
9+
{
10+
}
11+
12+
// Proving `N: Numoid`'s well-formedness causes us to have to prove `&'missing N: Add<N>`.
13+
// Since `'missing` is a region error, that will lead to us consider the predicate to hold,
14+
// since it references errors. Since the freshener turns error regions into fresh regions,
15+
// this means that subsequent lookups of `&'?0 N: Add<N>` will also hit this cache entry
16+
// even if candidate assembly can't assemble anything for `&'?0 N: Add<?1>` anyways. This
17+
// led to an ICE.
18+
pub fn compute<N: Numoid>(a: N) {
19+
let _ = &a + a;
20+
//~^ ERROR cannot add `N` to `&N`
21+
}
22+
23+
fn main() {}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
error[E0261]: use of undeclared lifetime name `'missing`
2+
--> $DIR/eval-caching-error-region.rs:7:6
3+
|
4+
LL | &'missing Self: Add<Self>,
5+
| ^^^^^^^^ undeclared lifetime
6+
|
7+
= note: for more information on higher-ranked polymorphism, visit https://doc.rust-lang.org/nomicon/hrtb.html
8+
help: consider making the bound lifetime-generic with a new `'missing` lifetime
9+
|
10+
LL | for<'missing> &'missing Self: Add<Self>,
11+
| +++++++++++++
12+
help: consider introducing lifetime `'missing` here
13+
|
14+
LL | pub trait Numoid<'missing>: Sized
15+
| ++++++++++
16+
17+
error[E0369]: cannot add `N` to `&N`
18+
--> $DIR/eval-caching-error-region.rs:19:16
19+
|
20+
LL | let _ = &a + a;
21+
| -- ^ - N
22+
| |
23+
| &N
24+
|
25+
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
26+
|
27+
LL | pub fn compute<N: Numoid>(a: N) where &N: Add<N> {
28+
| ++++++++++++++++
29+
30+
error: aborting due to 2 previous errors
31+
32+
Some errors have detailed explanations: E0261, E0369.
33+
For more information about an error, try `rustc --explain E0261`.

0 commit comments

Comments
 (0)