@@ -349,7 +349,7 @@ pub struct ParenthesizedArgs {
349349 pub span : Span ,
350350
351351 /// `(A, B)`
352- pub inputs : ThinVec < Box < Ty > > ,
352+ pub inputs : ThinVec < Ty > ,
353353
354354 /// ```text
355355 /// Foo(A, B) -> C
@@ -366,8 +366,7 @@ impl ParenthesizedArgs {
366366 let args = self
367367 . inputs
368368 . iter ( )
369- . cloned ( )
370- . map ( |input| AngleBracketedArg :: Arg ( GenericArg :: Type ( input) ) )
369+ . map ( |input| AngleBracketedArg :: Arg ( GenericArg :: Type ( Box :: new ( input. clone ( ) ) ) ) )
371370 . collect ( ) ;
372371 AngleBracketedArgs { span : self . inputs_span , args }
373372 }
@@ -637,7 +636,7 @@ pub struct Pat {
637636impl Pat {
638637 /// Attempt reparsing the pattern as a type.
639638 /// This is intended for use by diagnostics.
640- pub fn to_ty ( & self ) -> Option < Box < Ty > > {
639+ pub fn to_ty ( & self ) -> Option < Ty > {
641640 let kind = match & self . kind {
642641 PatKind :: Missing => unreachable ! ( ) ,
643642 // In a type expression `_` is an inference variable.
@@ -649,13 +648,13 @@ impl Pat {
649648 PatKind :: Path ( qself, path) => TyKind :: Path ( qself. clone ( ) , path. clone ( ) ) ,
650649 PatKind :: MacCall ( mac) => TyKind :: MacCall ( mac. clone ( ) ) ,
651650 // `&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 } ) ) ? ,
655654 // A slice/array pattern `[P]` can be reparsed as `[T]`, an unsized array,
656655 // when `P` can be reparsed as a type `T`.
657656 PatKind :: Slice ( pats) if let [ pat] = pats. as_slice ( ) => {
658- pat. to_ty ( ) . map ( TyKind :: Slice ) ?
657+ TyKind :: Slice ( Box :: new ( pat. to_ty ( ) ? ) )
659658 }
660659 // A tuple pattern `(P0, .., Pn)` can be reparsed as `(T0, .., Tn)`
661660 // assuming `T0` to `Tn` are all syntactically valid as types.
@@ -670,7 +669,7 @@ impl Pat {
670669 _ => return None ,
671670 } ;
672671
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 } )
674673 }
675674
676675 /// Walk top-down and call `it` in each place where a pattern occurs
@@ -870,11 +869,11 @@ pub enum PatKind {
870869 Struct ( Option < Box < QSelf > > , Path , ThinVec < PatField > , PatFieldsRest ) ,
871870
872871 /// 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 > ) ,
874873
875874 /// An or-pattern `A | B | C`.
876875 /// Invariant: `pats.len() >= 2`.
877- Or ( ThinVec < Box < Pat > > ) ,
876+ Or ( ThinVec < Pat > ) ,
878877
879878 /// A possibly qualified path pattern.
880879 /// Unqualified path patterns `A::B::C` can legally refer to variants, structs, constants
@@ -883,7 +882,7 @@ pub enum PatKind {
883882 Path ( Option < Box < QSelf > > , Path ) ,
884883
885884 /// A tuple pattern (`(a, b)`).
886- Tuple ( ThinVec < Box < Pat > > ) ,
885+ Tuple ( ThinVec < Pat > ) ,
887886
888887 /// A `box` pattern.
889888 Box ( Box < Pat > ) ,
@@ -901,7 +900,7 @@ pub enum PatKind {
901900 Range ( Option < Box < Expr > > , Option < Box < Expr > > , Spanned < RangeEnd > ) ,
902901
903902 /// A slice pattern `[a, b, c]`.
904- Slice ( ThinVec < Box < Pat > > ) ,
903+ Slice ( ThinVec < Pat > ) ,
905904
906905 /// A rest pattern `..`.
907906 ///
@@ -1468,24 +1467,24 @@ impl Expr {
14681467 }
14691468
14701469 /// 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 > {
14721471 let kind = match & self . kind {
14731472 // Trivial conversions.
14741473 ExprKind :: Path ( qself, path) => TyKind :: Path ( qself. clone ( ) , path. clone ( ) ) ,
14751474 ExprKind :: MacCall ( mac) => TyKind :: MacCall ( mac. clone ( ) ) ,
14761475
1477- ExprKind :: Paren ( expr) => expr. to_ty ( ) . map ( TyKind :: Paren ) ? ,
1476+ ExprKind :: Paren ( expr) => TyKind :: Paren ( Box :: new ( expr. to_ty ( ) ? ) ) ,
14781477
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 } ) ) ? ,
14821481
14831482 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 ( ) ) ) ?
14851484 }
14861485
14871486 ExprKind :: Array ( exprs) if let [ expr] = exprs. as_slice ( ) => {
1488- expr. to_ty ( ) . map ( TyKind :: Slice ) ?
1487+ TyKind :: Slice ( Box :: new ( expr. to_ty ( ) ? ) )
14891488 }
14901489
14911490 ExprKind :: Tup ( exprs) => {
@@ -1510,7 +1509,7 @@ impl Expr {
15101509 _ => return None ,
15111510 } ;
15121511
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 } )
15141513 }
15151514
15161515 pub fn precedence ( & self ) -> ExprPrecedence {
@@ -2309,6 +2308,12 @@ pub enum Term {
23092308 Const ( AnonConst ) ,
23102309}
23112310
2311+ impl From < Ty > for Term {
2312+ fn from ( v : Ty ) -> Self {
2313+ Term :: Ty ( Box :: new ( v) )
2314+ }
2315+ }
2316+
23122317impl From < Box < Ty > > for Term {
23132318 fn from ( v : Box < Ty > ) -> Self {
23142319 Term :: Ty ( v)
@@ -2423,7 +2428,7 @@ pub enum TyKind {
24232428 /// The never type (`!`).
24242429 Never ,
24252430 /// A tuple (`(A, B, C, D,...)`).
2426- Tup ( ThinVec < Box < Ty > > ) ,
2431+ Tup ( ThinVec < Ty > ) ,
24272432 /// A path (`module::module::...::Type`), optionally
24282433 /// "qualified", e.g., `<Vec<T> as SomeTrait>::SomeType`.
24292434 ///
@@ -2532,7 +2537,7 @@ pub enum TyPatKind {
25322537 /// A range pattern (e.g., `1...2`, `1..2`, `1..`, `..2`, `1..=2`, `..=2`).
25332538 Range ( Option < Box < AnonConst > > , Option < Box < AnonConst > > , Spanned < RangeEnd > ) ,
25342539
2535- Or ( ThinVec < Box < TyPat > > ) ,
2540+ Or ( ThinVec < TyPat > ) ,
25362541
25372542 /// Placeholder for a pattern that wasn't syntactically well formed in some way.
25382543 Err ( ErrorGuaranteed ) ,
0 commit comments