Auto merge of #116887 - lcnr:alias-ty-constructor, r=compiler-errors
`TyCtxt::mk_alias_ty` -> `AliasTy::new`
This commit is contained in:
commit
e1aa9edde0
@ -448,7 +448,7 @@ impl<'tcx> dyn AstConv<'tcx> + '_ {
|
|||||||
|
|
||||||
debug!(?args_trait_ref_and_assoc_item);
|
debug!(?args_trait_ref_and_assoc_item);
|
||||||
|
|
||||||
tcx.mk_alias_ty(assoc_item.def_id, args_trait_ref_and_assoc_item)
|
ty::AliasTy::new(tcx, assoc_item.def_id, args_trait_ref_and_assoc_item)
|
||||||
})
|
})
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -437,7 +437,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||||||
);
|
);
|
||||||
|
|
||||||
let quiet_projection_ty =
|
let quiet_projection_ty =
|
||||||
tcx.mk_alias_ty(projection_ty.def_id, args_with_infer_self);
|
ty::AliasTy::new(tcx, projection_ty.def_id, args_with_infer_self);
|
||||||
|
|
||||||
let term = pred.skip_binder().term;
|
let term = pred.skip_binder().term;
|
||||||
|
|
||||||
|
@ -916,7 +916,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||||||
// Type aliases defined in crates that have the
|
// Type aliases defined in crates that have the
|
||||||
// feature `lazy_type_alias` enabled get encoded as a type alias that normalization will
|
// feature `lazy_type_alias` enabled get encoded as a type alias that normalization will
|
||||||
// then actually instantiate the where bounds of.
|
// then actually instantiate the where bounds of.
|
||||||
let alias_ty = tcx.mk_alias_ty(did, args);
|
let alias_ty = ty::AliasTy::new(tcx, did, args);
|
||||||
Ty::new_alias(tcx, ty::Weak, alias_ty)
|
Ty::new_alias(tcx, ty::Weak, alias_ty)
|
||||||
} else {
|
} else {
|
||||||
tcx.at(span).type_of(did).instantiate(tcx, args)
|
tcx.at(span).type_of(did).instantiate(tcx, args)
|
||||||
@ -1718,7 +1718,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||||||
.chain(args.into_iter().skip(parent_args.len())),
|
.chain(args.into_iter().skip(parent_args.len())),
|
||||||
);
|
);
|
||||||
|
|
||||||
let ty = Ty::new_alias(tcx, ty::Inherent, tcx.mk_alias_ty(assoc_item, args));
|
let ty = Ty::new_alias(tcx, ty::Inherent, ty::AliasTy::new(tcx, assoc_item, args));
|
||||||
|
|
||||||
return Ok(Some((ty, assoc_item)));
|
return Ok(Some((ty, assoc_item)));
|
||||||
}
|
}
|
||||||
|
@ -2286,7 +2286,7 @@ pub(super) fn check_type_bounds<'tcx>(
|
|||||||
_ => predicates.push(
|
_ => predicates.push(
|
||||||
ty::Binder::bind_with_vars(
|
ty::Binder::bind_with_vars(
|
||||||
ty::ProjectionPredicate {
|
ty::ProjectionPredicate {
|
||||||
projection_ty: tcx.mk_alias_ty(trait_ty.def_id, rebased_args),
|
projection_ty: ty::AliasTy::new(tcx, trait_ty.def_id, rebased_args),
|
||||||
term: normalize_impl_ty.into(),
|
term: normalize_impl_ty.into(),
|
||||||
},
|
},
|
||||||
bound_vars,
|
bound_vars,
|
||||||
|
@ -674,7 +674,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
);
|
);
|
||||||
|
|
||||||
let quiet_projection_ty =
|
let quiet_projection_ty =
|
||||||
tcx.mk_alias_ty(projection_ty.def_id, args_with_infer_self);
|
ty::AliasTy::new(tcx, projection_ty.def_id, args_with_infer_self);
|
||||||
|
|
||||||
let term = pred.skip_binder().term;
|
let term = pred.skip_binder().term;
|
||||||
|
|
||||||
|
@ -1687,7 +1687,6 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
&& let DefKind::Impl { of_trait: false } = self.def_kind(self.parent(_def_id))
|
&& let DefKind::Impl { of_trait: false } = self.def_kind(self.parent(_def_id))
|
||||||
{
|
{
|
||||||
// If this is an inherent projection.
|
// If this is an inherent projection.
|
||||||
|
|
||||||
generics.params.len() + 1
|
generics.params.len() + 1
|
||||||
} else {
|
} else {
|
||||||
generics.count()
|
generics.count()
|
||||||
@ -1897,15 +1896,6 @@ impl<'tcx> TyCtxt<'tcx> {
|
|||||||
self.mk_args_from_iter(iter::once(self_ty.into()).chain(rest))
|
self.mk_args_from_iter(iter::once(self_ty.into()).chain(rest))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mk_alias_ty(
|
|
||||||
self,
|
|
||||||
def_id: DefId,
|
|
||||||
args: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
|
|
||||||
) -> ty::AliasTy<'tcx> {
|
|
||||||
let args = self.check_and_mk_args(def_id, args);
|
|
||||||
ty::AliasTy { def_id, args, _use_mk_alias_ty_instead: () }
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn mk_bound_variable_kinds_from_iter<I, T>(self, iter: I) -> T::Output
|
pub fn mk_bound_variable_kinds_from_iter<I, T>(self, iter: I) -> T::Output
|
||||||
where
|
where
|
||||||
I: Iterator<Item = T>,
|
I: Iterator<Item = T>,
|
||||||
|
@ -1023,7 +1023,7 @@ impl<'tcx> Term<'tcx> {
|
|||||||
_ => None,
|
_ => None,
|
||||||
},
|
},
|
||||||
TermKind::Const(ct) => match ct.kind() {
|
TermKind::Const(ct) => match ct.kind() {
|
||||||
ConstKind::Unevaluated(uv) => Some(tcx.mk_alias_ty(uv.def, uv.args)),
|
ConstKind::Unevaluated(uv) => Some(AliasTy::new(tcx, uv.def, uv.args)),
|
||||||
_ => None,
|
_ => None,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
@ -288,7 +288,7 @@ impl<'tcx> Relate<'tcx> for ty::AliasTy<'tcx> {
|
|||||||
}
|
}
|
||||||
def => bug!("unknown alias DefKind: {def:?}"),
|
def => bug!("unknown alias DefKind: {def:?}"),
|
||||||
};
|
};
|
||||||
Ok(relation.tcx().mk_alias_ty(a.def_id, args))
|
Ok(ty::AliasTy::new(relation.tcx(), a.def_id, args))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1213,11 +1213,20 @@ pub struct AliasTy<'tcx> {
|
|||||||
pub def_id: DefId,
|
pub def_id: DefId,
|
||||||
|
|
||||||
/// This field exists to prevent the creation of `AliasTy` without using
|
/// This field exists to prevent the creation of `AliasTy` without using
|
||||||
/// [TyCtxt::mk_alias_ty].
|
/// [AliasTy::new].
|
||||||
pub(super) _use_mk_alias_ty_instead: (),
|
_use_alias_ty_new_instead: (),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'tcx> AliasTy<'tcx> {
|
impl<'tcx> AliasTy<'tcx> {
|
||||||
|
pub fn new(
|
||||||
|
tcx: TyCtxt<'tcx>,
|
||||||
|
def_id: DefId,
|
||||||
|
args: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
|
||||||
|
) -> ty::AliasTy<'tcx> {
|
||||||
|
let args = tcx.check_and_mk_args(def_id, args);
|
||||||
|
ty::AliasTy { def_id, args, _use_alias_ty_new_instead: () }
|
||||||
|
}
|
||||||
|
|
||||||
pub fn kind(self, tcx: TyCtxt<'tcx>) -> ty::AliasKind {
|
pub fn kind(self, tcx: TyCtxt<'tcx>) -> ty::AliasKind {
|
||||||
match tcx.def_kind(self.def_id) {
|
match tcx.def_kind(self.def_id) {
|
||||||
DefKind::AssocTy
|
DefKind::AssocTy
|
||||||
@ -1245,7 +1254,7 @@ impl<'tcx> AliasTy<'tcx> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_self_ty(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self {
|
pub fn with_self_ty(self, tcx: TyCtxt<'tcx>, self_ty: Ty<'tcx>) -> Self {
|
||||||
tcx.mk_alias_ty(self.def_id, [self_ty.into()].into_iter().chain(self.args.iter().skip(1)))
|
AliasTy::new(tcx, self.def_id, [self_ty.into()].into_iter().chain(self.args.iter().skip(1)))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1667,8 +1676,11 @@ impl<'tcx> ExistentialProjection<'tcx> {
|
|||||||
debug_assert!(!self_ty.has_escaping_bound_vars());
|
debug_assert!(!self_ty.has_escaping_bound_vars());
|
||||||
|
|
||||||
ty::ProjectionPredicate {
|
ty::ProjectionPredicate {
|
||||||
projection_ty: tcx
|
projection_ty: AliasTy::new(
|
||||||
.mk_alias_ty(self.def_id, [self_ty.into()].into_iter().chain(self.args)),
|
tcx,
|
||||||
|
self.def_id,
|
||||||
|
[self_ty.into()].into_iter().chain(self.args),
|
||||||
|
),
|
||||||
term: self.term,
|
term: self.term,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1971,7 +1983,7 @@ impl<'tcx> Ty<'tcx> {
|
|||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub fn new_opaque(tcx: TyCtxt<'tcx>, def_id: DefId, args: GenericArgsRef<'tcx>) -> Ty<'tcx> {
|
pub fn new_opaque(tcx: TyCtxt<'tcx>, def_id: DefId, args: GenericArgsRef<'tcx>) -> Ty<'tcx> {
|
||||||
Ty::new_alias(tcx, ty::Opaque, tcx.mk_alias_ty(def_id, args))
|
Ty::new_alias(tcx, ty::Opaque, AliasTy::new(tcx, def_id, args))
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Constructs a `TyKind::Error` type with current `ErrorGuaranteed`
|
/// Constructs a `TyKind::Error` type with current `ErrorGuaranteed`
|
||||||
@ -2135,7 +2147,7 @@ impl<'tcx> Ty<'tcx> {
|
|||||||
item_def_id: DefId,
|
item_def_id: DefId,
|
||||||
args: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
|
args: impl IntoIterator<Item: Into<GenericArg<'tcx>>>,
|
||||||
) -> Ty<'tcx> {
|
) -> Ty<'tcx> {
|
||||||
Ty::new_alias(tcx, ty::Projection, tcx.mk_alias_ty(item_def_id, args))
|
Ty::new_alias(tcx, ty::Projection, AliasTy::new(tcx, item_def_id, args))
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
@ -129,7 +129,7 @@ impl<'tcx> NormalizationFolder<'_, 'tcx> {
|
|||||||
self.at.cause.clone(),
|
self.at.cause.clone(),
|
||||||
self.at.param_env,
|
self.at.param_env,
|
||||||
ty::ProjectionPredicate {
|
ty::ProjectionPredicate {
|
||||||
projection_ty: tcx.mk_alias_ty(uv.def, uv.args),
|
projection_ty: AliasTy::new(tcx, uv.def, uv.args),
|
||||||
term: new_infer_ct.into(),
|
term: new_infer_ct.into(),
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
@ -352,8 +352,11 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
|
|||||||
|
|
||||||
let pred = tupled_inputs_and_output
|
let pred = tupled_inputs_and_output
|
||||||
.map_bound(|(inputs, output)| ty::ProjectionPredicate {
|
.map_bound(|(inputs, output)| ty::ProjectionPredicate {
|
||||||
projection_ty: tcx
|
projection_ty: ty::AliasTy::new(
|
||||||
.mk_alias_ty(goal.predicate.def_id(), [goal.predicate.self_ty(), inputs]),
|
tcx,
|
||||||
|
goal.predicate.def_id(),
|
||||||
|
[goal.predicate.self_ty(), inputs],
|
||||||
|
),
|
||||||
term: output.into(),
|
term: output.into(),
|
||||||
})
|
})
|
||||||
.to_predicate(tcx);
|
.to_predicate(tcx);
|
||||||
@ -472,7 +475,7 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
|
|||||||
ecx,
|
ecx,
|
||||||
goal,
|
goal,
|
||||||
ty::ProjectionPredicate {
|
ty::ProjectionPredicate {
|
||||||
projection_ty: ecx.tcx().mk_alias_ty(goal.predicate.def_id(), [self_ty]),
|
projection_ty: ty::AliasTy::new(ecx.tcx(), goal.predicate.def_id(), [self_ty]),
|
||||||
term,
|
term,
|
||||||
}
|
}
|
||||||
.to_predicate(tcx),
|
.to_predicate(tcx),
|
||||||
@ -512,9 +515,11 @@ impl<'tcx> assembly::GoalKind<'tcx> for ProjectionPredicate<'tcx> {
|
|||||||
ecx,
|
ecx,
|
||||||
goal,
|
goal,
|
||||||
ty::ProjectionPredicate {
|
ty::ProjectionPredicate {
|
||||||
projection_ty: ecx
|
projection_ty: ty::AliasTy::new(
|
||||||
.tcx()
|
ecx.tcx(),
|
||||||
.mk_alias_ty(goal.predicate.def_id(), [self_ty, generator.resume_ty()]),
|
goal.predicate.def_id(),
|
||||||
|
[self_ty, generator.resume_ty()],
|
||||||
|
),
|
||||||
term,
|
term,
|
||||||
}
|
}
|
||||||
.to_predicate(tcx),
|
.to_predicate(tcx),
|
||||||
|
@ -3937,7 +3937,7 @@ impl<'tcx> TypeErrCtxtExt<'tcx> for TypeErrCtxt<'_, 'tcx> {
|
|||||||
// This corresponds to `<ExprTy as Iterator>::Item = _`.
|
// This corresponds to `<ExprTy as Iterator>::Item = _`.
|
||||||
let projection = ty::Binder::dummy(ty::PredicateKind::Clause(
|
let projection = ty::Binder::dummy(ty::PredicateKind::Clause(
|
||||||
ty::ClauseKind::Projection(ty::ProjectionPredicate {
|
ty::ClauseKind::Projection(ty::ProjectionPredicate {
|
||||||
projection_ty: self.tcx.mk_alias_ty(proj.def_id, args),
|
projection_ty: ty::AliasTy::new(self.tcx, proj.def_id, args),
|
||||||
term: ty_var.into(),
|
term: ty_var.into(),
|
||||||
}),
|
}),
|
||||||
));
|
));
|
||||||
|
@ -2072,7 +2072,7 @@ fn confirm_generator_candidate<'cx, 'tcx>(
|
|||||||
};
|
};
|
||||||
|
|
||||||
ty::ProjectionPredicate {
|
ty::ProjectionPredicate {
|
||||||
projection_ty: tcx.mk_alias_ty(obligation.predicate.def_id, trait_ref.args),
|
projection_ty: ty::AliasTy::new(tcx, obligation.predicate.def_id, trait_ref.args),
|
||||||
term: ty.into(),
|
term: ty.into(),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -2116,7 +2116,7 @@ fn confirm_future_candidate<'cx, 'tcx>(
|
|||||||
debug_assert_eq!(tcx.associated_item(obligation.predicate.def_id).name, sym::Output);
|
debug_assert_eq!(tcx.associated_item(obligation.predicate.def_id).name, sym::Output);
|
||||||
|
|
||||||
ty::ProjectionPredicate {
|
ty::ProjectionPredicate {
|
||||||
projection_ty: tcx.mk_alias_ty(obligation.predicate.def_id, trait_ref.args),
|
projection_ty: ty::AliasTy::new(tcx, obligation.predicate.def_id, trait_ref.args),
|
||||||
term: return_ty.into(),
|
term: return_ty.into(),
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -2172,7 +2172,7 @@ fn confirm_builtin_candidate<'cx, 'tcx>(
|
|||||||
};
|
};
|
||||||
|
|
||||||
let predicate =
|
let predicate =
|
||||||
ty::ProjectionPredicate { projection_ty: tcx.mk_alias_ty(item_def_id, args), term };
|
ty::ProjectionPredicate { projection_ty: ty::AliasTy::new(tcx, item_def_id, args), term };
|
||||||
|
|
||||||
confirm_param_env_candidate(selcx, obligation, ty::Binder::dummy(predicate), false)
|
confirm_param_env_candidate(selcx, obligation, ty::Binder::dummy(predicate), false)
|
||||||
.with_addl_obligations(obligations)
|
.with_addl_obligations(obligations)
|
||||||
@ -2245,7 +2245,7 @@ fn confirm_callable_candidate<'cx, 'tcx>(
|
|||||||
flag,
|
flag,
|
||||||
)
|
)
|
||||||
.map_bound(|(trait_ref, ret_type)| ty::ProjectionPredicate {
|
.map_bound(|(trait_ref, ret_type)| ty::ProjectionPredicate {
|
||||||
projection_ty: tcx.mk_alias_ty(fn_once_output_def_id, trait_ref.args),
|
projection_ty: ty::AliasTy::new(tcx, fn_once_output_def_id, trait_ref.args),
|
||||||
term: ret_type.into(),
|
term: ret_type.into(),
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -704,7 +704,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
|
|||||||
let ty = traits::normalize_projection_type(
|
let ty = traits::normalize_projection_type(
|
||||||
self,
|
self,
|
||||||
param_env,
|
param_env,
|
||||||
tcx.mk_alias_ty(tcx.lang_items().deref_target()?, trait_ref.args),
|
ty::AliasTy::new(tcx, tcx.lang_items().deref_target()?, trait_ref.args),
|
||||||
cause.clone(),
|
cause.clone(),
|
||||||
0,
|
0,
|
||||||
// We're *intentionally* throwing these away,
|
// We're *intentionally* throwing these away,
|
||||||
|
@ -1133,7 +1133,7 @@ pub fn make_projection<'tcx>(
|
|||||||
#[cfg(debug_assertions)]
|
#[cfg(debug_assertions)]
|
||||||
assert_generic_args_match(tcx, assoc_item.def_id, args);
|
assert_generic_args_match(tcx, assoc_item.def_id, args);
|
||||||
|
|
||||||
Some(tcx.mk_alias_ty(assoc_item.def_id, args))
|
Some(ty::AliasTy::new(tcx, assoc_item.def_id, args))
|
||||||
}
|
}
|
||||||
helper(
|
helper(
|
||||||
tcx,
|
tcx,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user