Skip to content

Commit 13a36d0

Browse files
authored
Rollup merge of rust-lang#108176 - compiler-errors:bad-lexical-region-resolve-bug, r=oli-obk
Don't delay `ReError` bug during lexical region resolve Lexical region resolution returns a list of `RegionResolutionError` which don't necessarily correspond to diagnostics being emitted. The compiler may, validly, throw away these resolution errors and do something else. Therefore it's not valid to use `ReError` during lifetime resolution, since we may actually be on a totally fine compilation path. For example, the `implied_bounds_entailment` lint runs region resolution twice, and only emits an error if it fails both times. If we delay a bug and create a `ReError` during this first run, then we will ICE. Fixes rust-lang#108170 ---- Side-note: this is conceptually equivalent to how we can't necessarily delay bugs or create `ty::Error` during trait solving/fulfillment, since the compiler is allowed to throw away these fulfillment errors to do other things. It's only once we actually emit an error (`report_region_errors` / `report_fulfillment_errors`)
2 parents e57a494 + 90cf0cc commit 13a36d0

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -1046,7 +1046,7 @@ impl<'tcx> LexicalRegionResolutions<'tcx> {
10461046
ty::ReVar(rid) => match self.values[rid] {
10471047
VarValue::Empty(_) => r,
10481048
VarValue::Value(r) => r,
1049-
VarValue::ErrorValue => tcx.mk_re_error_misc(),
1049+
VarValue::ErrorValue => tcx.lifetimes.re_static,
10501050
},
10511051
_ => r,
10521052
};
+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// check-pass
2+
3+
// Allow this for now, can remove this UI test when this becomes a hard error.
4+
#![allow(implied_bounds_entailment)]
5+
6+
use std::collections::hash_map::{Keys, HashMap};
7+
use std::marker::PhantomData;
8+
9+
trait MapAssertion<'a, K, V, R> {
10+
fn key_set(&self) -> Subject<Keys<K, V>, (), R>;
11+
}
12+
13+
struct Subject<'a, T, V, R>(PhantomData<(&'a T, V, R)>);
14+
15+
impl<'a, K, V, R> MapAssertion<'a, K, V, R> for Subject<'a, HashMap<K, V>, (), R>
16+
{
17+
fn key_set(&self) -> Subject<'a, Keys<K, V>, (), R> {
18+
todo!()
19+
}
20+
}
21+
22+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
Future incompatibility report: Future breakage diagnostic:
2+
warning: impl method assumes more implied bounds than the corresponding trait method
3+
--> $DIR/resolve-re-error-ice.rs:17:16
4+
|
5+
LL | fn key_set(&self) -> Subject<'a, Keys<K, V>, (), R> {
6+
| ^^^^^ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace this type to make the impl signature compatible: `Subject<'_, std::collections::hash_map::Keys<'_, K, V>, (), R>`
7+
|
8+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
9+
= note: for more information, see issue #105572 <https://github.com/rust-lang/rust/issues/105572>
10+
note: the lint level is defined here
11+
--> $DIR/resolve-re-error-ice.rs:4:10
12+
|
13+
LL | #![allow(implied_bounds_entailment)]
14+
| ^^^^^^^^^^^^^^^^^^^^^^^^^
15+

0 commit comments

Comments
 (0)