Skip to content

Commit 92f40b8

Browse files
committed
fix ICE in check_unique
1 parent 73476d4 commit 92f40b8

File tree

3 files changed

+39
-2
lines changed

3 files changed

+39
-2
lines changed

compiler/rustc_borrowck/src/region_infer/opaque_types.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,18 @@ impl<'tcx> RegionInferenceContext<'tcx> {
6969
continue;
7070
}
7171

72+
// Ignore non-universal regions because they result in an error eventually.
73+
// FIXME(aliemjay): This logic will be rewritten in a later commit.
74+
let Some(r1) = self.universal_name(r1) else {
75+
continue;
76+
};
77+
let Some(r2) = self.universal_name(r2) else {
78+
continue;
79+
};
80+
7281
infcx.dcx().emit_err(LifetimeMismatchOpaqueParam {
73-
arg: self.universal_name(r1).unwrap().into(),
74-
prev: self.universal_name(r2).unwrap().into(),
82+
arg: r1.into(),
83+
prev: r2.into(),
7584
span: a_ty.span,
7685
prev_span: b_ty.span,
7786
});
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//! This test checks that when checking for opaque types that
2+
//! only differ in lifetimes, we handle the case of non-generic
3+
//! regions correctly.
4+
#![feature(type_alias_impl_trait)]
5+
6+
type Opq<'a> = impl Sized;
7+
8+
// Two defining uses: Opq<'{empty}> and Opq<'a>.
9+
// This used to ICE.
10+
// issue: #122782
11+
fn build<'a>() -> Opq<'a> {
12+
let _: Opq<'_> = ();
13+
//~^ ERROR expected generic lifetime parameter, found `'_`
14+
}
15+
16+
fn main() {}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
error[E0792]: expected generic lifetime parameter, found `'_`
2+
--> $DIR/param_mismatch4.rs:12:12
3+
|
4+
LL | type Opq<'a> = impl Sized;
5+
| -- this generic parameter must be used with a generic lifetime parameter
6+
...
7+
LL | let _: Opq<'_> = ();
8+
| ^^^^^^^
9+
10+
error: aborting due to 1 previous error
11+
12+
For more information about this error, try `rustc --explain E0792`.

0 commit comments

Comments
 (0)