report unconstrained region in hidden types lazily

This commit is contained in:
Adwin White 2026-01-31 16:20:09 +08:00
parent be4794c78b
commit 20c46d647f
5 changed files with 198 additions and 13 deletions

View file

@ -0,0 +1,21 @@
//@ check-pass
//@ compile-flags: -Znext-solver
// Regression test for trait-system-refactor-initiative#264.
//
// Some defining uses of opaque types can't constrain captured regions to universals.
// Previouly, we eagerly report error in this case.
// Now we report error only if there's no fully defining use from all bodies of the typeck root.
struct Inv<'a>(*mut &'a ());
fn mk_static() -> Inv<'static> { todo!() }
fn guide_closure_sig<'a>(f: impl FnOnce() -> Inv<'a>) {}
fn unconstrained_in_closure() -> impl Sized {
guide_closure_sig(|| unconstrained_in_closure());
mk_static()
}
fn main() {}

View file

@ -0,0 +1,34 @@
//@ compile-flags: -Znext-solver
// Just for diagnostics completeness.
// This is probably unimportant as we only report one error for such case in HIR typeck.
#![feature(type_alias_impl_trait)]
struct Invar<'a>(*mut &'a ());
fn mk_invar<'a>(a: &'a i32) -> Invar<'a> {
todo!()
}
type MultiUse = impl Sized;
#[define_opaque(MultiUse)]
fn capture_different_universals_not_on_bounds<'a, 'b, 'c>(a: &'a i32, b: &'b i32, c: &'c i32) {
let _ = || -> MultiUse {
//~^ ERROR: hidden type for `MultiUse` captures lifetime that does not appear in bounds [E0700]
mk_invar(a)
};
let _ = || -> MultiUse {
//~^ ERROR: hidden type for `MultiUse` captures lifetime that does not appear in bounds [E0700]
mk_invar(b)
};
let _ = || {
let _ = || -> MultiUse {
//~^ ERROR: hidden type for `MultiUse` captures lifetime that does not appear in bounds [E0700]
mk_invar(c)
};
};
}
fn main() {}

View file

@ -0,0 +1,36 @@
error[E0700]: hidden type for `MultiUse` captures lifetime that does not appear in bounds
--> $DIR/report-all-unexpected-hidden-errors.rs:18:19
|
LL | type MultiUse = impl Sized;
| ---------- opaque type defined here
...
LL | let _ = || -> MultiUse {
| ^^^^^^^^
|
= note: hidden type `Invar<'_>` captures lifetime `'_`
error[E0700]: hidden type for `MultiUse` captures lifetime that does not appear in bounds
--> $DIR/report-all-unexpected-hidden-errors.rs:22:19
|
LL | type MultiUse = impl Sized;
| ---------- opaque type defined here
...
LL | let _ = || -> MultiUse {
| ^^^^^^^^
|
= note: hidden type `Invar<'_>` captures lifetime `'_`
error[E0700]: hidden type for `MultiUse` captures lifetime that does not appear in bounds
--> $DIR/report-all-unexpected-hidden-errors.rs:27:23
|
LL | type MultiUse = impl Sized;
| ---------- opaque type defined here
...
LL | let _ = || -> MultiUse {
| ^^^^^^^^
|
= note: hidden type `Invar<'_>` captures lifetime `'_`
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0700`.