@@ -275,6 +275,7 @@ impl<'hir> ConstArg<'hir> {
275
275
match self . kind {
276
276
ConstArgKind :: Path ( path) => path. span ( ) ,
277
277
ConstArgKind :: Anon ( anon) => anon. span ,
278
+ ConstArgKind :: Infer ( span) => span,
278
279
}
279
280
}
280
281
}
@@ -289,6 +290,11 @@ pub enum ConstArgKind<'hir> {
289
290
/// However, in the future, we'll be using it for all of those.
290
291
Path ( QPath < ' hir > ) ,
291
292
Anon ( & ' hir AnonConst ) ,
293
+ /// **Note:** Not all inferred consts are represented as
294
+ /// `ConstArgKind::Infer`. In cases where it is ambiguous whether
295
+ /// a generic arg is a type or a const, inference variables are
296
+ /// represented as `GenericArg::Infer` instead.
297
+ Infer ( Span ) ,
292
298
}
293
299
294
300
#[ derive( Clone , Copy , Debug , HashStable_Generic ) ]
@@ -308,6 +314,10 @@ pub enum GenericArg<'hir> {
308
314
Lifetime ( & ' hir Lifetime ) ,
309
315
Type ( & ' hir Ty < ' hir > ) ,
310
316
Const ( & ' hir ConstArg < ' hir > ) ,
317
+ /// **Note:** Inference variables are only represented as
318
+ /// `GenericArg::Infer` in cases where it is ambiguous whether
319
+ /// a generic arg is a type or a const. Otherwise, inference variables
320
+ /// are represented as `TyKind::Infer` or `ConstArgKind::Infer`.
311
321
Infer ( InferArg ) ,
312
322
}
313
323
@@ -1645,29 +1655,6 @@ impl fmt::Display for ConstContext {
1645
1655
/// A literal.
1646
1656
pub type Lit = Spanned < LitKind > ;
1647
1657
1648
- #[ derive( Copy , Clone , Debug , HashStable_Generic ) ]
1649
- pub enum ArrayLen < ' hir > {
1650
- Infer ( InferArg ) ,
1651
- Body ( & ' hir ConstArg < ' hir > ) ,
1652
- }
1653
-
1654
- impl ArrayLen < ' _ > {
1655
- pub fn span ( self ) -> Span {
1656
- match self {
1657
- ArrayLen :: Infer ( arg) => arg. span ,
1658
- ArrayLen :: Body ( body) => body. span ( ) ,
1659
- }
1660
- }
1661
-
1662
- pub fn hir_id ( self ) -> HirId {
1663
- match self {
1664
- ArrayLen :: Infer ( InferArg { hir_id, .. } ) | ArrayLen :: Body ( & ConstArg { hir_id, .. } ) => {
1665
- hir_id
1666
- }
1667
- }
1668
- }
1669
- }
1670
-
1671
1658
/// A constant (expression) that's not an item or associated item,
1672
1659
/// but needs its own `DefId` for type-checking, const-eval, etc.
1673
1660
/// These are usually found nested inside types (e.g., array lengths)
@@ -2115,7 +2102,7 @@ pub enum ExprKind<'hir> {
2115
2102
///
2116
2103
/// E.g., `[1; 5]`. The first expression is the element
2117
2104
/// to be repeated; the second is the number of times to repeat it.
2118
- Repeat ( & ' hir Expr < ' hir > , ArrayLen < ' hir > ) ,
2105
+ Repeat ( & ' hir Expr < ' hir > , & ' hir ConstArg < ' hir > ) ,
2119
2106
2120
2107
/// A suspension point for coroutines (i.e., `yield <expr>`).
2121
2108
Yield ( & ' hir Expr < ' hir > , YieldSource ) ,
@@ -2625,7 +2612,7 @@ impl<'hir> Ty<'hir> {
2625
2612
TyKind :: Infer => true ,
2626
2613
TyKind :: Slice ( ty) => ty. is_suggestable_infer_ty ( ) ,
2627
2614
TyKind :: Array ( ty, length) => {
2628
- ty. is_suggestable_infer_ty ( ) || matches ! ( length, ArrayLen :: Infer ( ..) )
2615
+ ty. is_suggestable_infer_ty ( ) || matches ! ( length. kind , ConstArgKind :: Infer ( ..) )
2629
2616
}
2630
2617
TyKind :: Tup ( tys) => tys. iter ( ) . any ( Self :: is_suggestable_infer_ty) ,
2631
2618
TyKind :: Ptr ( mut_ty) | TyKind :: Ref ( _, mut_ty) => mut_ty. ty . is_suggestable_infer_ty ( ) ,
@@ -2834,7 +2821,7 @@ pub enum TyKind<'hir> {
2834
2821
/// A variable length slice (i.e., `[T]`).
2835
2822
Slice ( & ' hir Ty < ' hir > ) ,
2836
2823
/// A fixed length array (i.e., `[T; n]`).
2837
- Array ( & ' hir Ty < ' hir > , ArrayLen < ' hir > ) ,
2824
+ Array ( & ' hir Ty < ' hir > , & ' hir ConstArg < ' hir > ) ,
2838
2825
/// A raw pointer (i.e., `*const T` or `*mut T`).
2839
2826
Ptr ( MutTy < ' hir > ) ,
2840
2827
/// A reference (i.e., `&'a T` or `&'a mut T`).
@@ -2861,6 +2848,11 @@ pub enum TyKind<'hir> {
2861
2848
Typeof ( & ' hir AnonConst ) ,
2862
2849
/// `TyKind::Infer` means the type should be inferred instead of it having been
2863
2850
/// specified. This can appear anywhere in a type.
2851
+ ///
2852
+ /// **Note:** Not all inferred types are represented as
2853
+ /// `TyKind::Infer`. In cases where it is ambiguous whether
2854
+ /// a generic arg is a type or a const, inference variables are
2855
+ /// represented as `GenericArg::Infer` instead.
2864
2856
Infer ,
2865
2857
/// Placeholder for a type that has failed to be defined.
2866
2858
Err ( rustc_span:: ErrorGuaranteed ) ,
@@ -3801,8 +3793,6 @@ pub enum Node<'hir> {
3801
3793
Crate ( & ' hir Mod < ' hir > ) ,
3802
3794
Infer ( & ' hir InferArg ) ,
3803
3795
WherePredicate ( & ' hir WherePredicate < ' hir > ) ,
3804
- // FIXME: Merge into `Node::Infer`.
3805
- ArrayLenInfer ( & ' hir InferArg ) ,
3806
3796
PreciseCapturingNonLifetimeArg ( & ' hir PreciseCapturingNonLifetimeArg ) ,
3807
3797
// Created by query feeding
3808
3798
Synthetic ,
@@ -3856,7 +3846,6 @@ impl<'hir> Node<'hir> {
3856
3846
| Node :: OpaqueTy ( ..)
3857
3847
| Node :: Infer ( ..)
3858
3848
| Node :: WherePredicate ( ..)
3859
- | Node :: ArrayLenInfer ( ..)
3860
3849
| Node :: Synthetic
3861
3850
| Node :: Err ( ..) => None ,
3862
3851
}
0 commit comments