@@ -349,7 +349,7 @@ pub struct ParenthesizedArgs {
349
349
pub span : Span ,
350
350
351
351
/// `(A, B)`
352
- pub inputs : ThinVec < Box < Ty > > ,
352
+ pub inputs : ThinVec < Ty > ,
353
353
354
354
/// ```text
355
355
/// Foo(A, B) -> C
@@ -366,8 +366,7 @@ impl ParenthesizedArgs {
366
366
let args = self
367
367
. inputs
368
368
. iter ( )
369
- . cloned ( )
370
- . map ( |input| AngleBracketedArg :: Arg ( GenericArg :: Type ( input) ) )
369
+ . map ( |input| AngleBracketedArg :: Arg ( GenericArg :: Type ( Box :: new ( input. clone ( ) ) ) ) )
371
370
. collect ( ) ;
372
371
AngleBracketedArgs { span : self . inputs_span , args }
373
372
}
@@ -637,7 +636,7 @@ pub struct Pat {
637
636
impl Pat {
638
637
/// Attempt reparsing the pattern as a type.
639
638
/// This is intended for use by diagnostics.
640
- pub fn to_ty ( & self ) -> Option < Box < Ty > > {
639
+ pub fn to_ty ( & self ) -> Option < Ty > {
641
640
let kind = match & self . kind {
642
641
PatKind :: Missing => unreachable ! ( ) ,
643
642
// In a type expression `_` is an inference variable.
@@ -649,13 +648,13 @@ impl Pat {
649
648
PatKind :: Path ( qself, path) => TyKind :: Path ( qself. clone ( ) , path. clone ( ) ) ,
650
649
PatKind :: MacCall ( mac) => TyKind :: MacCall ( mac. clone ( ) ) ,
651
650
// `&mut? P` can be reinterpreted as `&mut? T` where `T` is `P` reparsed as a type.
652
- PatKind :: Ref ( pat, mutbl) => {
653
- pat . to_ty ( ) . map ( |ty| TyKind :: Ref ( None , MutTy { ty , mutbl : * mutbl } ) ) ?
654
- }
651
+ PatKind :: Ref ( pat, mutbl) => pat
652
+ . to_ty ( )
653
+ . map ( |ty| TyKind :: Ref ( None , MutTy { ty : Box :: new ( ty ) , mutbl : * mutbl } ) ) ? ,
655
654
// A slice/array pattern `[P]` can be reparsed as `[T]`, an unsized array,
656
655
// when `P` can be reparsed as a type `T`.
657
656
PatKind :: Slice ( pats) if let [ pat] = pats. as_slice ( ) => {
658
- pat. to_ty ( ) . map ( TyKind :: Slice ) ?
657
+ TyKind :: Slice ( Box :: new ( pat. to_ty ( ) ? ) )
659
658
}
660
659
// A tuple pattern `(P0, .., Pn)` can be reparsed as `(T0, .., Tn)`
661
660
// assuming `T0` to `Tn` are all syntactically valid as types.
@@ -670,7 +669,7 @@ impl Pat {
670
669
_ => return None ,
671
670
} ;
672
671
673
- Some ( Box :: new ( Ty { kind, id : self . id , span : self . span , tokens : None } ) )
672
+ Some ( Ty { kind, id : self . id , span : self . span , tokens : None } )
674
673
}
675
674
676
675
/// Walk top-down and call `it` in each place where a pattern occurs
@@ -870,11 +869,11 @@ pub enum PatKind {
870
869
Struct ( Option < Box < QSelf > > , Path , ThinVec < PatField > , PatFieldsRest ) ,
871
870
872
871
/// A tuple struct/variant pattern (`Variant(x, y, .., z)`).
873
- TupleStruct ( Option < Box < QSelf > > , Path , ThinVec < Box < Pat > > ) ,
872
+ TupleStruct ( Option < Box < QSelf > > , Path , ThinVec < Pat > ) ,
874
873
875
874
/// An or-pattern `A | B | C`.
876
875
/// Invariant: `pats.len() >= 2`.
877
- Or ( ThinVec < Box < Pat > > ) ,
876
+ Or ( ThinVec < Pat > ) ,
878
877
879
878
/// A possibly qualified path pattern.
880
879
/// Unqualified path patterns `A::B::C` can legally refer to variants, structs, constants
@@ -883,7 +882,7 @@ pub enum PatKind {
883
882
Path ( Option < Box < QSelf > > , Path ) ,
884
883
885
884
/// A tuple pattern (`(a, b)`).
886
- Tuple ( ThinVec < Box < Pat > > ) ,
885
+ Tuple ( ThinVec < Pat > ) ,
887
886
888
887
/// A `box` pattern.
889
888
Box ( Box < Pat > ) ,
@@ -901,7 +900,7 @@ pub enum PatKind {
901
900
Range ( Option < Box < Expr > > , Option < Box < Expr > > , Spanned < RangeEnd > ) ,
902
901
903
902
/// A slice pattern `[a, b, c]`.
904
- Slice ( ThinVec < Box < Pat > > ) ,
903
+ Slice ( ThinVec < Pat > ) ,
905
904
906
905
/// A rest pattern `..`.
907
906
///
@@ -1468,24 +1467,24 @@ impl Expr {
1468
1467
}
1469
1468
1470
1469
/// Attempts to reparse as `Ty` (for diagnostic purposes).
1471
- pub fn to_ty ( & self ) -> Option < Box < Ty > > {
1470
+ pub fn to_ty ( & self ) -> Option < Ty > {
1472
1471
let kind = match & self . kind {
1473
1472
// Trivial conversions.
1474
1473
ExprKind :: Path ( qself, path) => TyKind :: Path ( qself. clone ( ) , path. clone ( ) ) ,
1475
1474
ExprKind :: MacCall ( mac) => TyKind :: MacCall ( mac. clone ( ) ) ,
1476
1475
1477
- ExprKind :: Paren ( expr) => expr. to_ty ( ) . map ( TyKind :: Paren ) ? ,
1476
+ ExprKind :: Paren ( expr) => TyKind :: Paren ( Box :: new ( expr. to_ty ( ) ? ) ) ,
1478
1477
1479
- ExprKind :: AddrOf ( BorrowKind :: Ref , mutbl, expr) => {
1480
- expr . to_ty ( ) . map ( |ty| TyKind :: Ref ( None , MutTy { ty , mutbl : * mutbl } ) ) ?
1481
- }
1478
+ ExprKind :: AddrOf ( BorrowKind :: Ref , mutbl, expr) => expr
1479
+ . to_ty ( )
1480
+ . map ( |ty| TyKind :: Ref ( None , MutTy { ty : Box :: new ( ty ) , mutbl : * mutbl } ) ) ? ,
1482
1481
1483
1482
ExprKind :: Repeat ( expr, expr_len) => {
1484
- expr. to_ty ( ) . map ( |ty| TyKind :: Array ( ty , expr_len. clone ( ) ) ) ?
1483
+ expr. to_ty ( ) . map ( |ty| TyKind :: Array ( Box :: new ( ty ) , expr_len. clone ( ) ) ) ?
1485
1484
}
1486
1485
1487
1486
ExprKind :: Array ( exprs) if let [ expr] = exprs. as_slice ( ) => {
1488
- expr. to_ty ( ) . map ( TyKind :: Slice ) ?
1487
+ TyKind :: Slice ( Box :: new ( expr. to_ty ( ) ? ) )
1489
1488
}
1490
1489
1491
1490
ExprKind :: Tup ( exprs) => {
@@ -1510,7 +1509,7 @@ impl Expr {
1510
1509
_ => return None ,
1511
1510
} ;
1512
1511
1513
- Some ( Box :: new ( Ty { kind, id : self . id , span : self . span , tokens : None } ) )
1512
+ Some ( Ty { kind, id : self . id , span : self . span , tokens : None } )
1514
1513
}
1515
1514
1516
1515
pub fn precedence ( & self ) -> ExprPrecedence {
@@ -2309,6 +2308,12 @@ pub enum Term {
2309
2308
Const ( AnonConst ) ,
2310
2309
}
2311
2310
2311
+ impl From < Ty > for Term {
2312
+ fn from ( v : Ty ) -> Self {
2313
+ Term :: Ty ( Box :: new ( v) )
2314
+ }
2315
+ }
2316
+
2312
2317
impl From < Box < Ty > > for Term {
2313
2318
fn from ( v : Box < Ty > ) -> Self {
2314
2319
Term :: Ty ( v)
@@ -2423,7 +2428,7 @@ pub enum TyKind {
2423
2428
/// The never type (`!`).
2424
2429
Never ,
2425
2430
/// A tuple (`(A, B, C, D,...)`).
2426
- Tup ( ThinVec < Box < Ty > > ) ,
2431
+ Tup ( ThinVec < Ty > ) ,
2427
2432
/// A path (`module::module::...::Type`), optionally
2428
2433
/// "qualified", e.g., `<Vec<T> as SomeTrait>::SomeType`.
2429
2434
///
@@ -2532,7 +2537,7 @@ pub enum TyPatKind {
2532
2537
/// A range pattern (e.g., `1...2`, `1..2`, `1..`, `..2`, `1..=2`, `..=2`).
2533
2538
Range ( Option < Box < AnonConst > > , Option < Box < AnonConst > > , Spanned < RangeEnd > ) ,
2534
2539
2535
- Or ( ThinVec < Box < TyPat > > ) ,
2540
+ Or ( ThinVec < TyPat > ) ,
2536
2541
2537
2542
/// Placeholder for a pattern that wasn't syntactically well formed in some way.
2538
2543
Err ( ErrorGuaranteed ) ,
0 commit comments