Skip to content

Commit a72013f

Browse files
committed
instantiate hidden types in root universe
1 parent 8091736 commit a72013f

File tree

5 files changed

+135
-3
lines changed

5 files changed

+135
-3
lines changed

compiler/rustc_borrowck/src/type_check/mod.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ use rustc_mir_dataflow::impls::MaybeInitializedPlaces;
5050
use rustc_mir_dataflow::move_paths::MoveData;
5151
use rustc_mir_dataflow::ResultsCursor;
5252

53-
use crate::renumber::RegionCtxt;
5453
use crate::session_diagnostics::MoveUnsized;
5554
use crate::{
5655
borrow_set::BorrowSet,
@@ -1041,9 +1040,9 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> {
10411040
.collect();
10421041

10431042
let renumbered_opaques = self.infcx.tcx.fold_regions(opaques, |_, _| {
1044-
self.infcx.next_nll_region_var(
1043+
self.infcx.next_nll_region_var_in_universe(
10451044
NllRegionVariableOrigin::Existential { from_forall: false },
1046-
|| RegionCtxt::Unknown,
1045+
ty::UniverseIndex::ROOT,
10471046
)
10481047
});
10491048

compiler/rustc_infer/src/infer/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1474,6 +1474,7 @@ impl<'tcx> InferCtxt<'tcx> {
14741474
/// universes. Updates `self.universe` to that new universe.
14751475
pub fn create_next_universe(&self) -> ty::UniverseIndex {
14761476
let u = self.universe.get().next_universe();
1477+
debug!("create_next_universe {u:?}");
14771478
self.universe.set(u);
14781479
u
14791480
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// compile-flags: -Ztrait-solver=next
2+
// check-pass
3+
4+
trait Trait {
5+
type Ty;
6+
}
7+
8+
impl Trait for for<'a> fn(&'a u8, &'a u8) {
9+
type Ty = ();
10+
}
11+
12+
// argument is necessary to create universes before registering the hidden type.
13+
fn test<'a>(_: <fn(&u8, &u8) as Trait>::Ty) -> impl Sized {
14+
"hidden type is `&'?0 str` with '?0 member of ['static,]"
15+
}
16+
17+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
error: concrete type differs from previous defining opaque type use
2+
--> $DIR/normalize-hidden-types.rs:25:20
3+
|
4+
LL | fn define() -> Opaque {
5+
| ^^^^^^ expected `*const (dyn FnOnce(()) + 'static)`, got `*const dyn for<'a> FnOnce(<u8 as Trait>::Gat<'a>)`
6+
|
7+
note: previous use here
8+
--> $DIR/normalize-hidden-types.rs:27:9
9+
|
10+
LL | dyn_hoops::<_>(0)
11+
| ^^^^^^^^^^^^^^^^^
12+
13+
error: concrete type differs from previous defining opaque type use
14+
--> $DIR/normalize-hidden-types.rs:34:22
15+
|
16+
LL | fn define_1() -> Opaque { dyn_hoops::<_>(0) }
17+
| ^^^^^^ expected `*const (dyn FnOnce(()) + 'static)`, got `*const dyn for<'a> FnOnce(<u8 as Trait>::Gat<'a>)`
18+
|
19+
note: previous use here
20+
--> $DIR/normalize-hidden-types.rs:34:31
21+
|
22+
LL | fn define_1() -> Opaque { dyn_hoops::<_>(0) }
23+
| ^^^^^^^^^^^^^^^^^
24+
25+
error[E0308]: mismatched types
26+
--> $DIR/normalize-hidden-types.rs:44:25
27+
|
28+
LL | type Opaque = impl Sized;
29+
| ---------- the expected opaque type
30+
...
31+
LL | let _: Opaque = dyn_hoops::<u8>(0);
32+
| ------ ^^^^^^^^^^^^^^^^^^ expected opaque type, found `*const dyn FnOnce(())`
33+
| |
34+
| expected due to this
35+
|
36+
= note: expected opaque type `typeck::Opaque`
37+
found raw pointer `*const (dyn FnOnce(()) + 'static)`
38+
= help: consider constraining the associated type `<u8 as Trait>::Gat<'_>` to `()` or calling a method that returns `<u8 as Trait>::Gat<'_>`
39+
= note: for more information, visit https://doc.rust-lang.org/book/ch19-03-advanced-traits.html
40+
41+
error: concrete type differs from previous defining opaque type use
42+
--> $DIR/normalize-hidden-types.rs:54:25
43+
|
44+
LL | let _: Opaque = dyn_hoops::<_>(0);
45+
| ^^^^^^^^^^^^^^^^^ expected `*const (dyn FnOnce(()) + 'static)`, got `*const dyn for<'a> FnOnce(<u8 as Trait>::Gat<'a>)`
46+
|
47+
note: previous use here
48+
--> $DIR/normalize-hidden-types.rs:56:9
49+
|
50+
LL | None
51+
| ^^^^
52+
53+
error: aborting due to 4 previous errors
54+
55+
For more information about this error, try `rustc --explain E0308`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
// Regression test for #112691
2+
//
3+
// revisions: current next
4+
// [next] compile-flags: -Ztrait-solver=next
5+
// [next] check-pass
6+
// [current]: known-bug: #112691
7+
8+
#![feature(type_alias_impl_trait)]
9+
10+
trait Trait {
11+
type Gat<'lt>;
12+
}
13+
14+
impl Trait for u8 {
15+
type Gat<'lt> = ();
16+
}
17+
18+
fn dyn_hoops<T: Trait>(_: T) -> *const dyn FnOnce(T::Gat<'_>) {
19+
loop {}
20+
}
21+
22+
mod typeof_1 {
23+
use super::*;
24+
type Opaque = impl Sized;
25+
fn define() -> Opaque {
26+
//[current]~^ ERROR concrete type differs
27+
dyn_hoops::<_>(0)
28+
}
29+
}
30+
31+
mod typeof_2 {
32+
use super::*;
33+
type Opaque = impl Sized;
34+
fn define_1() -> Opaque { dyn_hoops::<_>(0) }
35+
//[current]~^ ERROR concrete type differs
36+
fn define_2() -> Opaque { dyn_hoops::<u8>(0) }
37+
}
38+
39+
mod typeck {
40+
use super::*;
41+
type Opaque = impl Sized;
42+
fn define() -> Option<Opaque> {
43+
let _: Opaque = dyn_hoops::<_>(0);
44+
let _: Opaque = dyn_hoops::<u8>(0);
45+
//[current]~^ ERROR mismatched types
46+
None
47+
}
48+
}
49+
50+
mod borrowck {
51+
use super::*;
52+
type Opaque = impl Sized;
53+
fn define() -> Option<Opaque> {
54+
let _: Opaque = dyn_hoops::<_>(0);
55+
//[current]~^ ERROR concrete type differs
56+
None
57+
}
58+
}
59+
60+
fn main() {}

0 commit comments

Comments
 (0)