diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index 738435891f16f..eb0c72d10f430 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -344,7 +344,7 @@ pub struct ParenthesizedArgs { pub span: Span, /// `(A, B)` - pub inputs: ThinVec>, + pub inputs: ThinVec, /// ```text /// Foo(A, B) -> C @@ -361,8 +361,7 @@ impl ParenthesizedArgs { let args = self .inputs .iter() - .cloned() - .map(|input| AngleBracketedArg::Arg(GenericArg::Type(input))) + .map(|input| AngleBracketedArg::Arg(GenericArg::Type(Box::new(input.clone())))) .collect(); AngleBracketedArgs { span: self.inputs_span, args } } @@ -632,37 +631,37 @@ pub struct Pat { impl Pat { /// Attempt reparsing the pattern as a type. /// This is intended for use by diagnostics. - pub fn to_ty(&self) -> Option> { - let kind = match &self.kind { + pub fn to_ty(&self) -> Option { + let kind = match self.kind { PatKind::Missing => unreachable!(), // In a type expression `_` is an inference variable. PatKind::Wild => TyKind::Infer, // An IDENT pattern with no binding mode would be valid as path to a type. E.g. `u32`. PatKind::Ident(BindingMode::NONE, ident, None) => { - TyKind::Path(None, Path::from_ident(*ident)) + TyKind::Path(None, Path::from_ident(ident)) } - PatKind::Path(qself, path) => TyKind::Path(qself.clone(), path.clone()), - PatKind::MacCall(mac) => TyKind::MacCall(mac.clone()), + PatKind::Path(ref qself, ref path) => TyKind::Path(qself.clone(), path.clone()), + PatKind::MacCall(ref mac) => TyKind::MacCall(mac.clone()), // `&mut? P` can be reinterpreted as `&mut? T` where `T` is `P` reparsed as a type. - PatKind::Ref(pat, pinned, mutbl) => pat.to_ty().map(|ty| match pinned { - Pinnedness::Not => TyKind::Ref(None, MutTy { ty, mutbl: *mutbl }), - Pinnedness::Pinned => TyKind::PinnedRef(None, MutTy { ty, mutbl: *mutbl }), + PatKind::Ref(ref pat, pinned, mutbl) => pat.to_ty().map(|ty| match pinned { + Pinnedness::Not => TyKind::Ref(None, MutTy { ty: Box::new(ty), mutbl }), + Pinnedness::Pinned => TyKind::PinnedRef(None, MutTy { ty: Box::new(ty), mutbl }), })?, // A slice/array pattern `[P]` can be reparsed as `[T]`, an unsized array, // when `P` can be reparsed as a type `T`. - PatKind::Slice(pats) if let [pat] = pats.as_slice() => { - pat.to_ty().map(TyKind::Slice)? + PatKind::Slice(ref pats) if let [pat] = pats.as_slice() => { + TyKind::Slice(Box::new(pat.to_ty()?)) } // A tuple pattern `(P0, .., Pn)` can be reparsed as `(T0, .., Tn)` // assuming `T0` to `Tn` are all syntactically valid as types. - PatKind::Tuple(pats) => { + PatKind::Tuple(ref pats) => { let tys = pats.iter().map(|pat| pat.to_ty()).collect::>>()?; TyKind::Tup(tys) } _ => return None, }; - Some(Box::new(Ty { kind, id: self.id, span: self.span, tokens: None })) + Some(Ty { kind, id: self.id, span: self.span, tokens: None }) } /// Walk top-down and call `it` in each place where a pattern occurs @@ -1501,24 +1500,24 @@ impl Expr { } /// Attempts to reparse as `Ty` (for diagnostic purposes). - pub fn to_ty(&self) -> Option> { + pub fn to_ty(&self) -> Option { let kind = match &self.kind { // Trivial conversions. ExprKind::Path(qself, path) => TyKind::Path(qself.clone(), path.clone()), ExprKind::MacCall(mac) => TyKind::MacCall(mac.clone()), - ExprKind::Paren(expr) => expr.to_ty().map(TyKind::Paren)?, + ExprKind::Paren(expr) => TyKind::Paren(Box::new(expr.to_ty()?)), - ExprKind::AddrOf(BorrowKind::Ref, mutbl, expr) => { - expr.to_ty().map(|ty| TyKind::Ref(None, MutTy { ty, mutbl: *mutbl }))? - } + ExprKind::AddrOf(BorrowKind::Ref, mutbl, expr) => expr + .to_ty() + .map(|ty| TyKind::Ref(None, MutTy { ty: Box::new(ty), mutbl: *mutbl }))?, ExprKind::Repeat(expr, expr_len) => { - expr.to_ty().map(|ty| TyKind::Array(ty, expr_len.clone()))? + expr.to_ty().map(|ty| TyKind::Array(Box::new(ty), expr_len.clone()))? } ExprKind::Array(exprs) if let [expr] = exprs.as_slice() => { - expr.to_ty().map(TyKind::Slice)? + TyKind::Slice(Box::new(expr.to_ty()?)) } ExprKind::Tup(exprs) => { @@ -1542,7 +1541,7 @@ impl Expr { _ => return None, }; - Some(Box::new(Ty { kind, id: self.id, span: self.span, tokens: None })) + Some(Ty { kind, id: self.id, span: self.span, tokens: None }) } pub fn precedence(&self) -> ExprPrecedence { @@ -1978,7 +1977,7 @@ pub enum UnsafeBinderCastKind { /// ``` #[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct QSelf { - pub ty: Box, + pub ty: Ty, /// The span of `a::b::Trait` in a path like ` as /// a::b::Trait>::AssociatedItem`; in the case where `position == @@ -2409,18 +2408,6 @@ pub enum Term { Const(AnonConst), } -impl From> for Term { - fn from(v: Box) -> Self { - Term::Ty(v) - } -} - -impl From for Term { - fn from(v: AnonConst) -> Self { - Term::Const(v) - } -} - /// The kind of [associated item constraint][AssocItemConstraint]. #[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub enum AssocItemConstraintKind { @@ -2496,7 +2483,7 @@ pub struct FnPtrTy { #[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct UnsafeBinderTy { pub generic_params: ThinVec, - pub inner_ty: Box, + pub inner_ty: Ty, } /// The various kinds of type recognized by the compiler. @@ -2523,7 +2510,7 @@ pub enum TyKind { /// The never type (`!`). Never, /// A tuple (`(A, B, C, D,...)`). - Tup(ThinVec>), + Tup(ThinVec), /// A path (`module::module::...::Type`), optionally /// "qualified", e.g., ` as SomeTrait>::SomeType`. /// @@ -2907,7 +2894,7 @@ pub struct InlineAsm { #[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct Param { pub attrs: AttrVec, - pub ty: Box, + pub ty: Ty, pub pat: Box, pub id: NodeId, pub span: Span, @@ -2926,7 +2913,7 @@ pub enum SelfKind { /// `&'lt pin const self`, `&'lt pin mut self` Pinned(Option, Mutability), /// `self: TYPE`, `mut self: TYPE` - Explicit(Box, Mutability), + Explicit(Ty, Mutability), } impl SelfKind { @@ -2982,32 +2969,32 @@ impl Param { /// Builds a `Param` object from `ExplicitSelf`. pub fn from_self(attrs: AttrVec, eself: ExplicitSelf, eself_ident: Ident) -> Param { let span = eself.span.to(eself_ident.span); - let infer_ty = Box::new(Ty { + let infer_ty = Ty { id: DUMMY_NODE_ID, kind: TyKind::ImplicitSelf, span: eself_ident.span, tokens: None, - }); + }; let (mutbl, ty) = match eself.node { SelfKind::Explicit(ty, mutbl) => (mutbl, ty), SelfKind::Value(mutbl) => (mutbl, infer_ty), SelfKind::Region(lt, mutbl) => ( Mutability::Not, - Box::new(Ty { + Ty { id: DUMMY_NODE_ID, - kind: TyKind::Ref(lt, MutTy { ty: infer_ty, mutbl }), + kind: TyKind::Ref(lt, MutTy { ty: Box::new(infer_ty), mutbl }), span, tokens: None, - }), + }, ), SelfKind::Pinned(lt, mutbl) => ( mutbl, - Box::new(Ty { + Ty { id: DUMMY_NODE_ID, - kind: TyKind::PinnedRef(lt, MutTy { ty: infer_ty, mutbl }), + kind: TyKind::PinnedRef(lt, MutTy { ty: Box::new(infer_ty), mutbl }), span, tokens: None, - }), + }, ), }; Param { @@ -3554,7 +3541,7 @@ pub struct FieldDef { pub safety: Safety, pub ident: Option, - pub ty: Box, + pub ty: Ty, pub default: Option, pub is_placeholder: bool, } @@ -3864,7 +3851,7 @@ pub struct DelegationMac { #[derive(Clone, Encodable, Decodable, Debug, Walkable)] pub struct StaticItem { pub ident: Ident, - pub ty: Box, + pub ty: Ty, pub safety: Safety, pub mutability: Mutability, pub expr: Option>, @@ -3876,7 +3863,7 @@ pub struct ConstItem { pub defaultness: Defaultness, pub ident: Ident, pub generics: Generics, - pub ty: Box, + pub ty: Ty, pub rhs_kind: ConstItemRhsKind, pub define_opaque: Option>, } @@ -4262,7 +4249,7 @@ mod size_asserts { static_assert_size!(LitKind, 24); static_assert_size!(Local, 96); static_assert_size!(MetaItemLit, 40); - static_assert_size!(Param, 40); + static_assert_size!(Param, 96); static_assert_size!(Pat, 80); static_assert_size!(PatKind, 56); static_assert_size!(Path, 24); diff --git a/compiler/rustc_ast/src/expand/autodiff_attrs.rs b/compiler/rustc_ast/src/expand/autodiff_attrs.rs index 90f15753e99c9..2088e493509bd 100644 --- a/compiler/rustc_ast/src/expand/autodiff_attrs.rs +++ b/compiler/rustc_ast/src/expand/autodiff_attrs.rs @@ -164,7 +164,7 @@ pub fn valid_ret_activity(mode: DiffMode, activity: DiffActivity) -> bool { /// since Duplicated expects a mutable ref/ptr and we would thus end up with a shadow value /// who is an indirect type, which doesn't match the primal scalar type. We can't prevent /// users here from marking scalars as Duplicated, due to type aliases. -pub fn valid_ty_for_activity(ty: &Box, activity: DiffActivity) -> bool { +pub fn valid_ty_for_activity(ty: &Ty, activity: DiffActivity) -> bool { use DiffActivity::*; // It's always allowed to mark something as Const, since we won't compute derivatives wrt. it. // Dual variants also support all types. diff --git a/compiler/rustc_ast/src/visit.rs b/compiler/rustc_ast/src/visit.rs index 8556e8288670f..0a6b7a6542874 100644 --- a/compiler/rustc_ast/src/visit.rs +++ b/compiler/rustc_ast/src/visit.rs @@ -392,7 +392,7 @@ macro_rules! common_visitor_and_walkers { ThinVec, ThinVec, ThinVec, - ThinVec>, + ThinVec, ThinVec, ThinVec, ); diff --git a/compiler/rustc_ast_passes/src/ast_validation.rs b/compiler/rustc_ast_passes/src/ast_validation.rs index c8dbba006f6db..2e3032590251f 100644 --- a/compiler/rustc_ast_passes/src/ast_validation.rs +++ b/compiler/rustc_ast_passes/src/ast_validation.rs @@ -1911,7 +1911,7 @@ fn deny_equality_constraints( ident: *ident, gen_args, kind: AssocItemConstraintKind::Equality { - term: predicate.rhs_ty.clone().into(), + term: Term::Ty(predicate.rhs_ty.clone()), }, span: ident.span, }); diff --git a/compiler/rustc_builtin_macros/src/alloc_error_handler.rs b/compiler/rustc_builtin_macros/src/alloc_error_handler.rs index 5f78758513e17..93c63da8fac72 100644 --- a/compiler/rustc_builtin_macros/src/alloc_error_handler.rs +++ b/compiler/rustc_builtin_macros/src/alloc_error_handler.rs @@ -75,7 +75,7 @@ fn generate_handler(cx: &ExtCtxt<'_>, handler: Ident, span: Span, sig_span: Span let call = cx.expr_call_ident(sig_span, handler, thin_vec![layout]); - let never = ast::FnRetTy::Ty(cx.ty(span, TyKind::Never)); + let never = ast::FnRetTy::Ty(Box::new(cx.ty(span, TyKind::Never))); let params = thin_vec![cx.param(span, size, ty_usize.clone()), cx.param(span, align, ty_usize)]; let decl = cx.fn_decl(params, never); let header = FnHeader { safety: Safety::Unsafe(span), ..FnHeader::default() }; diff --git a/compiler/rustc_builtin_macros/src/autodiff.rs b/compiler/rustc_builtin_macros/src/autodiff.rs index 264f797a78250..7f670fdf053e8 100644 --- a/compiler/rustc_builtin_macros/src/autodiff.rs +++ b/compiler/rustc_builtin_macros/src/autodiff.rs @@ -551,7 +551,7 @@ mod llvm_enzyme { .filter_map(|p| match &p.kind { GenericParamKind::Type { .. } => { let path = ast::Path::from_ident(p.ident); - let ty = ecx.ty_path(path); + let ty = Box::new(ecx.ty_path(path)); Some(AngleBracketedArg::Arg(GenericArg::Type(ty))) } GenericParamKind::Const { .. } => { @@ -682,7 +682,7 @@ mod llvm_enzyme { for i in 0..x.width { let mut shadow_arg = arg.clone(); // We += into the shadow in reverse mode. - shadow_arg.ty = Box::new(assure_mut_ref(&arg.ty)); + shadow_arg.ty = assure_mut_ref(&arg.ty); let old_name = if let PatKind::Ident(_, ident, _) = arg.pat.kind { ident.name } else { @@ -758,7 +758,7 @@ mod llvm_enzyme { match x.ret_activity { DiffActivity::Active | DiffActivity::ActiveOnly => { let ty = match d_decl.output { - FnRetTy::Ty(ref ty) => ty.clone(), + FnRetTy::Ty(ref ty) => (&**ty).clone(), FnRetTy::Default(span) => { panic!("Did not expect Default ret ty: {:?}", span); } @@ -788,17 +788,12 @@ mod llvm_enzyme { if x.mode.is_fwd() { let ty = match d_decl.output { - FnRetTy::Ty(ref ty) => ty.clone(), + FnRetTy::Ty(ref ty) => (&**ty).clone(), FnRetTy::Default(span) => { // We want to return std::hint::black_box(()). let kind = TyKind::Tup(ThinVec::new()); - let ty = Box::new(rustc_ast::Ty { - kind, - id: ast::DUMMY_NODE_ID, - span, - tokens: None, - }); - d_decl.output = FnRetTy::Ty(ty.clone()); + let ty = rustc_ast::Ty { kind, id: ast::DUMMY_NODE_ID, span, tokens: None }; + d_decl.output = FnRetTy::Ty(Box::new(ty.clone())); assert!(matches!(x.ret_activity, DiffActivity::None)); // this won't be used below, so any type would be fine. ty @@ -817,7 +812,7 @@ mod llvm_enzyme { value: ecx.expr_usize(span, 1 + x.width as usize), mgca_disambiguation: MgcaDisambiguation::Direct, }; - TyKind::Array(ty.clone(), anon_const) + TyKind::Array(Box::new(ty.clone()), anon_const) }; let ty = Box::new(rustc_ast::Ty { kind, id: ty.id, span: ty.span, tokens: None }); d_decl.output = FnRetTy::Ty(ty); @@ -832,7 +827,7 @@ mod llvm_enzyme { value: ecx.expr_usize(span, x.width as usize), mgca_disambiguation: MgcaDisambiguation::Direct, }; - let kind = TyKind::Array(ty.clone(), anon_const); + let kind = TyKind::Array(Box::new(ty.clone()), anon_const); let ty = Box::new(rustc_ast::Ty { kind, id: ty.id, span: ty.span, tokens: None }); d_decl.output = FnRetTy::Ty(ty); @@ -853,14 +848,14 @@ mod llvm_enzyme { let ret_ty = match d_decl.output { FnRetTy::Ty(ref ty) => { if !active_only_ret { - act_ret.insert(0, ty.clone()); + act_ret.insert(0, (&**ty).clone()); } let kind = TyKind::Tup(act_ret); Box::new(rustc_ast::Ty { kind, id: ty.id, span: ty.span, tokens: None }) } FnRetTy::Default(span) => { if act_ret.len() == 1 { - act_ret[0].clone() + Box::new(act_ret[0].clone()) } else { let kind = TyKind::Tup(act_ret.iter().map(|arg| arg.clone()).collect()); Box::new(rustc_ast::Ty { kind, id: ast::DUMMY_NODE_ID, span, tokens: None }) diff --git a/compiler/rustc_builtin_macros/src/deriving/clone.rs b/compiler/rustc_builtin_macros/src/deriving/clone.rs index af3db65bd0a63..c3d2e0b2f12e8 100644 --- a/compiler/rustc_builtin_macros/src/deriving/clone.rs +++ b/compiler/rustc_builtin_macros/src/deriving/clone.rs @@ -143,7 +143,7 @@ fn cs_clone_simple( super::assert_ty_bounds( cx, &mut stmts, - field.ty.clone(), + Box::new(field.ty.clone()), field.span, &[sym::clone, sym::AssertParamIsClone], ); @@ -154,7 +154,8 @@ fn cs_clone_simple( if is_union { // Just a single assertion for unions, that the union impls `Copy`. // let _: AssertParamIsCopy; - let self_ty = cx.ty_path(cx.path_ident(trait_span, Ident::with_dummy_span(kw::SelfUpper))); + let self_ty = + Box::new(cx.ty_path(cx.path_ident(trait_span, Ident::with_dummy_span(kw::SelfUpper)))); super::assert_ty_bounds( cx, &mut stmts, diff --git a/compiler/rustc_builtin_macros/src/deriving/cmp/eq.rs b/compiler/rustc_builtin_macros/src/deriving/cmp/eq.rs index d9b82e97cb462..d427fb244bd9b 100644 --- a/compiler/rustc_builtin_macros/src/deriving/cmp/eq.rs +++ b/compiler/rustc_builtin_macros/src/deriving/cmp/eq.rs @@ -71,7 +71,7 @@ fn cs_total_eq_assert( super::assert_ty_bounds( cx, &mut stmts, - field.ty.clone(), + Box::new(field.ty.clone()), field.span, &[sym::cmp, sym::AssertParamIsEq], ); diff --git a/compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs b/compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs index 1d9551f93a14c..14709c9a6a658 100644 --- a/compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs +++ b/compiler/rustc_builtin_macros/src/deriving/coerce_pointee.rs @@ -51,7 +51,9 @@ pub(crate) fn expand_deriving_coerce_pointee( .iter() .map(|p| match p.kind { GenericParamKind::Lifetime => GenericArg::Lifetime(cx.lifetime(p.span(), p.ident)), - GenericParamKind::Type { .. } => GenericArg::Type(cx.ty_ident(p.span(), p.ident)), + GenericParamKind::Type { .. } => { + GenericArg::Type(Box::new(cx.ty_ident(p.span(), p.ident))) + } GenericParamKind::Const { .. } => GenericArg::Const(cx.const_ident(p.span(), p.ident)), }) .collect(); @@ -140,7 +142,7 @@ pub(crate) fn expand_deriving_coerce_pointee( trait_ref, })), constness: ast::Const::No, - self_ty: self_type.clone(), + self_ty: Box::new(self_type.clone()), items: ThinVec::new(), }), ), @@ -163,7 +165,7 @@ pub(crate) fn expand_deriving_coerce_pointee( trait_ref, })), constness: ast::Const::No, - self_ty: self_type.clone(), + self_ty: Box::new(self_type.clone()), items: ThinVec::new(), }), ); @@ -174,8 +176,9 @@ pub(crate) fn expand_deriving_coerce_pointee( // example, instead of `MyType<'a, T>`, it will be `MyType<'a, __S>`. let s_ty = cx.ty_ident(span, Ident::new(sym::__S, span)); let mut alt_self_params = self_params; - alt_self_params[pointee_param_idx] = GenericArg::Type(s_ty.clone()); - let alt_self_type = cx.ty_path(cx.path_all(span, false, vec![name_ident], alt_self_params)); + alt_self_params[pointee_param_idx] = GenericArg::Type(Box::new(s_ty.clone())); + let alt_self_type = + Box::new(cx.ty_path(cx.path_all(span, false, vec![name_ident], alt_self_params))); // # Add `Unsize<__S>` bound to `#[pointee]` at the generic parameter location // @@ -198,7 +201,7 @@ pub(crate) fn expand_deriving_coerce_pointee( }); return; } - let arg = GenericArg::Type(s_ty.clone()); + let arg = GenericArg::Type(Box::new(s_ty.clone())); let unsize = cx.path_all(span, true, path!(span, core::marker::Unsize), vec![arg]); pointee.bounds.push(cx.trait_bound(unsize, false)); // Drop `#[pointee]` attribute since it should not be recognized outside `derive(CoercePointee)` diff --git a/compiler/rustc_builtin_macros/src/deriving/debug.rs b/compiler/rustc_builtin_macros/src/deriving/debug.rs index 48a2f19261f62..c98bba3d503ce 100644 --- a/compiler/rustc_builtin_macros/src/deriving/debug.rs +++ b/compiler/rustc_builtin_macros/src/deriving/debug.rs @@ -152,34 +152,35 @@ fn show_substructure(cx: &ExtCtxt<'_>, span: Span, substr: &Substructure<'_>) -> // `let names: &'static _ = &["field1", "field2"];` let names_let = is_struct.then(|| { let lt_static = Some(cx.lifetime_static(span)); - let ty_static_ref = cx.ty_ref(span, cx.ty_infer(span), lt_static, ast::Mutability::Not); + let ty_static_ref = + cx.ty_ref(span, Box::new(cx.ty_infer(span)), lt_static, ast::Mutability::Not); cx.stmt_let_ty( span, false, Ident::new(sym::names, span), - Some(ty_static_ref), + Some(Box::new(ty_static_ref)), cx.expr_array_ref(span, name_exprs), ) }); // `let values: &[&dyn Debug] = &[&&self.field1, &&self.field2];` let path_debug = cx.path_global(span, cx.std_path(&[sym::fmt, sym::Debug])); - let ty_dyn_debug = cx.ty( + let ty_dyn_debug = Box::new(cx.ty( span, ast::TyKind::TraitObject( vec![cx.trait_bound(path_debug, false)], ast::TraitObjectSyntax::Dyn, ), - ); - let ty_slice = cx.ty( + )); + let ty_slice = Box::new(cx.ty( span, - ast::TyKind::Slice(cx.ty_ref(span, ty_dyn_debug, None, ast::Mutability::Not)), - ); + ast::TyKind::Slice(Box::new(cx.ty_ref(span, ty_dyn_debug, None, ast::Mutability::Not))), + )); let values_let = cx.stmt_let_ty( span, false, Ident::new(sym::values, span), - Some(cx.ty_ref(span, ty_slice, None, ast::Mutability::Not)), + Some(Box::new(cx.ty_ref(span, ty_slice, None, ast::Mutability::Not))), cx.expr_array_ref(span, value_exprs), ); diff --git a/compiler/rustc_builtin_macros/src/deriving/from.rs b/compiler/rustc_builtin_macros/src/deriving/from.rs index 2e4369f3bb1c8..39c73bc3191e3 100644 --- a/compiler/rustc_builtin_macros/src/deriving/from.rs +++ b/compiler/rustc_builtin_macros/src/deriving/from.rs @@ -55,10 +55,10 @@ pub(crate) fn expand_deriving_from( _ => cx.dcx().bug("Invalid derive(From) ADT input"), }; - let from_type = Ty::AstTy(match field { + let from_type = Ty::AstTy(Box::new(match field { Ok(ref field) => field.ty.clone(), Err(guar) => cx.ty(span, ast::TyKind::Err(guar)), - }); + })); let path = Path::new_(pathvec_std!(convert::From), vec![Box::new(from_type.clone())], PathKind::Std); diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs index 5362bcde1aad8..fcb08f694ac1f 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/mod.rs @@ -596,7 +596,7 @@ impl<'a> TraitDef<'a> { cx: &ExtCtxt<'_>, type_ident: Ident, generics: &Generics, - field_tys: Vec>, + field_tys: Vec, methods: Vec>, is_packed: bool, ) -> Box { @@ -619,7 +619,7 @@ impl<'a> TraitDef<'a> { generics: Generics::default(), after_where_clause: ast::WhereClause::default(), bounds: Vec::new(), - ty: Some(type_def.to_ty(cx, self.span, type_ident, generics)), + ty: Some(Box::new(type_def.to_ty(cx, self.span, type_ident, generics))), })), tokens: None, }) @@ -782,9 +782,9 @@ impl<'a> TraitDef<'a> { GenericParamKind::Lifetime { .. } => { GenericArg::Lifetime(cx.lifetime(param.ident.span.with_ctxt(ctxt), param.ident)) } - GenericParamKind::Type { .. } => { - GenericArg::Type(cx.ty_ident(param.ident.span.with_ctxt(ctxt), param.ident)) - } + GenericParamKind::Type { .. } => GenericArg::Type(Box::new( + cx.ty_ident(param.ident.span.with_ctxt(ctxt), param.ident), + )), GenericParamKind::Const { .. } => { GenericArg::Const(cx.const_ident(param.ident.span.with_ctxt(ctxt), param.ident)) } @@ -794,7 +794,7 @@ impl<'a> TraitDef<'a> { // Create the type of `self`. let path = cx.path_all(type_ident.span.with_ctxt(ctxt), false, vec![type_ident], self_params); - let self_type = cx.ty_path(path); + let self_ty = Box::new(cx.ty_path(path)); let rustc_const_unstable = cx.path_ident(self.span, Ident::new(sym::rustc_const_unstable, self.span)); @@ -855,7 +855,7 @@ impl<'a> TraitDef<'a> { trait_ref, })), constness: if self.is_const { ast::Const::Yes(DUMMY_SP) } else { ast::Const::No }, - self_ty: self_type, + self_ty, items: methods.into_iter().chain(associated_types).collect(), }), ) @@ -870,7 +870,7 @@ impl<'a> TraitDef<'a> { from_scratch: bool, is_packed: bool, ) -> Box { - let field_tys: Vec> = + let field_tys: Vec = struct_def.fields().iter().map(|field| field.ty.clone()).collect(); let methods = self @@ -1005,7 +1005,7 @@ impl<'a> MethodDef<'a> { trait_: &TraitDef<'_>, type_ident: Ident, generics: &Generics, - ) -> (Option, ThinVec>, Vec>, Vec<(Ident, Box)>) + ) -> (Option, ThinVec>, Vec>, Vec<(Ident, ast::Ty)>) { let mut selflike_args = ThinVec::new(); let mut nonselflike_args = Vec::new(); @@ -1043,7 +1043,7 @@ impl<'a> MethodDef<'a> { type_ident: Ident, generics: &Generics, explicit_self: Option, - nonself_arg_tys: Vec<(Ident, Box)>, + nonself_arg_tys: Vec<(Ident, ast::Ty)>, body: BlockOrExpr, ) -> Box { let span = trait_.span; @@ -1063,7 +1063,7 @@ impl<'a> MethodDef<'a> { let ret_type = if let Ty::Unit = &self.ret_ty { ast::FnRetTy::Default(span) } else { - ast::FnRetTy::Ty(self.ret_ty.to_ty(cx, span, type_ident, generics)) + ast::FnRetTy::Ty(Box::new(self.ret_ty.to_ty(cx, span, type_ident, generics))) }; let method_ident = Ident::new(self.name, span); diff --git a/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs b/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs index 1458553d4925e..9880463e52c72 100644 --- a/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs +++ b/compiler/rustc_builtin_macros/src/deriving/generic/ty.rs @@ -40,7 +40,7 @@ impl Path { span: Span, self_ty: Ident, self_generics: &Generics, - ) -> Box { + ) -> ast::Ty { cx.ty_path(self.to_path(cx, span, self_ty, self_generics)) } pub(crate) fn to_path( @@ -51,8 +51,11 @@ impl Path { self_generics: &Generics, ) -> ast::Path { let mut idents = self.path.iter().map(|s| Ident::new(*s, span)).collect(); - let tys = self.params.iter().map(|t| t.to_ty(cx, span, self_ty, self_generics)); - let params = tys.map(GenericArg::Type).collect(); + let params = self + .params + .iter() + .map(|t| GenericArg::Type(Box::new(t.to_ty(cx, span, self_ty, self_generics)))) + .collect(); match self.kind { PathKind::Local => cx.path_all(span, false, idents, params), @@ -91,10 +94,10 @@ impl Ty { span: Span, self_ty: Ident, self_generics: &Generics, - ) -> Box { + ) -> ast::Ty { match self { Ref(ty, mutbl) => { - let raw_ty = ty.to_ty(cx, span, self_ty, self_generics); + let raw_ty = Box::new(ty.to_ty(cx, span, self_ty, self_generics)); cx.ty_ref(span, raw_ty, None, *mutbl) } Path(p) => p.to_ty(cx, span, self_ty, self_generics), @@ -103,7 +106,7 @@ impl Ty { let ty = ast::TyKind::Tup(ThinVec::new()); cx.ty(span, ty) } - AstTy(ty) => ty.clone(), + AstTy(ty) => (&**ty).clone(), } } @@ -124,7 +127,7 @@ impl Ty { GenericArg::Lifetime(ast::Lifetime { id: param.id, ident: param.ident }) } GenericParamKind::Type { .. } => { - GenericArg::Type(cx.ty_ident(span, param.ident)) + GenericArg::Type(Box::new(cx.ty_ident(span, param.ident))) } GenericParamKind::Const { .. } => { GenericArg::Const(cx.const_ident(span, param.ident)) diff --git a/compiler/rustc_builtin_macros/src/deriving/mod.rs b/compiler/rustc_builtin_macros/src/deriving/mod.rs index cee6952fa3460..2df91634aba67 100644 --- a/compiler/rustc_builtin_macros/src/deriving/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/mod.rs @@ -123,5 +123,5 @@ fn assert_ty_bounds( // Generate statement `let _: assert_path;`. let span = cx.with_def_site_ctxt(span); let assert_path = cx.path_all(span, true, cx.std_path(assert_path), vec![GenericArg::Type(ty)]); - stmts.push(cx.stmt_let_type_only(span, cx.ty_path(assert_path))); + stmts.push(cx.stmt_let_type_only(span, Box::new(cx.ty_path(assert_path)))); } diff --git a/compiler/rustc_builtin_macros/src/env.rs b/compiler/rustc_builtin_macros/src/env.rs index af78db156a221..09cb715b25aee 100644 --- a/compiler/rustc_builtin_macros/src/env.rs +++ b/compiler/rustc_builtin_macros/src/env.rs @@ -59,12 +59,12 @@ pub(crate) fn expand_option_env<'cx>( sp, true, cx.std_path(&[sym::option, sym::Option, sym::None]), - vec![GenericArg::Type(cx.ty_ref( + vec![GenericArg::Type(Box::new(cx.ty_ref( sp, - cx.ty_ident(sp, Ident::new(sym::str, sp)), + Box::new(cx.ty_ident(sp, Ident::new(sym::str, sp))), Some(lt), Mutability::Not, - ))], + )))], )) } Err(VarError::NotUnicode(_)) => { diff --git a/compiler/rustc_builtin_macros/src/global_allocator.rs b/compiler/rustc_builtin_macros/src/global_allocator.rs index 1bce3c03743af..d524fe3303215 100644 --- a/compiler/rustc_builtin_macros/src/global_allocator.rs +++ b/compiler/rustc_builtin_macros/src/global_allocator.rs @@ -71,7 +71,7 @@ impl AllocFnFactory<'_, '_> { let mut abi_args = ThinVec::new(); let args = method.inputs.iter().map(|input| self.arg_ty(input, &mut abi_args)).collect(); let result = self.call_allocator(method.name, args); - let output_ty = self.ret_ty(&method.output); + let output_ty = Box::new(self.ret_ty(&method.output)); let decl = self.cx.fn_decl(abi_args, ast::FnRetTy::Ty(output_ty)); let header = FnHeader { safety: Safety::Unsafe(self.span), ..FnHeader::default() }; let sig = FnSig { decl, header, span: self.span }; @@ -162,7 +162,7 @@ impl AllocFnFactory<'_, '_> { } } - fn ret_ty(&self, ty: &AllocatorTy) -> Box { + fn ret_ty(&self, ty: &AllocatorTy) -> Ty { match *ty { AllocatorTy::ResultPtr => self.ptr_u8(), @@ -174,20 +174,20 @@ impl AllocFnFactory<'_, '_> { } } - fn usize(&self) -> Box { + fn usize(&self) -> Ty { let usize = self.cx.path_ident(self.span, Ident::new(sym::usize, self.span)); self.cx.ty_path(usize) } - fn ptr_alignment(&self) -> Box { + fn ptr_alignment(&self) -> Ty { let path = self.cx.std_path(&[sym::ptr, sym::Alignment]); let path = self.cx.path(self.span, path); self.cx.ty_path(path) } - fn ptr_u8(&self) -> Box { + fn ptr_u8(&self) -> Ty { let u8 = self.cx.path_ident(self.span, Ident::new(sym::u8, self.span)); - let ty_u8 = self.cx.ty_path(u8); + let ty_u8 = Box::new(self.cx.ty_path(u8)); self.cx.ty_ptr(self.span, ty_u8, Mutability::Mut) } } diff --git a/compiler/rustc_builtin_macros/src/pattern_type.rs b/compiler/rustc_builtin_macros/src/pattern_type.rs index 4126547b0515a..7c2144ad71ac9 100644 --- a/compiler/rustc_builtin_macros/src/pattern_type.rs +++ b/compiler/rustc_builtin_macros/src/pattern_type.rs @@ -18,7 +18,7 @@ pub(crate) fn expand<'cx>( } }; - ExpandResult::Ready(base::MacEager::ty(cx.ty(sp, ast::TyKind::Pat(ty, pat)))) + ExpandResult::Ready(base::MacEager::ty(Box::new(cx.ty(sp, ast::TyKind::Pat(ty, pat))))) } fn parse_pat_ty<'a>( @@ -27,7 +27,7 @@ fn parse_pat_ty<'a>( ) -> PResult<'a, (Box, Box)> { let mut parser = cx.new_parser_from_tts(stream); - let ty = parser.parse_ty()?; + let ty = Box::new(parser.parse_ty()?); parser.expect_keyword(exp!(Is))?; let start = parser.token.span; diff --git a/compiler/rustc_builtin_macros/src/proc_macro_harness.rs b/compiler/rustc_builtin_macros/src/proc_macro_harness.rs index 24a5d79958c60..785632b9a6c3f 100644 --- a/compiler/rustc_builtin_macros/src/proc_macro_harness.rs +++ b/compiler/rustc_builtin_macros/src/proc_macro_harness.rs @@ -367,12 +367,12 @@ fn mk_decls(cx: &mut ExtCtxt<'_>, macros: &[ProcMacro]) -> Box { Ident::new(sym::_DECLS, span), cx.ty_ref( span, - cx.ty( + Box::new(cx.ty( span, - ast::TyKind::Slice( + ast::TyKind::Slice(Box::new( cx.ty_path(cx.path(span, vec![proc_macro, bridge, client, proc_macro_ty])), - ), - ), + )), + )), None, ast::Mutability::Not, ), diff --git a/compiler/rustc_builtin_macros/src/test_harness.rs b/compiler/rustc_builtin_macros/src/test_harness.rs index 1bb6d8a6bfd05..4cef9a0628641 100644 --- a/compiler/rustc_builtin_macros/src/test_harness.rs +++ b/compiler/rustc_builtin_macros/src/test_harness.rs @@ -319,7 +319,7 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> Box { let doc_hidden_attr = ecx.attr_nested_word(sym::doc, sym::hidden, sp); // pub fn main() { ... } - let main_ret_ty = ecx.ty(sp, ast::TyKind::Tup(ThinVec::new())); + let main_ret_ty = Box::new(ecx.ty(sp, ast::TyKind::Tup(ThinVec::new()))); // If no test runner is provided we need to import the test crate let main_body = if cx.test_runner.is_none() { diff --git a/compiler/rustc_expand/src/build.rs b/compiler/rustc_expand/src/build.rs index 19a2d65762e86..749d51c2f9ee4 100644 --- a/compiler/rustc_expand/src/build.rs +++ b/compiler/rustc_expand/src/build.rs @@ -73,21 +73,21 @@ impl<'a> ExtCtxt<'a> { ast::MutTy { ty, mutbl } } - pub fn ty(&self, span: Span, kind: ast::TyKind) -> Box { - Box::new(ast::Ty { id: ast::DUMMY_NODE_ID, span, kind, tokens: None }) + pub fn ty(&self, span: Span, kind: ast::TyKind) -> ast::Ty { + ast::Ty { id: ast::DUMMY_NODE_ID, span, kind, tokens: None } } - pub fn ty_infer(&self, span: Span) -> Box { + pub fn ty_infer(&self, span: Span) -> ast::Ty { self.ty(span, ast::TyKind::Infer) } - pub fn ty_path(&self, path: ast::Path) -> Box { + pub fn ty_path(&self, path: ast::Path) -> ast::Ty { self.ty(path.span, ast::TyKind::Path(None, path)) } // Might need to take bounds as an argument in the future, if you ever want // to generate a bounded existential trait type. - pub fn ty_ident(&self, span: Span, ident: Ident) -> Box { + pub fn ty_ident(&self, span: Span, ident: Ident) -> ast::Ty { self.ty_path(self.path_ident(span, ident)) } @@ -119,11 +119,11 @@ impl<'a> ExtCtxt<'a> { ty: Box, lifetime: Option, mutbl: ast::Mutability, - ) -> Box { + ) -> ast::Ty { self.ty(span, ast::TyKind::Ref(lifetime, self.ty_mt(ty, mutbl))) } - pub fn ty_ptr(&self, span: Span, ty: Box, mutbl: ast::Mutability) -> Box { + pub fn ty_ptr(&self, span: Span, ty: Box, mutbl: ast::Mutability) -> ast::Ty { self.ty(span, ast::TyKind::Ptr(self.ty_mt(ty, mutbl))) } @@ -665,7 +665,7 @@ impl<'a> ExtCtxt<'a> { self.lambda1(span, self.expr_block(self.block(span, stmts)), ident) } - pub fn param(&self, span: Span, ident: Ident, ty: Box) -> ast::Param { + pub fn param(&self, span: Span, ident: Ident, ty: ast::Ty) -> ast::Param { let pat = Box::new(self.pat_ident(span, ident)); ast::Param { attrs: AttrVec::default(), @@ -701,7 +701,7 @@ impl<'a> ExtCtxt<'a> { &self, span: Span, ident: Ident, - ty: Box, + ty: ast::Ty, mutability: ast::Mutability, expr: Box, ) -> Box { @@ -726,7 +726,7 @@ impl<'a> ExtCtxt<'a> { &self, span: Span, ident: Ident, - ty: Box, + ty: ast::Ty, rhs_kind: ast::ConstItemRhsKind, ) -> Box { let defaultness = ast::Defaultness::Implicit; diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index 76a9a6f9d03d9..8488234da96a1 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -1152,7 +1152,7 @@ pub fn parse_ast_fragment<'a>( AstFragment::OptExpr(None) } } - AstFragmentKind::Ty => AstFragment::Ty(this.parse_ty()?), + AstFragmentKind::Ty => AstFragment::Ty(Box::new(this.parse_ty()?)), AstFragmentKind::Pat => AstFragment::Pat(Box::new(this.parse_pat_allow_top_guard( None, RecoverComma::No, diff --git a/compiler/rustc_expand/src/placeholders.rs b/compiler/rustc_expand/src/placeholders.rs index 2db18429a5216..09379ff318bb5 100644 --- a/compiler/rustc_expand/src/placeholders.rs +++ b/compiler/rustc_expand/src/placeholders.rs @@ -42,9 +42,7 @@ pub(crate) fn placeholder( tokens: None, }) }; - let ty = || { - Box::new(ast::Ty { id, kind: ast::TyKind::MacCall(mac_placeholder()), span, tokens: None }) - }; + let ty = || ast::Ty { id, kind: ast::TyKind::MacCall(mac_placeholder()), span, tokens: None }; let pat = || { Box::new(ast::Pat { id, @@ -209,7 +207,7 @@ pub(crate) fn placeholder( span, kind: ast::WherePredicateKind::BoundPredicate(ast::WhereBoundPredicate { bound_generic_params: Default::default(), - bounded_ty: ty(), + bounded_ty: Box::new(ty()), bounds: Default::default(), }), is_placeholder: true, diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index b8672f6cafdfc..7c967b7a7dd87 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -60,20 +60,20 @@ pub(super) fn dummy_arg(ident: Ident, guar: ErrorGuaranteed) -> Param { id: ast::DUMMY_NODE_ID, pat, span: ident.span, - ty: Box::new(ty), + ty, is_placeholder: false, } } pub(super) trait RecoverQPath: Sized + 'static { const PATH_STYLE: PathStyle = PathStyle::Expr; - fn to_ty(&self) -> Option>; + fn to_ty(&self) -> Option; fn recovered(qself: Option>, path: ast::Path) -> Self; } impl RecoverQPath for Box { const PATH_STYLE: PathStyle = T::PATH_STYLE; - fn to_ty(&self) -> Option> { + fn to_ty(&self) -> Option { T::to_ty(self) } fn recovered(qself: Option>, path: ast::Path) -> Self { @@ -83,8 +83,8 @@ impl RecoverQPath for Box { impl RecoverQPath for Ty { const PATH_STYLE: PathStyle = PathStyle::Type; - fn to_ty(&self) -> Option> { - Some(Box::new(self.clone())) + fn to_ty(&self) -> Option { + Some(self.clone()) } fn recovered(qself: Option>, path: ast::Path) -> Self { Self { @@ -98,7 +98,7 @@ impl RecoverQPath for Ty { impl RecoverQPath for Pat { const PATH_STYLE: PathStyle = PathStyle::Pat; - fn to_ty(&self) -> Option> { + fn to_ty(&self) -> Option { self.to_ty() } fn recovered(qself: Option>, path: ast::Path) -> Self { @@ -112,7 +112,7 @@ impl RecoverQPath for Pat { } impl RecoverQPath for Expr { - fn to_ty(&self) -> Option> { + fn to_ty(&self) -> Option { self.to_ty() } fn recovered(qself: Option>, path: ast::Path) -> Self { @@ -1586,7 +1586,7 @@ impl<'a> Parser<'a> { } /// Swift lets users write `Ty?` to mean `Option`. Parse the construct and recover from it. - pub(super) fn maybe_recover_from_question_mark(&mut self, ty: Box) -> Box { + pub(super) fn maybe_recover_from_question_mark(&mut self, ty: Ty) -> Ty { if self.token == token::Question { self.bump(); let guar = self.dcx().emit_err(QuestionMarkInType { @@ -1846,7 +1846,7 @@ impl<'a> Parser<'a> { pub(super) fn maybe_recover_from_bad_qpath_stage_2( &mut self, ty_span: Span, - ty: Box, + ty: Ty, ) -> PResult<'a, T> { self.expect(exp!(PathSep))?; @@ -2386,7 +2386,7 @@ impl<'a> Parser<'a> { } #[cold] - pub(super) fn recover_arg_parse(&mut self) -> PResult<'a, (Box, Box)> { + pub(super) fn recover_arg_parse(&mut self) -> PResult<'a, (Box, ast::Ty)> { let pat = self.parse_pat_no_top_alt(Some(Expected::ArgumentName), None)?; self.expect(exp!(Colon))?; let ty = self.parse_ty()?; @@ -2683,9 +2683,9 @@ impl<'a> Parser<'a> { Applicability::MaybeIncorrect, ); let guar = err.emit(); - return Ok(GenericArg::Type( + return Ok(GenericArg::Type(Box::new( self.mk_ty(start.to(expr.span), TyKind::Err(guar)), - )); + ))); } else if self.token == token::Comma || self.token.kind.should_end_const_arg() { // Avoid the following output by checking that we consumed a full const arg: // help: expressions must be enclosed in braces to be used as const generic diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 5c44bfb0cf3f3..0801bcabade4e 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -275,7 +275,7 @@ impl<'a> Parser<'a> { let op = op.node; // Special cases: if op == AssocOp::Cast { - lhs = self.parse_assoc_op_cast(lhs, lhs_span, op_span, ExprKind::Cast)?; + lhs = self.parse_assoc_op_cast(lhs, lhs_span, op_span)?; continue; } else if let AssocOp::Range(limits) = op { // If we didn't have to handle `x..`/`x..=`, it would be pretty easy to @@ -664,17 +664,19 @@ impl<'a> Parser<'a> { lhs: Box, lhs_span: Span, op_span: Span, - expr_kind: fn(Box, Box) -> ExprKind, ) -> PResult<'a, Box> { let mk_expr = |this: &mut Self, lhs: Box, rhs: Box| { - this.mk_expr(this.mk_expr_sp(&lhs, lhs_span, op_span, rhs.span), expr_kind(lhs, rhs)) + this.mk_expr( + this.mk_expr_sp(&lhs, lhs_span, op_span, rhs.span), + ExprKind::Cast(lhs, rhs), + ) }; // Save the state of the parser before parsing type normally, in case there is a // LessThan comparison after this cast. let parser_snapshot_before_type = self.clone(); let cast_expr = match self.parse_as_cast_ty() { - Ok(rhs) => mk_expr(self, lhs, rhs), + Ok(rhs) => mk_expr(self, lhs, Box::new(rhs)), Err(type_err) => { if !self.may_recover() { return Err(type_err); @@ -723,7 +725,7 @@ impl<'a> Parser<'a> { let expr = mk_expr( self, lhs, - self.mk_ty(path.span, TyKind::Path(None, path.clone())), + Box::new(self.mk_ty(path.span, TyKind::Path(None, path.clone()))), ); let args_span = self.look_ahead(1, |t| t.span).to(span_after_type); @@ -2027,7 +2029,7 @@ impl<'a> Parser<'a> { /// Built-in macro for `offset_of!` expressions. pub(crate) fn parse_expr_offset_of(&mut self, lo: Span) -> PResult<'a, Box> { - let container = self.parse_ty()?; + let container = Box::new(self.parse_ty()?); self.expect(exp!(Comma))?; let fields = self.parse_floating_field_access()?; @@ -2057,7 +2059,7 @@ impl<'a> Parser<'a> { pub(crate) fn parse_expr_type_ascribe(&mut self, lo: Span) -> PResult<'a, Box> { let expr = self.parse_expr()?; self.expect(exp!(Comma))?; - let ty = self.parse_ty()?; + let ty = Box::new(self.parse_ty()?); let span = lo.to(self.token.span); Ok(self.mk_expr(span, ExprKind::Type(expr, ty))) } @@ -2068,7 +2070,7 @@ impl<'a> Parser<'a> { kind: UnsafeBinderCastKind, ) -> PResult<'a, Box> { let expr = self.parse_expr()?; - let ty = if self.eat(exp!(Comma)) { Some(self.parse_ty()?) } else { None }; + let ty = if self.eat(exp!(Comma)) { Some(Box::new(self.parse_ty()?)) } else { None }; let span = lo.to(self.token.span); Ok(self.mk_expr(span, ExprKind::UnsafeBinderCast(kind, expr, ty))) } @@ -3581,7 +3583,7 @@ impl<'a> Parser<'a> { /// Parses a `try {...}` or `try bikeshed Ty {...}` expression (`try` token already eaten). fn parse_try_block(&mut self, span_lo: Span) -> PResult<'a, Box> { let annotation = - if self.eat_keyword(exp!(Bikeshed)) { Some(self.parse_ty()?) } else { None }; + if self.eat_keyword(exp!(Bikeshed)) { Some(Box::new(self.parse_ty()?)) } else { None }; let (attrs, body) = self.parse_inner_attrs_and_block(None)?; if self.eat_keyword(exp!(Catch)) { diff --git a/compiler/rustc_parse/src/parser/generics.rs b/compiler/rustc_parse/src/parser/generics.rs index 8c02092fd6788..c15a8a162fd31 100644 --- a/compiler/rustc_parse/src/parser/generics.rs +++ b/compiler/rustc_parse/src/parser/generics.rs @@ -89,7 +89,7 @@ impl<'a> Parser<'a> { Vec::new() }; - let default = if self.eat(exp!(Eq)) { Some(self.parse_ty()?) } else { None }; + let default = if self.eat(exp!(Eq)) { Some(Box::new(self.parse_ty()?)) } else { None }; Ok(GenericParam { ident, id: ast::DUMMY_NODE_ID, @@ -120,7 +120,7 @@ impl<'a> Parser<'a> { Applicability::HasPlaceholders, ); let kind = TyKind::Err(err.emit()); - let ty = self.mk_ty(span, kind); + let ty = Box::new(self.mk_ty(span, kind)); Ok(GenericParam { ident, id: ast::DUMMY_NODE_ID, @@ -134,7 +134,7 @@ impl<'a> Parser<'a> { Err(err) }; } - let ty = self.parse_ty()?; + let ty = Box::new(self.parse_ty()?); // Parse optional const generics default value. let default = if self.eat(exp!(Eq)) { Some(self.parse_const_arg()?) } else { None }; @@ -162,7 +162,7 @@ impl<'a> Parser<'a> { ) -> PResult<'a, GenericParam> { let ident = self.parse_ident()?; self.expect(exp!(Colon))?; - let ty = self.parse_ty()?; + let ty = Box::new(self.parse_ty()?); // Parse optional const generics default value. let default = if self.eat(exp!(Eq)) { Some(self.parse_const_arg()?) } else { None }; @@ -594,7 +594,7 @@ impl<'a> Parser<'a> { // FIXME: Decide what should be used here, `=` or `==`. // FIXME: We are just dropping the binders in lifetime_defs on the floor here. } else if self.eat(exp!(Eq)) || self.eat(exp!(EqEq)) { - let rhs_ty = self.parse_ty()?; + let rhs_ty = Box::new(self.parse_ty()?); Ok(ast::WherePredicateKind::EqPredicate(ast::WhereEqPredicate { lhs_ty: ty, rhs_ty })) } else { self.maybe_recover_bounds_doubled_colon(&ty)?; diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index c03a237239e07..7928d77de9cfe 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -686,9 +686,9 @@ impl<'a> Parser<'a> { // AST validation later detects this `TyKind::Dummy` and emits an // error. (#121072 will hopefully remove all this special handling // of the obsolete `impl Trait for ..` and then this can go away.) - Some(self.mk_ty(self.prev_token.span, TyKind::Dummy)) + Some(Box::new(self.mk_ty(self.prev_token.span, TyKind::Dummy))) } else if has_for || self.token.can_begin_type() { - Some(self.parse_ty()?) + Some(Box::new(self.parse_ty()?)) } else { None }; @@ -708,7 +708,6 @@ impl<'a> Parser<'a> { self.dcx().emit_err(errors::MissingForInTraitImpl { span: missing_for_span }); } - let ty_first = *ty_first; let path = match ty_first.kind { // This notably includes paths passed through `ty` macro fragments (#46438). TyKind::Path(None, path) => path, @@ -1171,7 +1170,7 @@ impl<'a> Parser<'a> { let bounds = if self.eat(exp!(Colon)) { self.parse_generic_bounds()? } else { Vec::new() }; generics.where_clause = self.parse_where_clause()?; - let ty = if self.eat(exp!(Eq)) { Some(self.parse_ty()?) } else { None }; + let ty = if self.eat(exp!(Eq)) { Some(Box::new(self.parse_ty()?)) } else { None }; let after_where_clause = self.parse_where_clause()?; @@ -1556,7 +1555,7 @@ impl<'a> Parser<'a> { fn parse_const_item( &mut self, const_arg: bool, - ) -> PResult<'a, (Ident, Generics, Box, ConstItemRhsKind)> { + ) -> PResult<'a, (Ident, Generics, Ty, ConstItemRhsKind)> { let ident = self.parse_ident_or_underscore()?; let mut generics = self.parse_generics()?; @@ -1658,7 +1657,7 @@ impl<'a> Parser<'a> { &mut self, colon_present: bool, m: Option, - ) -> Box { + ) -> Ty { // Construct the error and stash it away with the hope // that typeck will later enrich the error with a type. let kind = match m { @@ -1678,7 +1677,7 @@ impl<'a> Parser<'a> { // The user intended that the type be inferred, // so treat this as if the user wrote e.g. `const A: _ = expr;`. - Box::new(Ty { kind: TyKind::Infer, span, id: ast::DUMMY_NODE_ID, tokens: None }) + Ty { kind: TyKind::Infer, span, id: ast::DUMMY_NODE_ID, tokens: None } } /// Parses an enum declaration. diff --git a/compiler/rustc_parse/src/parser/nonterminal.rs b/compiler/rustc_parse/src/parser/nonterminal.rs index 706b454835fab..e75211c2c79aa 100644 --- a/compiler/rustc_parse/src/parser/nonterminal.rs +++ b/compiler/rustc_parse/src/parser/nonterminal.rs @@ -159,9 +159,9 @@ impl<'a> Parser<'a> { self.collect_tokens_no_attrs(|this| this.parse_literal_maybe_minus())?, )) } - NonterminalKind::Ty => Ok(ParseNtResult::Ty( + NonterminalKind::Ty => Ok(ParseNtResult::Ty(Box::new( self.collect_tokens_no_attrs(|this| this.parse_ty_no_question_mark_recover())?, - )), + ))), // This could be handled like a token, since it is one. NonterminalKind::Ident => { if let Some((ident, is_raw)) = get_macro_ident(&self.token) { diff --git a/compiler/rustc_parse/src/parser/path.rs b/compiler/rustc_parse/src/parser/path.rs index 9196d8d156d8e..2be525667b95e 100644 --- a/compiler/rustc_parse/src/parser/path.rs +++ b/compiler/rustc_parse/src/parser/path.rs @@ -5,7 +5,7 @@ use rustc_ast::token::{self, MetaVarKind, Token, TokenKind}; use rustc_ast::{ self as ast, AngleBracketedArg, AngleBracketedArgs, AnonConst, AssocItemConstraint, AssocItemConstraintKind, BlockCheckMode, GenericArg, GenericArgs, Generics, MgcaDisambiguation, - ParenthesizedArgs, Path, PathSegment, QSelf, + ParenthesizedArgs, Path, PathSegment, QSelf, Term, }; use rustc_errors::{Applicability, Diag, PResult}; use rustc_span::{BytePos, Ident, Span, kw, sym}; @@ -795,10 +795,10 @@ impl<'a> Parser<'a> { let arg = self.parse_generic_arg(None)?; let span = ident.span.to(self.prev_token.span); let term = match arg { - Some(GenericArg::Type(ty)) => ty.into(), + Some(GenericArg::Type(ty)) => Term::Ty(ty), Some(GenericArg::Const(c)) => { self.psess.gated_spans.gate(sym::associated_const_equality, span); - c.into() + Term::Const(c) } Some(GenericArg::Lifetime(lt)) => { let guar = self.dcx().emit_err(errors::LifetimeInEqConstraint { @@ -809,7 +809,7 @@ impl<'a> Parser<'a> { .map_or(ident.span, |args| args.span()) .between(lt.ident.span), }); - self.mk_ty(lt.ident.span, ast::TyKind::Err(guar)).into() + Term::Ty(Box::new(self.mk_ty(lt.ident.span, ast::TyKind::Err(guar)))) } None => { let after_eq = eq_span.shrink_to_hi(); @@ -971,6 +971,7 @@ impl<'a> Parser<'a> { match self.parse_ty() { Ok(ty) => { + let ty = Box::new(ty); // Since the type parser recovers from some malformed slice and array types and // successfully returns a type, we need to look for `TyKind::Err`s in the // type to determine if error recovery has occurred and if the input is not a @@ -1034,7 +1035,9 @@ impl<'a> Parser<'a> { fix_span: attr_span.until(arg.span()), }); return Ok(Some(match arg { - GenericArg::Type(_) => GenericArg::Type(self.mk_ty(attr_span, TyKind::Err(guar))), + GenericArg::Type(_) => { + GenericArg::Type(Box::new(self.mk_ty(attr_span, TyKind::Err(guar)))) + } GenericArg::Const(_) => { let error_expr = self.mk_expr(attr_span, ExprKind::Err(guar)); GenericArg::Const(AnonConst { diff --git a/compiler/rustc_parse/src/parser/stmt.rs b/compiler/rustc_parse/src/parser/stmt.rs index 3c6629572ae50..89f8369d6f3b1 100644 --- a/compiler/rustc_parse/src/parser/stmt.rs +++ b/compiler/rustc_parse/src/parser/stmt.rs @@ -325,7 +325,7 @@ impl<'a> Parser<'a> { let parser_snapshot_before_type = self.clone(); let colon_sp = self.prev_token.span; match self.parse_ty() { - Ok(ty) => (None, Some(ty), Some(colon_sp)), + Ok(ty) => (None, Some(Box::new(ty)), Some(colon_sp)), Err(mut err) => { err.span_label( colon_sp, diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index 6ff165eb22b71..5cdf0a3cae9a7 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -104,7 +104,7 @@ fn can_begin_dyn_bound_in_edition_2015(t: Token) -> bool { impl<'a> Parser<'a> { /// Parses a type. - pub fn parse_ty(&mut self) -> PResult<'a, Box> { + pub fn parse_ty(&mut self) -> PResult<'a, Ty> { if self.token == token::DotDotDot { // We special case this so that we don't talk about "nested C-variadics" in types. // We still pass in `AllowCVariadic::No` so that `parse_ty_common` can complain about @@ -139,12 +139,13 @@ impl<'a> Parser<'a> { Some(ty_params), RecoverQuestionMark::Yes, ) + .map(Box::new) } /// Parse a type suitable for a function or function pointer parameter. /// The difference from `parse_ty` is that this version allows `...` /// (`CVarArgs`) at the top level of the type. - pub(super) fn parse_ty_for_param(&mut self) -> PResult<'a, Box> { + pub(super) fn parse_ty_for_param(&mut self) -> PResult<'a, Ty> { let ty = self.parse_ty_common( AllowPlus::Yes, AllowCVariadic::Yes, @@ -184,7 +185,7 @@ impl<'a> Parser<'a> { /// `+` is prohibited to maintain operator priority (P(+) < P(&)). /// Example 2: `value1 as TYPE + value2` /// `+` is prohibited to avoid interactions with expression grammar. - pub(super) fn parse_ty_no_plus(&mut self) -> PResult<'a, Box> { + pub(super) fn parse_ty_no_plus(&mut self) -> PResult<'a, Ty> { self.parse_ty_common( AllowPlus::No, AllowCVariadic::No, @@ -197,7 +198,7 @@ impl<'a> Parser<'a> { /// Parses a type following an `as` cast. Similar to `parse_ty_no_plus`, but signaling origin /// for better diagnostics involving `?`. - pub(super) fn parse_as_cast_ty(&mut self) -> PResult<'a, Box> { + pub(super) fn parse_as_cast_ty(&mut self) -> PResult<'a, Ty> { self.parse_ty_common( AllowPlus::No, AllowCVariadic::No, @@ -208,7 +209,7 @@ impl<'a> Parser<'a> { ) } - pub(super) fn parse_ty_no_question_mark_recover(&mut self) -> PResult<'a, Box> { + pub(super) fn parse_ty_no_question_mark_recover(&mut self) -> PResult<'a, Ty> { self.parse_ty_common( AllowPlus::Yes, AllowCVariadic::No, @@ -230,6 +231,7 @@ impl<'a> Parser<'a> { None, RecoverQuestionMark::Yes, ) + .map(Box::new) } /// Parses an optional return type `[ -> TY ]` in a function declaration. @@ -250,7 +252,7 @@ impl<'a> Parser<'a> { None, RecoverQuestionMark::Yes, )?; - FnRetTy::Ty(ty) + FnRetTy::Ty(Box::new(ty)) } else if recover_return_sign.can_recover(&self.token.kind) { // Don't `eat` to prevent `=>` from being added as an expected token which isn't // actually expected and could only confuse users @@ -267,7 +269,7 @@ impl<'a> Parser<'a> { None, RecoverQuestionMark::Yes, )?; - FnRetTy::Ty(ty) + FnRetTy::Ty(Box::new(ty)) } else { FnRetTy::Default(self.prev_token.span.shrink_to_hi()) }) @@ -281,7 +283,7 @@ impl<'a> Parser<'a> { recover_return_sign: RecoverReturnSign, ty_generics: Option<&Generics>, recover_question_mark: RecoverQuestionMark, - ) -> PResult<'a, Box> { + ) -> PResult<'a, Ty> { let allow_qpath_recovery = recover_qpath == RecoverQPath::Yes; maybe_recover_from_interpolated_ty_qpath!(self, allow_qpath_recovery); if self.token == token::Pound && self.look_ahead(1, |t| *t == token::OpenBracket) { @@ -495,7 +497,7 @@ impl<'a> Parser<'a> { self.parse_remaining_bounds(bounds, true) } // `(TYPE)` - _ => Ok(TyKind::Paren(ty)), + _ => Ok(TyKind::Paren(Box::new(ty))), } } else { Ok(TyKind::Tup(ts)) @@ -542,6 +544,7 @@ impl<'a> Parser<'a> { let mutbl = self.parse_mutability(); match self.parse_ty_no_plus() { Ok(ty) => { + let ty = Box::new(ty); err.span_suggestion_verbose( lo.shrink_to_lo(), "you might have meant to write a reference type here", @@ -606,7 +609,7 @@ impl<'a> Parser<'a> { Mutability::Mut => "mut", }; - let ty = self.parse_ty_no_question_mark_recover()?; + let ty = Box::new(self.parse_ty_no_question_mark_recover()?); self.dcx() .struct_span_err( @@ -636,7 +639,7 @@ impl<'a> Parser<'a> { }); Mutability::Not }); - let ty = self.parse_ty_no_plus()?; + let ty = Box::new(self.parse_ty_no_plus()?); Ok(TyKind::Ptr(MutTy { ty, mutbl })) } @@ -644,7 +647,7 @@ impl<'a> Parser<'a> { /// The opening `[` bracket is already eaten. fn parse_array_or_slice_ty(&mut self) -> PResult<'a, TyKind> { let elt_ty = match self.parse_ty() { - Ok(ty) => ty, + Ok(ty) => Box::new(ty), Err(err) if self.look_ahead(1, |t| *t == token::CloseBracket) | self.look_ahead(1, |t| *t == token::Semi) => @@ -652,7 +655,7 @@ impl<'a> Parser<'a> { // Recover from `[LIT; EXPR]` and `[LIT]` self.bump(); let guar = err.emit(); - self.mk_ty(self.prev_token.span, TyKind::Err(guar)) + Box::new(self.mk_ty(self.prev_token.span, TyKind::Err(guar))) } Err(err) => return Err(err), }; @@ -766,7 +769,7 @@ impl<'a> Parser<'a> { self.bump(); self.bump_with((dyn_tok, dyn_tok_sp)); } - let ty = self.parse_ty_no_plus()?; + let ty = Box::new(self.parse_ty_no_plus()?); Ok(match pinned { Pinnedness::Not => TyKind::Ref(opt_lifetime, MutTy { ty, mutbl }), Pinnedness::Pinned => TyKind::PinnedRef(opt_lifetime, MutTy { ty, mutbl }), @@ -1593,7 +1596,7 @@ impl<'a> Parser<'a> { } } - pub(super) fn mk_ty(&self, span: Span, kind: TyKind) -> Box { - Box::new(Ty { kind, span, id: ast::DUMMY_NODE_ID, tokens: None }) + pub(super) fn mk_ty(&self, span: Span, kind: TyKind) -> Ty { + Ty { kind, span, id: ast::DUMMY_NODE_ID, tokens: None } } } diff --git a/compiler/rustc_resolve/src/late.rs b/compiler/rustc_resolve/src/late.rs index 0b92792611a11..a67224798f960 100644 --- a/compiler/rustc_resolve/src/late.rs +++ b/compiler/rustc_resolve/src/late.rs @@ -936,7 +936,7 @@ impl<'ast, 'ra, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'ra, 'tc false, // We don't need to deal with patterns in parameters, because // they are not possible for foreign or bodiless functions. - fn_ptr.decl.inputs.iter().map(|Param { ty, .. }| (None, &**ty)), + fn_ptr.decl.inputs.iter().map(|Param { ty, .. }| (None, ty)), &fn_ptr.decl.output, false, ) @@ -1056,7 +1056,7 @@ impl<'ast, 'ra, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'ra, 'tc self.resolve_fn_signature( fn_id, sig.decl.has_self(), - sig.decl.inputs.iter().map(|Param { ty, .. }| (None, &**ty)), + sig.decl.inputs.iter().map(|Param { ty, .. }| (None, ty)), &sig.decl.output, false, ); @@ -1108,7 +1108,7 @@ impl<'ast, 'ra, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'ra, 'tc declaration .inputs .iter() - .map(|Param { pat, ty, .. }| (Some(&**pat), &**ty)), + .map(|Param { pat, ty, .. }| (Some(&**pat), ty)), &declaration.output, coro_node_id.is_some(), ); @@ -1325,7 +1325,7 @@ impl<'ast, 'ra, 'tcx> Visitor<'ast> for LateResolutionVisitor<'_, 'ast, 'ra, 'tc self.resolve_fn_signature( binder, false, - p_args.inputs.iter().map(|ty| (None, &**ty)), + p_args.inputs.iter().map(|ty| (None, ty)), &p_args.output, false, ); diff --git a/src/tools/rustfmt/src/types.rs b/src/tools/rustfmt/src/types.rs index 2d7bc59c62788..fdc27f9ce6601 100644 --- a/src/tools/rustfmt/src/types.rs +++ b/src/tools/rustfmt/src/types.rs @@ -576,7 +576,7 @@ fn rewrite_generic_args( } } ast::GenericArgs::Parenthesized(ref data) => format_function_type( - data.inputs.iter().map(|x| &**x), + data.inputs.iter(), &data.output, false, data.span,