Strip OpaqueCast
during RevealAll
.
This commit is contained in:
parent
479fa4a74d
commit
6ea2db7c2d
@ -875,7 +875,7 @@ pub(crate) fn codegen_place<'tcx>(
|
||||
PlaceElem::Deref => {
|
||||
cplace = cplace.place_deref(fx);
|
||||
}
|
||||
PlaceElem::OpaqueCast(ty) => cplace = cplace.place_opaque_cast(fx, ty),
|
||||
PlaceElem::OpaqueCast(ty) => bug!("encountered OpaqueCast({ty}) in codegen"),
|
||||
PlaceElem::Field(field, _ty) => {
|
||||
cplace = cplace.place_field(fx, field);
|
||||
}
|
||||
|
@ -463,7 +463,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
|
||||
mir::ProjectionElem::Field(ref field, _) => {
|
||||
cg_base.project_field(bx, field.index())
|
||||
}
|
||||
mir::ProjectionElem::OpaqueCast(ty) => cg_base.project_type(bx, ty),
|
||||
mir::ProjectionElem::OpaqueCast(ty) => {
|
||||
bug!("encountered OpaqueCast({ty}) in codegen")
|
||||
}
|
||||
mir::ProjectionElem::Index(index) => {
|
||||
let index = &mir::Operand::Copy(mir::Place::from(index));
|
||||
let index = self.codegen_operand(bx, index);
|
||||
|
@ -316,7 +316,7 @@ where
|
||||
{
|
||||
use rustc_middle::mir::ProjectionElem::*;
|
||||
Ok(match proj_elem {
|
||||
OpaqueCast(ty) => base.transmute(self.layout_of(ty)?, self)?,
|
||||
OpaqueCast(ty) => bug!("OpaqueCast({ty}) encountered after borrowck"),
|
||||
Field(field, _) => self.project_field(base, field.index())?,
|
||||
Downcast(_, variant) => self.project_downcast(base, variant)?,
|
||||
Deref => self.deref_pointer(&base.to_op(self)?)?.into(),
|
||||
|
@ -25,6 +25,25 @@ impl<'tcx> MutVisitor<'tcx> for RevealAllVisitor<'tcx> {
|
||||
self.tcx
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn visit_place(
|
||||
&mut self,
|
||||
place: &mut Place<'tcx>,
|
||||
_context: PlaceContext,
|
||||
_location: Location,
|
||||
) {
|
||||
// `OpaqueCast` projections are only needed if there are opaque types on which projections are performed.
|
||||
// After the `RevealAll` pass, all opaque types are replaced with their hidden types, so we don't need these
|
||||
// projections anymore.
|
||||
place.projection = self.tcx.mk_place_elems(
|
||||
&place
|
||||
.projection
|
||||
.into_iter()
|
||||
.filter(|elem| !matches!(elem, ProjectionElem::OpaqueCast(_)))
|
||||
.collect::<Vec<_>>(),
|
||||
);
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn visit_constant(&mut self, constant: &mut ConstOperand<'tcx>, _: Location) {
|
||||
// We have to use `try_normalize_erasing_regions` here, since it's
|
||||
|
@ -2,7 +2,7 @@ error[E0391]: cycle detected when computing layout of `{async fn body@$DIR/indir
|
||||
|
|
||||
= note: ...which requires computing layout of `<<A as First>::Second as Second>::{opaque#0}`...
|
||||
= note: ...which again requires computing layout of `{async fn body@$DIR/indirect-recursion-issue-112047.rs:35:27: 37:6}`, completing the cycle
|
||||
= note: cycle used when computing layout of `<impl at $DIR/indirect-recursion-issue-112047.rs:31:1: 31:21>::second::{opaque#0}`
|
||||
= note: cycle used when computing layout of `{async block@$DIR/indirect-recursion-issue-112047.rs:8:13: 10:6}`
|
||||
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
|
||||
|
||||
error: aborting due to previous error
|
||||
|
@ -32,7 +32,6 @@ where
|
||||
|
||||
#[rustc_polymorphize_error]
|
||||
pub fn unused_type<T>() -> impl Generator<(), Yield = u32, Return = u32> + Unpin {
|
||||
//~^ ERROR item has unused generic parameters
|
||||
|| {
|
||||
//~^ ERROR item has unused generic parameters
|
||||
yield 1;
|
||||
@ -58,7 +57,6 @@ pub fn used_type_in_return<R: Default>() -> impl Generator<(), Yield = u32, Retu
|
||||
|
||||
#[rustc_polymorphize_error]
|
||||
pub fn unused_const<const T: u32>() -> impl Generator<(), Yield = u32, Return = u32> + Unpin {
|
||||
//~^ ERROR item has unused generic parameters
|
||||
|| {
|
||||
//~^ ERROR item has unused generic parameters
|
||||
yield 1;
|
||||
|
@ -8,34 +8,20 @@ LL | #![feature(generic_const_exprs, generators, generator_trait, rustc_attrs)]
|
||||
= note: `#[warn(incomplete_features)]` on by default
|
||||
|
||||
error: item has unused generic parameters
|
||||
--> $DIR/generators.rs:36:5
|
||||
--> $DIR/generators.rs:35:5
|
||||
|
|
||||
LL | pub fn unused_type<T>() -> impl Generator<(), Yield = u32, Return = u32> + Unpin {
|
||||
| - generic parameter `T` is unused
|
||||
LL |
|
||||
LL | || {
|
||||
| ^^
|
||||
|
||||
error: item has unused generic parameters
|
||||
--> $DIR/generators.rs:34:8
|
||||
|
|
||||
LL | pub fn unused_type<T>() -> impl Generator<(), Yield = u32, Return = u32> + Unpin {
|
||||
| ^^^^^^^^^^^ - generic parameter `T` is unused
|
||||
|
||||
error: item has unused generic parameters
|
||||
--> $DIR/generators.rs:62:5
|
||||
--> $DIR/generators.rs:60:5
|
||||
|
|
||||
LL | pub fn unused_const<const T: u32>() -> impl Generator<(), Yield = u32, Return = u32> + Unpin {
|
||||
| ------------ generic parameter `T` is unused
|
||||
LL |
|
||||
LL | || {
|
||||
| ^^
|
||||
|
||||
error: item has unused generic parameters
|
||||
--> $DIR/generators.rs:60:8
|
||||
|
|
||||
LL | pub fn unused_const<const T: u32>() -> impl Generator<(), Yield = u32, Return = u32> + Unpin {
|
||||
| ^^^^^^^^^^^^ ------------ generic parameter `T` is unused
|
||||
|
||||
error: aborting due to 4 previous errors; 1 warning emitted
|
||||
error: aborting due to 2 previous errors; 1 warning emitted
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
// compile-flags: --edition=2021
|
||||
// check-pass
|
||||
// build-pass
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
fn main() {
|
||||
|
@ -0,0 +1,23 @@
|
||||
// build-pass
|
||||
// edition: 2021
|
||||
|
||||
#![feature(type_alias_impl_trait)]
|
||||
|
||||
fn foo<T>(x: T) {
|
||||
type Opaque<T> = impl Sized;
|
||||
let foo: Opaque<T> = (x,);
|
||||
let (a,): (T,) = foo;
|
||||
}
|
||||
|
||||
const fn bar<T: Copy>(x: T) {
|
||||
type Opaque<T: Copy> = impl Copy;
|
||||
let foo: Opaque<T> = (x, 2u32);
|
||||
let (a, b): (T, u32) = foo;
|
||||
}
|
||||
|
||||
fn main() {
|
||||
foo::<u32>(1);
|
||||
bar::<u32>(1);
|
||||
const CONST: () = bar::<u32>(42u32);
|
||||
CONST
|
||||
}
|
@ -1,6 +1,5 @@
|
||||
error[E0391]: cycle detected when computing layout of `{async block@$DIR/indirect-recursion-issue-112047.rs:23:9: 23:42}`
|
||||
|
|
||||
= note: ...which requires computing layout of `core::mem::maybe_uninit::MaybeUninit<recur::{opaque#0}>`...
|
||||
= note: ...which requires computing layout of `core::mem::maybe_uninit::MaybeUninit<{async fn body@$DIR/indirect-recursion-issue-112047.rs:15:31: 17:2}>`...
|
||||
= note: ...which requires computing layout of `core::mem::manually_drop::ManuallyDrop<{async fn body@$DIR/indirect-recursion-issue-112047.rs:15:31: 17:2}>`...
|
||||
= note: ...which requires computing layout of `{async fn body@$DIR/indirect-recursion-issue-112047.rs:15:31: 17:2}`...
|
||||
@ -8,7 +7,11 @@ error[E0391]: cycle detected when computing layout of `{async block@$DIR/indirec
|
||||
= note: ...which requires computing layout of `core::mem::maybe_uninit::MaybeUninit<{async block@$DIR/indirect-recursion-issue-112047.rs:23:9: 23:42}>`...
|
||||
= note: ...which requires computing layout of `core::mem::manually_drop::ManuallyDrop<{async block@$DIR/indirect-recursion-issue-112047.rs:23:9: 23:42}>`...
|
||||
= note: ...which again requires computing layout of `{async block@$DIR/indirect-recursion-issue-112047.rs:23:9: 23:42}`, completing the cycle
|
||||
= note: cycle used when computing layout of `<impl at $DIR/indirect-recursion-issue-112047.rs:19:1: 19:18>::Recur`
|
||||
note: cycle used when elaborating drops for `<impl at $DIR/indirect-recursion-issue-112047.rs:19:1: 19:18>::recur`
|
||||
--> $DIR/indirect-recursion-issue-112047.rs:22:5
|
||||
|
|
||||
LL | fn recur(self) -> Self::Recur {
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
= note: see https://rustc-dev-guide.rust-lang.org/overview.html#queries and https://rustc-dev-guide.rust-lang.org/query.html for more information
|
||||
|
||||
error: aborting due to previous error
|
||||
|
Loading…
x
Reference in New Issue
Block a user