mirror of
https://github.com/rust-lang/rust.git
synced 2025-04-28 02:57:37 +00:00
shim: adjust valid shim asserts
This commit makes valid shim asserts more specific - checking for the specific types that are valid for a given type of shim - and removes asserts for types which require substitutions. Signed-off-by: David Wood <david@davidtw.co>
This commit is contained in:
parent
19e849516e
commit
47756bb0fa
@ -4,7 +4,7 @@ use rustc_hir::lang_items::FnMutTraitLangItem;
|
||||
use rustc_middle::mir::*;
|
||||
use rustc_middle::ty::query::Providers;
|
||||
use rustc_middle::ty::subst::{InternalSubsts, Subst};
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt, TypeFoldable};
|
||||
use rustc_middle::ty::{self, Ty, TyCtxt};
|
||||
use rustc_target::abi::VariantIdx;
|
||||
|
||||
use rustc_index::vec::{Idx, IndexVec};
|
||||
@ -36,11 +36,6 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> Body<'
|
||||
build_call_shim(tcx, instance, Some(Adjustment::Deref), CallKind::Direct(def_id), None)
|
||||
}
|
||||
ty::InstanceDef::FnPtrShim(def_id, ty) => {
|
||||
// FIXME(eddyb) support generating shims for a "shallow type",
|
||||
// e.g. `Foo<_>` or `[_]` instead of requiring a fully monomorphic
|
||||
// `Foo<Bar>` or `[String]` etc.
|
||||
assert!(!ty.needs_subst());
|
||||
|
||||
let trait_ = tcx.trait_of_item(def_id).unwrap();
|
||||
let adjustment = match tcx.fn_trait_kind_from_lang_item(trait_) {
|
||||
Some(ty::ClosureKind::FnOnce) => Adjustment::Identity,
|
||||
@ -83,22 +78,8 @@ fn make_shim<'tcx>(tcx: TyCtxt<'tcx>, instance: ty::InstanceDef<'tcx>) -> Body<'
|
||||
None,
|
||||
)
|
||||
}
|
||||
ty::InstanceDef::DropGlue(def_id, ty) => {
|
||||
// FIXME(eddyb) support generating shims for a "shallow type",
|
||||
// e.g. `Foo<_>` or `[_]` instead of requiring a fully monomorphic
|
||||
// `Foo<Bar>` or `[String]` etc.
|
||||
assert!(!ty.needs_subst());
|
||||
|
||||
build_drop_shim(tcx, def_id, ty)
|
||||
}
|
||||
ty::InstanceDef::CloneShim(def_id, ty) => {
|
||||
// FIXME(eddyb) support generating shims for a "shallow type",
|
||||
// e.g. `Foo<_>` or `[_]` instead of requiring a fully monomorphic
|
||||
// `Foo<Bar>` or `[String]` etc.
|
||||
assert!(!ty.needs_subst());
|
||||
|
||||
build_clone_shim(tcx, def_id, ty)
|
||||
}
|
||||
ty::InstanceDef::DropGlue(def_id, ty) => build_drop_shim(tcx, def_id, ty),
|
||||
ty::InstanceDef::CloneShim(def_id, ty) => build_clone_shim(tcx, def_id, ty),
|
||||
ty::InstanceDef::Virtual(..) => {
|
||||
bug!("InstanceDef::Virtual ({:?}) is for direct calls only", instance)
|
||||
}
|
||||
|
@ -3,7 +3,7 @@ use rustc_hir::def_id::{DefId, LocalDefId};
|
||||
use rustc_infer::infer::TyCtxtInferExt;
|
||||
use rustc_middle::ty::subst::SubstsRef;
|
||||
use rustc_middle::ty::{self, Instance, TyCtxt, TypeFoldable};
|
||||
use rustc_span::sym;
|
||||
use rustc_span::{sym, DUMMY_SP};
|
||||
use rustc_target::spec::abi::Abi;
|
||||
use rustc_trait_selection::traits;
|
||||
use traits::{translate_substs, Reveal};
|
||||
@ -67,12 +67,19 @@ fn inner_resolve_instance<'tcx>(
|
||||
let ty = substs.type_at(0);
|
||||
|
||||
if ty.needs_drop(tcx, param_env) {
|
||||
// `DropGlue` requires a monomorphic aka concrete type.
|
||||
if ty.needs_subst() {
|
||||
return Ok(None);
|
||||
debug!(" => nontrivial drop glue");
|
||||
match ty.kind {
|
||||
ty::Closure(..)
|
||||
| ty::Generator(..)
|
||||
| ty::Tuple(..)
|
||||
| ty::Adt(..)
|
||||
| ty::Dynamic(..)
|
||||
| ty::Array(..)
|
||||
| ty::Slice(..) => {}
|
||||
// Drop shims can only be built from ADTs.
|
||||
_ => return Ok(None),
|
||||
}
|
||||
|
||||
debug!(" => nontrivial drop glue");
|
||||
ty::InstanceDef::DropGlue(def_id, Some(ty))
|
||||
} else {
|
||||
debug!(" => trivial drop glue");
|
||||
@ -224,17 +231,13 @@ fn resolve_associated_item<'tcx>(
|
||||
trait_closure_kind,
|
||||
))
|
||||
}
|
||||
traits::ImplSourceFnPointer(ref data) => {
|
||||
// `FnPtrShim` requires a monomorphic aka concrete type.
|
||||
if data.fn_ty.needs_subst() {
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
Some(Instance {
|
||||
traits::ImplSourceFnPointer(ref data) => match data.fn_ty.kind {
|
||||
ty::FnDef(..) | ty::FnPtr(..) => Some(Instance {
|
||||
def: ty::InstanceDef::FnPtrShim(trait_item.def_id, data.fn_ty),
|
||||
substs: rcvr_substs,
|
||||
})
|
||||
}
|
||||
}),
|
||||
_ => None,
|
||||
},
|
||||
traits::ImplSourceObject(ref data) => {
|
||||
let index = traits::get_vtable_index_of_object_method(tcx, data, def_id);
|
||||
Some(Instance { def: ty::InstanceDef::Virtual(def_id, index), substs: rcvr_substs })
|
||||
@ -246,10 +249,12 @@ fn resolve_associated_item<'tcx>(
|
||||
if name == sym::clone {
|
||||
let self_ty = trait_ref.self_ty();
|
||||
|
||||
// `CloneShim` requires a monomorphic aka concrete type.
|
||||
if self_ty.needs_subst() {
|
||||
return Ok(None);
|
||||
}
|
||||
let is_copy = self_ty.is_copy_modulo_regions(tcx.at(DUMMY_SP), param_env);
|
||||
match self_ty.kind {
|
||||
_ if is_copy => (),
|
||||
ty::Array(..) | ty::Closure(..) | ty::Tuple(..) => {}
|
||||
_ => return Ok(None),
|
||||
};
|
||||
|
||||
Some(Instance {
|
||||
def: ty::InstanceDef::CloneShim(def_id, self_ty),
|
||||
|
Loading…
Reference in New Issue
Block a user