Skip to content

Commit

Permalink
Normalize opaques during codegen in new solver
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed Jul 4, 2023
1 parent 388339f commit 51d7111
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 5 deletions.
4 changes: 1 addition & 3 deletions compiler/rustc_trait_selection/src/solve/normalize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,7 @@ impl<'tcx> FallibleTypeFolder<TyCtxt<'tcx>> for NormalizationFolder<'_, 'tcx> {
// We don't normalize opaque types unless we have
// `Reveal::All`, even if we're in the defining scope.
let data = match *ty.kind() {
ty::Alias(kind, alias_ty) if kind != ty::Opaque || reveal == Reveal::UserFacing => {
alias_ty
}
ty::Alias(kind, alias_ty) if kind != ty::Opaque || reveal == Reveal::All => alias_ty,
_ => return ty.try_super_fold_with(self),
};

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/dyn-star/param-env-region-infer.current.stderr
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
error[E0282]: type annotations needed
--> $DIR/param-env-region-infer.rs:16:10
--> $DIR/param-env-region-infer.rs:17:10
|
LL | t as _
| ^ cannot infer type
Expand Down
55 changes: 55 additions & 0 deletions tests/ui/dyn-star/param-env-region-infer.next.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
error[E0391]: cycle detected when computing type of `make_dyn_star::{opaque#0}`
--> $DIR/param-env-region-infer.rs:14:60
|
LL | fn make_dyn_star<'a, T: PointerLike + Debug + 'a>(t: T) -> impl PointerLike + Debug + 'a {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: ...which requires type-checking `make_dyn_star`...
--> $DIR/param-env-region-infer.rs:14:1
|
LL | fn make_dyn_star<'a, T: PointerLike + Debug + 'a>(t: T) -> impl PointerLike + Debug + 'a {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: ...which requires computing layout of `make_dyn_star::{opaque#0}`...
= note: ...which requires normalizing `make_dyn_star::{opaque#0}`...
= note: ...which again requires computing type of `make_dyn_star::{opaque#0}`, completing the cycle
note: cycle used when checking item types in top-level module
--> $DIR/param-env-region-infer.rs:8:1
|
LL | / #![feature(dyn_star, pointer_like_trait)]
LL | | #![allow(incomplete_features)]
LL | |
LL | | use std::fmt::Debug;
... |
LL | |
LL | | fn main() {}
| |____________^

error[E0391]: cycle detected when computing type of `make_dyn_star::{opaque#0}`
--> $DIR/param-env-region-infer.rs:14:60
|
LL | fn make_dyn_star<'a, T: PointerLike + Debug + 'a>(t: T) -> impl PointerLike + Debug + 'a {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: ...which requires type-checking `make_dyn_star`...
--> $DIR/param-env-region-infer.rs:14:1
|
LL | fn make_dyn_star<'a, T: PointerLike + Debug + 'a>(t: T) -> impl PointerLike + Debug + 'a {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
= note: ...which requires computing layout of `make_dyn_star::{opaque#0}`...
= note: ...which requires normalizing `make_dyn_star::{opaque#0}`...
= note: ...which again requires computing type of `make_dyn_star::{opaque#0}`, completing the cycle
note: cycle used when checking item types in top-level module
--> $DIR/param-env-region-infer.rs:8:1
|
LL | / #![feature(dyn_star, pointer_like_trait)]
LL | | #![allow(incomplete_features)]
LL | |
LL | | use std::fmt::Debug;
... |
LL | |
LL | | fn main() {}
| |____________^

error: aborting due to 2 previous errors

For more information about this error, try `rustc --explain E0391`.
3 changes: 2 additions & 1 deletion tests/ui/dyn-star/param-env-region-infer.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// revisions: current next
//[next] compile-flags: -Ztrait-solver=next
//[next] check-pass
// incremental

// checks that we don't ICE if there are region inference variables in the environment
Expand All @@ -13,6 +12,8 @@ use std::fmt::Debug;
use std::marker::PointerLike;

fn make_dyn_star<'a, T: PointerLike + Debug + 'a>(t: T) -> impl PointerLike + Debug + 'a {
//[next]~^ ERROR cycle detected when computing
//[next]~| ERROR cycle detected when computing
t as _
//[current]~^ ERROR type annotations needed
}
Expand Down
11 changes: 11 additions & 0 deletions tests/ui/impl-trait/reveal-during-codegen.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// build-pass
// revisions: current next
//[next] compile-flags: -Ztrait-solver=next

fn test() -> Option<impl Sized> {
Some("")
}

fn main() {
test();
}

0 comments on commit 51d7111

Please sign in to comment.