mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
hir: Use InferArg
in ArrayLen::Infer
This commit is contained in:
parent
5f8030dcc9
commit
b2b5b91bfb
@ -2305,7 +2305,10 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
|
|||||||
match c.value.kind {
|
match c.value.kind {
|
||||||
ExprKind::Underscore => {
|
ExprKind::Underscore => {
|
||||||
if self.tcx.features().generic_arg_infer {
|
if self.tcx.features().generic_arg_infer {
|
||||||
hir::ArrayLen::Infer(self.lower_node_id(c.id), self.lower_span(c.value.span))
|
hir::ArrayLen::Infer(hir::InferArg {
|
||||||
|
hir_id: self.lower_node_id(c.id),
|
||||||
|
span: self.lower_span(c.value.span),
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
feature_err(
|
feature_err(
|
||||||
&self.tcx.sess,
|
&self.tcx.sess,
|
||||||
|
@ -1531,14 +1531,16 @@ pub type Lit = Spanned<LitKind>;
|
|||||||
|
|
||||||
#[derive(Copy, Clone, Debug, HashStable_Generic)]
|
#[derive(Copy, Clone, Debug, HashStable_Generic)]
|
||||||
pub enum ArrayLen {
|
pub enum ArrayLen {
|
||||||
Infer(HirId, Span),
|
Infer(InferArg),
|
||||||
Body(AnonConst),
|
Body(AnonConst),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl ArrayLen {
|
impl ArrayLen {
|
||||||
pub fn hir_id(&self) -> HirId {
|
pub fn hir_id(&self) -> HirId {
|
||||||
match self {
|
match self {
|
||||||
&ArrayLen::Infer(hir_id, _) | &ArrayLen::Body(AnonConst { hir_id, .. }) => hir_id,
|
ArrayLen::Infer(InferArg { hir_id, .. }) | ArrayLen::Body(AnonConst { hir_id, .. }) => {
|
||||||
|
*hir_id
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -2423,7 +2425,7 @@ impl<'hir> Ty<'hir> {
|
|||||||
TyKind::Infer => true,
|
TyKind::Infer => true,
|
||||||
TyKind::Slice(ty) => ty.is_suggestable_infer_ty(),
|
TyKind::Slice(ty) => ty.is_suggestable_infer_ty(),
|
||||||
TyKind::Array(ty, length) => {
|
TyKind::Array(ty, length) => {
|
||||||
ty.is_suggestable_infer_ty() || matches!(length, ArrayLen::Infer(_, _))
|
ty.is_suggestable_infer_ty() || matches!(length, ArrayLen::Infer(..))
|
||||||
}
|
}
|
||||||
TyKind::Tup(tys) => tys.iter().any(Self::is_suggestable_infer_ty),
|
TyKind::Tup(tys) => tys.iter().any(Self::is_suggestable_infer_ty),
|
||||||
TyKind::Ptr(mut_ty) | TyKind::Ref(_, mut_ty) => mut_ty.ty.is_suggestable_infer_ty(),
|
TyKind::Ptr(mut_ty) | TyKind::Ref(_, mut_ty) => mut_ty.ty.is_suggestable_infer_ty(),
|
||||||
|
@ -669,7 +669,7 @@ pub fn walk_pat_field<'v, V: Visitor<'v>>(visitor: &mut V, field: &'v PatField<'
|
|||||||
|
|
||||||
pub fn walk_array_len<'v, V: Visitor<'v>>(visitor: &mut V, len: &'v ArrayLen) {
|
pub fn walk_array_len<'v, V: Visitor<'v>>(visitor: &mut V, len: &'v ArrayLen) {
|
||||||
match len {
|
match len {
|
||||||
&ArrayLen::Infer(hir_id, _span) => visitor.visit_id(hir_id),
|
ArrayLen::Infer(InferArg { hir_id, span: _ }) => visitor.visit_id(*hir_id),
|
||||||
ArrayLen::Body(c) => visitor.visit_anon_const(c),
|
ArrayLen::Body(c) => visitor.visit_anon_const(c),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2529,7 +2529,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
|
|||||||
}
|
}
|
||||||
hir::TyKind::Array(ty, length) => {
|
hir::TyKind::Array(ty, length) => {
|
||||||
let length = match length {
|
let length = match length {
|
||||||
&hir::ArrayLen::Infer(_, span) => self.ct_infer(tcx.types.usize, None, span),
|
hir::ArrayLen::Infer(inf) => self.ct_infer(tcx.types.usize, None, inf.span),
|
||||||
hir::ArrayLen::Body(constant) => {
|
hir::ArrayLen::Body(constant) => {
|
||||||
ty::Const::from_anon_const(tcx, constant.def_id)
|
ty::Const::from_anon_const(tcx, constant.def_id)
|
||||||
}
|
}
|
||||||
|
@ -146,8 +146,8 @@ impl<'v> Visitor<'v> for HirPlaceholderCollector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
fn visit_array_length(&mut self, length: &'v hir::ArrayLen) {
|
fn visit_array_length(&mut self, length: &'v hir::ArrayLen) {
|
||||||
if let &hir::ArrayLen::Infer(_, span) = length {
|
if let hir::ArrayLen::Infer(inf) = length {
|
||||||
self.0.push(span);
|
self.0.push(inf.span);
|
||||||
}
|
}
|
||||||
intravisit::walk_array_len(self, length)
|
intravisit::walk_array_len(self, length)
|
||||||
}
|
}
|
||||||
|
@ -956,7 +956,7 @@ impl<'a> State<'a> {
|
|||||||
|
|
||||||
fn print_array_length(&mut self, len: &hir::ArrayLen) {
|
fn print_array_length(&mut self, len: &hir::ArrayLen) {
|
||||||
match len {
|
match len {
|
||||||
hir::ArrayLen::Infer(_, _) => self.word("_"),
|
hir::ArrayLen::Infer(..) => self.word("_"),
|
||||||
hir::ArrayLen::Body(ct) => self.print_anon_const(ct),
|
hir::ArrayLen::Body(ct) => self.print_anon_const(ct),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -405,7 +405,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
|
|||||||
|
|
||||||
pub fn array_length_to_const(&self, length: &hir::ArrayLen) -> ty::Const<'tcx> {
|
pub fn array_length_to_const(&self, length: &hir::ArrayLen) -> ty::Const<'tcx> {
|
||||||
match length {
|
match length {
|
||||||
&hir::ArrayLen::Infer(_, span) => self.ct_infer(self.tcx.types.usize, None, span),
|
hir::ArrayLen::Infer(inf) => self.ct_infer(self.tcx.types.usize, None, inf.span),
|
||||||
hir::ArrayLen::Body(anon_const) => {
|
hir::ArrayLen::Body(anon_const) => {
|
||||||
let span = self.tcx.def_span(anon_const.def_id);
|
let span = self.tcx.def_span(anon_const.def_id);
|
||||||
let c = ty::Const::from_anon_const(self.tcx, anon_const.def_id);
|
let c = ty::Const::from_anon_const(self.tcx, anon_const.def_id);
|
||||||
|
@ -1835,7 +1835,7 @@ pub(crate) fn clean_ty<'tcx>(ty: &hir::Ty<'tcx>, cx: &mut DocContext<'tcx>) -> T
|
|||||||
TyKind::Slice(ty) => Slice(Box::new(clean_ty(ty, cx))),
|
TyKind::Slice(ty) => Slice(Box::new(clean_ty(ty, cx))),
|
||||||
TyKind::Array(ty, ref length) => {
|
TyKind::Array(ty, ref length) => {
|
||||||
let length = match length {
|
let length = match length {
|
||||||
hir::ArrayLen::Infer(_, _) => "_".to_string(),
|
hir::ArrayLen::Infer(..) => "_".to_string(),
|
||||||
hir::ArrayLen::Body(anon_const) => {
|
hir::ArrayLen::Body(anon_const) => {
|
||||||
// NOTE(min_const_generics): We can't use `const_eval_poly` for constants
|
// NOTE(min_const_generics): We can't use `const_eval_poly` for constants
|
||||||
// as we currently do not supply the parent generics to anonymous constants
|
// as we currently do not supply the parent generics to anonymous constants
|
||||||
|
Loading…
Reference in New Issue
Block a user