Move GenericArgKind::as_{type,const,region}
to GenericArg
This commit is contained in:
parent
3f15521396
commit
25b9263b34
5 changed files with 38 additions and 54 deletions
|
@ -1181,7 +1181,7 @@ fn build_generic_type_param_di_nodes<'ll, 'tcx>(
|
||||||
let names = get_parameter_names(cx, generics);
|
let names = get_parameter_names(cx, generics);
|
||||||
let template_params: SmallVec<_> = iter::zip(substs, names)
|
let template_params: SmallVec<_> = iter::zip(substs, names)
|
||||||
.filter_map(|(kind, name)| {
|
.filter_map(|(kind, name)| {
|
||||||
kind.unpack().as_type().map(|ty| {
|
kind.as_type().map(|ty| {
|
||||||
let actual_type =
|
let actual_type =
|
||||||
cx.tcx.normalize_erasing_regions(ParamEnv::reveal_all(), ty);
|
cx.tcx.normalize_erasing_regions(ParamEnv::reveal_all(), ty);
|
||||||
let actual_type_di_node = type_di_node(cx, actual_type);
|
let actual_type_di_node = type_di_node(cx, actual_type);
|
||||||
|
|
|
@ -461,7 +461,7 @@ impl<'ll, 'tcx> DebugInfoMethods<'tcx> for CodegenCx<'ll, 'tcx> {
|
||||||
let names = get_parameter_names(cx, generics);
|
let names = get_parameter_names(cx, generics);
|
||||||
iter::zip(substs, names)
|
iter::zip(substs, names)
|
||||||
.filter_map(|(kind, name)| {
|
.filter_map(|(kind, name)| {
|
||||||
kind.unpack().as_type().map(|ty| {
|
kind.as_type().map(|ty| {
|
||||||
let actual_type =
|
let actual_type =
|
||||||
cx.tcx.normalize_erasing_regions(ParamEnv::reveal_all(), ty);
|
cx.tcx.normalize_erasing_regions(ParamEnv::reveal_all(), ty);
|
||||||
let actual_type_metadata = type_di_node(cx, actual_type);
|
let actual_type_metadata = type_di_node(cx, actual_type);
|
||||||
|
|
|
@ -250,7 +250,7 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> {
|
||||||
|
|
||||||
fn ty_infer(&self, param: Option<&ty::GenericParamDef>, span: Span) -> Ty<'tcx> {
|
fn ty_infer(&self, param: Option<&ty::GenericParamDef>, span: Span) -> Ty<'tcx> {
|
||||||
match param {
|
match param {
|
||||||
Some(param) => self.var_for_def(span, param).unpack().as_type().unwrap(),
|
Some(param) => self.var_for_def(span, param).as_type().unwrap(),
|
||||||
None => self.next_ty_var(TypeVariableOrigin {
|
None => self.next_ty_var(TypeVariableOrigin {
|
||||||
kind: TypeVariableOriginKind::TypeInference,
|
kind: TypeVariableOriginKind::TypeInference,
|
||||||
span,
|
span,
|
||||||
|
@ -265,7 +265,7 @@ impl<'a, 'tcx> AstConv<'tcx> for FnCtxt<'a, 'tcx> {
|
||||||
span: Span,
|
span: Span,
|
||||||
) -> Const<'tcx> {
|
) -> Const<'tcx> {
|
||||||
match param {
|
match param {
|
||||||
Some(param) => self.var_for_def(span, param).unpack().as_const().unwrap(),
|
Some(param) => self.var_for_def(span, param).as_const().unwrap(),
|
||||||
None => self.next_const_var(
|
None => self.next_const_var(
|
||||||
ty,
|
ty,
|
||||||
ConstVariableOrigin { kind: ConstVariableOriginKind::ConstInference, span },
|
ConstVariableOrigin { kind: ConstVariableOriginKind::ConstInference, span },
|
||||||
|
|
|
@ -103,30 +103,6 @@ impl<'tcx> GenericArgKind<'tcx> {
|
||||||
|
|
||||||
GenericArg { ptr: unsafe { NonZeroUsize::new_unchecked(ptr | tag) }, marker: PhantomData }
|
GenericArg { ptr: unsafe { NonZeroUsize::new_unchecked(ptr | tag) }, marker: PhantomData }
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn as_type(self) -> Option<Ty<'tcx>> {
|
|
||||||
match self {
|
|
||||||
GenericArgKind::Type(ty) => Some(ty),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn as_region(self) -> Option<ty::Region<'tcx>> {
|
|
||||||
match self {
|
|
||||||
GenericArgKind::Lifetime(re) => Some(re),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#[inline]
|
|
||||||
pub fn as_const(self) -> Option<ty::Const<'tcx>> {
|
|
||||||
match self {
|
|
||||||
GenericArgKind::Const(ct) => Some(ct),
|
|
||||||
_ => None,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> fmt::Debug for GenericArg<'tcx> {
|
impl<'tcx> fmt::Debug for GenericArg<'tcx> {
|
||||||
|
@ -204,30 +180,45 @@ impl<'tcx> GenericArg<'tcx> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn as_type(self) -> Option<Ty<'tcx>> {
|
||||||
|
match self.unpack() {
|
||||||
|
GenericArgKind::Type(ty) => Some(ty),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn as_region(self) -> Option<ty::Region<'tcx>> {
|
||||||
|
match self.unpack() {
|
||||||
|
GenericArgKind::Lifetime(re) => Some(re),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[inline]
|
||||||
|
pub fn as_const(self) -> Option<ty::Const<'tcx>> {
|
||||||
|
match self.unpack() {
|
||||||
|
GenericArgKind::Const(ct) => Some(ct),
|
||||||
|
_ => None,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Unpack the `GenericArg` as a region when it is known certainly to be a region.
|
/// Unpack the `GenericArg` as a region when it is known certainly to be a region.
|
||||||
pub fn expect_region(self) -> ty::Region<'tcx> {
|
pub fn expect_region(self) -> ty::Region<'tcx> {
|
||||||
match self.unpack() {
|
self.as_region().unwrap_or_else(|| bug!("expected a region, but found another kind"))
|
||||||
GenericArgKind::Lifetime(lt) => lt,
|
|
||||||
_ => bug!("expected a region, but found another kind"),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Unpack the `GenericArg` as a type when it is known certainly to be a type.
|
/// Unpack the `GenericArg` as a type when it is known certainly to be a type.
|
||||||
/// This is true in cases where `Substs` is used in places where the kinds are known
|
/// This is true in cases where `Substs` is used in places where the kinds are known
|
||||||
/// to be limited (e.g. in tuples, where the only parameters are type parameters).
|
/// to be limited (e.g. in tuples, where the only parameters are type parameters).
|
||||||
pub fn expect_ty(self) -> Ty<'tcx> {
|
pub fn expect_ty(self) -> Ty<'tcx> {
|
||||||
match self.unpack() {
|
self.as_type().unwrap_or_else(|| bug!("expected a type, but found another kind"))
|
||||||
GenericArgKind::Type(ty) => ty,
|
|
||||||
_ => bug!("expected a type, but found another kind"),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Unpack the `GenericArg` as a const when it is known certainly to be a const.
|
/// Unpack the `GenericArg` as a const when it is known certainly to be a const.
|
||||||
pub fn expect_const(self) -> ty::Const<'tcx> {
|
pub fn expect_const(self) -> ty::Const<'tcx> {
|
||||||
match self.unpack() {
|
self.as_const().unwrap_or_else(|| bug!("expected a const, but found another kind"))
|
||||||
GenericArgKind::Const(c) => c,
|
|
||||||
_ => bug!("expected a const, but found another kind"),
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn is_non_region_infer(self) -> bool {
|
pub fn is_non_region_infer(self) -> bool {
|
||||||
|
@ -403,17 +394,17 @@ impl<'tcx> InternalSubsts<'tcx> {
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn types(&'tcx self) -> impl DoubleEndedIterator<Item = Ty<'tcx>> + 'tcx {
|
pub fn types(&'tcx self) -> impl DoubleEndedIterator<Item = Ty<'tcx>> + 'tcx {
|
||||||
self.iter().filter_map(|k| k.unpack().as_type())
|
self.iter().filter_map(|k| k.as_type())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn regions(&'tcx self) -> impl DoubleEndedIterator<Item = ty::Region<'tcx>> + 'tcx {
|
pub fn regions(&'tcx self) -> impl DoubleEndedIterator<Item = ty::Region<'tcx>> + 'tcx {
|
||||||
self.iter().filter_map(|k| k.unpack().as_region())
|
self.iter().filter_map(|k| k.as_region())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn consts(&'tcx self) -> impl DoubleEndedIterator<Item = ty::Const<'tcx>> + 'tcx {
|
pub fn consts(&'tcx self) -> impl DoubleEndedIterator<Item = ty::Const<'tcx>> + 'tcx {
|
||||||
self.iter().filter_map(|k| k.unpack().as_const())
|
self.iter().filter_map(|k| k.as_const())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -429,17 +420,13 @@ impl<'tcx> InternalSubsts<'tcx> {
|
||||||
#[inline]
|
#[inline]
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn type_at(&self, i: usize) -> Ty<'tcx> {
|
pub fn type_at(&self, i: usize) -> Ty<'tcx> {
|
||||||
self[i]
|
self[i].as_type().unwrap_or_else(|| bug!("expected type for param #{} in {:?}", i, self))
|
||||||
.unpack()
|
|
||||||
.as_type()
|
|
||||||
.unwrap_or_else(|| bug!("expected type for param #{} in {:?}", i, self))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn region_at(&self, i: usize) -> ty::Region<'tcx> {
|
pub fn region_at(&self, i: usize) -> ty::Region<'tcx> {
|
||||||
self[i]
|
self[i]
|
||||||
.unpack()
|
|
||||||
.as_region()
|
.as_region()
|
||||||
.unwrap_or_else(|| bug!("expected region for param #{} in {:?}", i, self))
|
.unwrap_or_else(|| bug!("expected region for param #{} in {:?}", i, self))
|
||||||
}
|
}
|
||||||
|
@ -447,10 +434,7 @@ impl<'tcx> InternalSubsts<'tcx> {
|
||||||
#[inline]
|
#[inline]
|
||||||
#[track_caller]
|
#[track_caller]
|
||||||
pub fn const_at(&self, i: usize) -> ty::Const<'tcx> {
|
pub fn const_at(&self, i: usize) -> ty::Const<'tcx> {
|
||||||
self[i]
|
self[i].as_const().unwrap_or_else(|| bug!("expected const for param #{} in {:?}", i, self))
|
||||||
.unpack()
|
|
||||||
.as_const()
|
|
||||||
.unwrap_or_else(|| bug!("expected const for param #{} in {:?}", i, self))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
|
@ -45,7 +45,7 @@ impl<'tcx> Visitor<'tcx> for FunctionItemRefChecker<'_, 'tcx> {
|
||||||
// Handle calls to `transmute`
|
// Handle calls to `transmute`
|
||||||
if self.tcx.is_diagnostic_item(sym::transmute, def_id) {
|
if self.tcx.is_diagnostic_item(sym::transmute, def_id) {
|
||||||
let arg_ty = args[0].ty(self.body, self.tcx);
|
let arg_ty = args[0].ty(self.body, self.tcx);
|
||||||
for inner_ty in arg_ty.walk().filter_map(|arg| arg.unpack().as_type()) {
|
for inner_ty in arg_ty.walk().filter_map(|arg| arg.as_type()) {
|
||||||
if let Some((fn_id, fn_substs)) =
|
if let Some((fn_id, fn_substs)) =
|
||||||
FunctionItemRefChecker::is_fn_ref(inner_ty)
|
FunctionItemRefChecker::is_fn_ref(inner_ty)
|
||||||
{
|
{
|
||||||
|
@ -80,7 +80,7 @@ impl<'tcx> FunctionItemRefChecker<'_, 'tcx> {
|
||||||
let arg_defs = self.tcx.fn_sig(def_id).subst_identity().skip_binder().inputs();
|
let arg_defs = self.tcx.fn_sig(def_id).subst_identity().skip_binder().inputs();
|
||||||
for (arg_num, arg_def) in arg_defs.iter().enumerate() {
|
for (arg_num, arg_def) in arg_defs.iter().enumerate() {
|
||||||
// For all types reachable from the argument type in the fn sig
|
// For all types reachable from the argument type in the fn sig
|
||||||
for inner_ty in arg_def.walk().filter_map(|arg| arg.unpack().as_type()) {
|
for inner_ty in arg_def.walk().filter_map(|arg| arg.as_type()) {
|
||||||
// If the inner type matches the type bound by `Pointer`
|
// If the inner type matches the type bound by `Pointer`
|
||||||
if inner_ty == bound_ty {
|
if inner_ty == bound_ty {
|
||||||
// Do a substitution using the parameters from the callsite
|
// Do a substitution using the parameters from the callsite
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue