From 92f40b8059096c8cc868c1116a31a6d2eea8bc71 Mon Sep 17 00:00:00 2001 From: Ali MJ Al-Nasrawy Date: Thu, 21 Mar 2024 03:04:49 +0000 Subject: [PATCH] fix ICE in check_unique --- .../src/region_infer/opaque_types.rs | 13 +++++++++++-- .../ui/type-alias-impl-trait/param_mismatch4.rs | 16 ++++++++++++++++ .../type-alias-impl-trait/param_mismatch4.stderr | 12 ++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 tests/ui/type-alias-impl-trait/param_mismatch4.rs create mode 100644 tests/ui/type-alias-impl-trait/param_mismatch4.stderr diff --git a/compiler/rustc_borrowck/src/region_infer/opaque_types.rs b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs index d5875a226fe..49f7242cd83 100644 --- a/compiler/rustc_borrowck/src/region_infer/opaque_types.rs +++ b/compiler/rustc_borrowck/src/region_infer/opaque_types.rs @@ -69,9 +69,18 @@ fn check_unique( continue; } + // Ignore non-universal regions because they result in an error eventually. + // FIXME(aliemjay): This logic will be rewritten in a later commit. + let Some(r1) = self.universal_name(r1) else { + continue; + }; + let Some(r2) = self.universal_name(r2) else { + continue; + }; + infcx.dcx().emit_err(LifetimeMismatchOpaqueParam { - arg: self.universal_name(r1).unwrap().into(), - prev: self.universal_name(r2).unwrap().into(), + arg: r1.into(), + prev: r2.into(), span: a_ty.span, prev_span: b_ty.span, }); diff --git a/tests/ui/type-alias-impl-trait/param_mismatch4.rs b/tests/ui/type-alias-impl-trait/param_mismatch4.rs new file mode 100644 index 00000000000..e072f3ab8e0 --- /dev/null +++ b/tests/ui/type-alias-impl-trait/param_mismatch4.rs @@ -0,0 +1,16 @@ +//! This test checks that when checking for opaque types that +//! only differ in lifetimes, we handle the case of non-generic +//! regions correctly. +#![feature(type_alias_impl_trait)] + +type Opq<'a> = impl Sized; + +// Two defining uses: Opq<'{empty}> and Opq<'a>. +// This used to ICE. +// issue: #122782 +fn build<'a>() -> Opq<'a> { + let _: Opq<'_> = (); + //~^ ERROR expected generic lifetime parameter, found `'_` +} + +fn main() {} diff --git a/tests/ui/type-alias-impl-trait/param_mismatch4.stderr b/tests/ui/type-alias-impl-trait/param_mismatch4.stderr new file mode 100644 index 00000000000..d3fdea25a3d --- /dev/null +++ b/tests/ui/type-alias-impl-trait/param_mismatch4.stderr @@ -0,0 +1,12 @@ +error[E0792]: expected generic lifetime parameter, found `'_` + --> $DIR/param_mismatch4.rs:12:12 + | +LL | type Opq<'a> = impl Sized; + | -- this generic parameter must be used with a generic lifetime parameter +... +LL | let _: Opq<'_> = (); + | ^^^^^^^ + +error: aborting due to 1 previous error + +For more information about this error, try `rustc --explain E0792`.