Rollup merge of #111490 - compiler-errors:layout-placeholder, r=aliemjay

Don't ICE in layout computation for placeholder types

We use `layout_of` for the built-in `PointerLike` trait to check if a type can be coerced to a `dyn*`.

Since the new solver canonicalizes parameter types to placeholders, that code needs to be able to treat placeholders like params, and for the most part it does, **except** for a call to `is_trivially_sized`. This PR fixes that.
This commit is contained in:
Matthias Krüger 2023-05-12 07:11:14 +02:00 committed by GitHub
commit 4c12f5d252
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 21 additions and 5 deletions

View file

@ -2366,13 +2366,11 @@ impl<'tcx> Ty<'tcx> {
ty::Adt(def, _substs) => def.sized_constraint(tcx).0.is_empty(),
ty::Alias(..) | ty::Param(_) => false,
ty::Alias(..) | ty::Param(_) | ty::Placeholder(..) => false,
ty::Infer(ty::TyVar(_)) => false,
ty::Bound(..)
| ty::Placeholder(..)
| ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
ty::Bound(..) | ty::Infer(ty::FreshTy(_) | ty::FreshIntTy(_) | ty::FreshFloatTy(_)) => {
bug!("`is_trivially_sized` applied to unexpected type: {:?}", self)
}
}

View file

@ -1,5 +1,5 @@
error[E0277]: `&T` needs to have the same ABI as a pointer
--> $DIR/check-size-at-cast-polymorphic-bad.rs:11:15
--> $DIR/check-size-at-cast-polymorphic-bad.rs:14:15
|
LL | dyn_debug(t);
| ^ `&T` needs to be a pointer-like type

View file

@ -0,0 +1,15 @@
error[E0277]: `&T` needs to have the same ABI as a pointer
--> $DIR/check-size-at-cast-polymorphic-bad.rs:14:15
|
LL | dyn_debug(t);
| ^ `&T` needs to be a pointer-like type
|
= help: the trait `PointerLike` is not implemented for `&T`
help: consider introducing a `where` clause, but there might be an alternative better way to express this requirement
|
LL | fn polymorphic<T: Debug + ?Sized>(t: &T) where &T: PointerLike {
| +++++++++++++++++++++
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.

View file

@ -1,3 +1,6 @@
// revisions: current next
//[next] compile-flags: -Ztrait-solver=next
#![feature(dyn_star)]
#![allow(incomplete_features)]