Skip to content

Rollup of 8 pull requests #145161

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
331 changes: 165 additions & 166 deletions compiler/rustc_ast/src/ast.rs

Large diffs are not rendered by default.

11 changes: 5 additions & 6 deletions compiler/rustc_ast/src/ast_traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use std::fmt;
use std::marker::PhantomData;

use crate::ptr::P;
use crate::tokenstream::LazyAttrTokenStream;
use crate::{
Arm, AssocItem, AttrItem, AttrKind, AttrVec, Attribute, Block, Crate, Expr, ExprField,
Expand Down Expand Up @@ -53,7 +52,7 @@ impl_has_node_id!(
WherePredicate,
);

impl<T: HasNodeId> HasNodeId for P<T> {
impl<T: HasNodeId> HasNodeId for Box<T> {
fn node_id(&self) -> NodeId {
(**self).node_id()
}
Expand Down Expand Up @@ -119,7 +118,7 @@ impl<T: HasTokens> HasTokens for Option<T> {
}
}

impl<T: HasTokens> HasTokens for P<T> {
impl<T: HasTokens> HasTokens for Box<T> {
fn tokens(&self) -> Option<&LazyAttrTokenStream> {
(**self).tokens()
}
Expand Down Expand Up @@ -245,7 +244,7 @@ impl_has_attrs!(
);
impl_has_attrs_none!(Attribute, AttrItem, Block, Pat, Path, Ty, Visibility);

impl<T: HasAttrs> HasAttrs for P<T> {
impl<T: HasAttrs> HasAttrs for Box<T> {
const SUPPORTS_CUSTOM_INNER_ATTRS: bool = T::SUPPORTS_CUSTOM_INNER_ATTRS;
fn attrs(&self) -> &[Attribute] {
(**self).attrs()
Expand Down Expand Up @@ -322,8 +321,8 @@ impl<Wrapped, Tag> AstNodeWrapper<Wrapped, Tag> {
}

// FIXME: remove after `stmt_expr_attributes` is stabilized.
impl<T, Tag> From<AstNodeWrapper<P<T>, Tag>> for AstNodeWrapper<T, Tag> {
fn from(value: AstNodeWrapper<P<T>, Tag>) -> Self {
impl<T, Tag> From<AstNodeWrapper<Box<T>, Tag>> for AstNodeWrapper<T, Tag> {
fn from(value: AstNodeWrapper<Box<T>, Tag>) -> Self {
AstNodeWrapper { wrapped: *value.wrapped, tag: value.tag }
}
}
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_ast/src/attr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ use crate::ast::{
Expr, ExprKind, LitKind, MetaItem, MetaItemInner, MetaItemKind, MetaItemLit, NormalAttr, Path,
PathSegment, Safety,
};
use crate::ptr::P;
use crate::token::{self, CommentKind, Delimiter, InvisibleOrigin, MetaVarKind, Token};
use crate::tokenstream::{
DelimSpan, LazyAttrTokenStream, Spacing, TokenStream, TokenStreamIter, TokenTree,
Expand Down Expand Up @@ -660,7 +659,7 @@ pub fn mk_attr_from_item(
span: Span,
) -> Attribute {
Attribute {
kind: AttrKind::Normal(P(NormalAttr { item, tokens })),
kind: AttrKind::Normal(Box::new(NormalAttr { item, tokens })),
id: g.mk_attr_id(),
style,
span,
Expand Down Expand Up @@ -710,7 +709,7 @@ pub fn mk_attr_name_value_str(
span: Span,
) -> Attribute {
let lit = token::Lit::new(token::Str, escape_string_symbol(val), None);
let expr = P(Expr {
let expr = Box::new(Expr {
id: DUMMY_NODE_ID,
kind: ExprKind::Lit(lit),
span,
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_ast/src/expand/autodiff_attrs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use std::fmt::{self, Display, Formatter};
use std::str::FromStr;

use crate::expand::{Decodable, Encodable, HashStable_Generic};
use crate::ptr::P;
use crate::{Ty, TyKind};

/// Forward and Reverse Mode are well known names for automatic differentiation implementations.
Expand Down Expand Up @@ -162,7 +161,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: &P<Ty>, activity: DiffActivity) -> bool {
pub fn valid_ty_for_activity(ty: &Box<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.
Expand Down
3 changes: 1 addition & 2 deletions compiler/rustc_ast/src/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ use rustc_macros::{Decodable, Encodable, Walkable};
use rustc_span::{Ident, Span, Symbol};

use crate::Expr;
use crate::ptr::P;
use crate::token::LitKind;

// Definitions:
Expand Down Expand Up @@ -147,7 +146,7 @@ impl FormatArguments {
#[derive(Clone, Encodable, Decodable, Debug, Walkable)]
pub struct FormatArgument {
pub kind: FormatArgumentKind,
pub expr: P<Expr>,
pub expr: Box<Expr>,
}

#[derive(Clone, Encodable, Decodable, Debug, Walkable)]
Expand Down
1 change: 0 additions & 1 deletion compiler/rustc_ast/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ pub mod expand;
pub mod format;
pub mod mut_visit;
pub mod node_id;
pub mod ptr;
pub mod token;
pub mod tokenstream;
pub mod visit;
Expand Down
19 changes: 9 additions & 10 deletions compiler/rustc_ast/src/mut_visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use smallvec::{SmallVec, smallvec};
use thin_vec::ThinVec;

use crate::ast::*;
use crate::ptr::P;
use crate::tokenstream::*;
use crate::visit::{AssocCtxt, BoundKind, FnCtxt, LifetimeCtxt, VisitorResult, try_visit};

Expand All @@ -41,7 +40,7 @@ pub(crate) trait MutVisitable<V: MutVisitor> {
fn visit_mut(&mut self, visitor: &mut V, extra: Self::Extra);
}

impl<V: MutVisitor, T: ?Sized> MutVisitable<V> for P<T>
impl<V: MutVisitor, T: ?Sized> MutVisitable<V> for Box<T>
where
T: MutVisitable<V>,
{
Expand Down Expand Up @@ -293,15 +292,15 @@ macro_rules! generate_flat_map_visitor_fns {
}

generate_flat_map_visitor_fns! {
visit_items, P<Item>, flat_map_item;
visit_foreign_items, P<ForeignItem>, flat_map_foreign_item;
visit_items, Box<Item>, flat_map_item;
visit_foreign_items, Box<ForeignItem>, flat_map_foreign_item;
visit_generic_params, GenericParam, flat_map_generic_param;
visit_stmts, Stmt, flat_map_stmt;
visit_exprs, P<Expr>, filter_map_expr;
visit_exprs, Box<Expr>, filter_map_expr;
visit_expr_fields, ExprField, flat_map_expr_field;
visit_pat_fields, PatField, flat_map_pat_field;
visit_variants, Variant, flat_map_variant;
visit_assoc_items, P<AssocItem>, flat_map_assoc_item, ctxt: AssocCtxt;
visit_assoc_items, Box<AssocItem>, flat_map_assoc_item, ctxt: AssocCtxt;
visit_where_predicates, WherePredicate, flat_map_where_predicate;
visit_params, Param, flat_map_param;
visit_field_defs, FieldDef, flat_map_field_def;
Expand Down Expand Up @@ -333,12 +332,12 @@ generate_walk_flat_map_fns! {
walk_flat_map_where_predicate(WherePredicate) => visit_where_predicate;
walk_flat_map_field_def(FieldDef) => visit_field_def;
walk_flat_map_expr_field(ExprField) => visit_expr_field;
walk_flat_map_item(P<Item>) => visit_item;
walk_flat_map_foreign_item(P<ForeignItem>) => visit_foreign_item;
walk_flat_map_assoc_item(P<AssocItem>, ctxt: AssocCtxt) => visit_assoc_item;
walk_flat_map_item(Box<Item>) => visit_item;
walk_flat_map_foreign_item(Box<ForeignItem>) => visit_foreign_item;
walk_flat_map_assoc_item(Box<AssocItem>, ctxt: AssocCtxt) => visit_assoc_item;
}

pub fn walk_filter_map_expr<T: MutVisitor>(vis: &mut T, mut e: P<Expr>) -> Option<P<Expr>> {
pub fn walk_filter_map_expr<T: MutVisitor>(vis: &mut T, mut e: Box<Expr>) -> Option<Box<Expr>> {
vis.visit_expr(&mut e);
Some(e)
}
Expand Down
11 changes: 0 additions & 11 deletions compiler/rustc_ast/src/ptr.rs

This file was deleted.

29 changes: 14 additions & 15 deletions compiler/rustc_ast/src/visit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ use rustc_span::{Ident, Span, Symbol};
use thin_vec::ThinVec;

use crate::ast::*;
use crate::ptr::P;
use crate::tokenstream::DelimSpan;

#[derive(Copy, Clone, Debug, PartialEq)]
Expand Down Expand Up @@ -82,7 +81,7 @@ pub(crate) trait Visitable<'a, V: Visitor<'a>> {
fn visit(&'a self, visitor: &mut V, extra: Self::Extra) -> V::Result;
}

impl<'a, V: Visitor<'a>, T: ?Sized> Visitable<'a, V> for P<T>
impl<'a, V: Visitor<'a>, T: ?Sized> Visitable<'a, V> for Box<T>
where
T: Visitable<'a, V>,
{
Expand Down Expand Up @@ -322,7 +321,7 @@ macro_rules! common_visitor_and_walkers {
Fn(FnCtxt, &'a $($mut)? Visibility, &'a $($mut)? Fn),

/// E.g., `|x, y| body`.
Closure(&'a $($mut)? ClosureBinder, &'a $($mut)? Option<CoroutineKind>, &'a $($mut)? P<FnDecl>, &'a $($mut)? P<Expr>),
Closure(&'a $($mut)? ClosureBinder, &'a $($mut)? Option<CoroutineKind>, &'a $($mut)? Box<FnDecl>, &'a $($mut)? Box<Expr>),
}

impl<'a> FnKind<'a> {
Expand Down Expand Up @@ -390,9 +389,9 @@ macro_rules! common_visitor_and_walkers {
ThinVec<(NodeId, Path)>,
ThinVec<PathSegment>,
ThinVec<PreciseCapturingArg>,
ThinVec<P<Pat>>,
ThinVec<P<Ty>>,
ThinVec<P<TyPat>>,
ThinVec<Box<Pat>>,
ThinVec<Box<Ty>>,
ThinVec<Box<TyPat>>,
);

// This macro generates `impl Visitable` and `impl MutVisitable` that forward to `Walkable`
Expand Down Expand Up @@ -676,11 +675,11 @@ macro_rules! common_visitor_and_walkers {
// Do nothing.
}

fn flat_map_foreign_item(&mut self, ni: P<ForeignItem>) -> SmallVec<[P<ForeignItem>; 1]> {
fn flat_map_foreign_item(&mut self, ni: Box<ForeignItem>) -> SmallVec<[Box<ForeignItem>; 1]> {
walk_flat_map_foreign_item(self, ni)
}

fn flat_map_item(&mut self, i: P<Item>) -> SmallVec<[P<Item>; 1]> {
fn flat_map_item(&mut self, i: Box<Item>) -> SmallVec<[Box<Item>; 1]> {
walk_flat_map_item(self, i)
}

Expand All @@ -690,9 +689,9 @@ macro_rules! common_visitor_and_walkers {

fn flat_map_assoc_item(
&mut self,
i: P<AssocItem>,
i: Box<AssocItem>,
ctxt: AssocCtxt,
) -> SmallVec<[P<AssocItem>; 1]> {
) -> SmallVec<[Box<AssocItem>; 1]> {
walk_flat_map_assoc_item(self, i, ctxt)
}

Expand All @@ -704,7 +703,7 @@ macro_rules! common_visitor_and_walkers {
walk_flat_map_arm(self, arm)
}

fn filter_map_expr(&mut self, e: P<Expr>) -> Option<P<Expr>> {
fn filter_map_expr(&mut self, e: Box<Expr>) -> Option<Box<Expr>> {
walk_filter_map_expr(self, e)
}

Expand Down Expand Up @@ -1144,15 +1143,15 @@ macro_rules! generate_list_visit_fns {
}

generate_list_visit_fns! {
visit_items, P<Item>, visit_item;
visit_foreign_items, P<ForeignItem>, visit_foreign_item;
visit_items, Box<Item>, visit_item;
visit_foreign_items, Box<ForeignItem>, visit_foreign_item;
visit_generic_params, GenericParam, visit_generic_param;
visit_stmts, Stmt, visit_stmt;
visit_exprs, P<Expr>, visit_expr;
visit_exprs, Box<Expr>, visit_expr;
visit_expr_fields, ExprField, visit_expr_field;
visit_pat_fields, PatField, visit_pat_field;
visit_variants, Variant, visit_variant;
visit_assoc_items, P<AssocItem>, visit_assoc_item, ctxt: AssocCtxt;
visit_assoc_items, Box<AssocItem>, visit_assoc_item, ctxt: AssocCtxt;
visit_where_predicates, WherePredicate, visit_where_predicate;
visit_params, Param, visit_param;
visit_field_defs, FieldDef, visit_field_def;
Expand Down
17 changes: 8 additions & 9 deletions compiler/rustc_ast_lowering/src/expr.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use std::ops::ControlFlow;
use std::sync::Arc;

use rustc_ast::ptr::P as AstP;
use rustc_ast::*;
use rustc_ast_pretty::pprust::expr_to_string;
use rustc_data_structures::stack::ensure_sufficient_stack;
Expand Down Expand Up @@ -53,7 +52,7 @@ impl<'v> rustc_ast::visit::Visitor<'v> for WillCreateDefIdsVisitor {
}

impl<'hir> LoweringContext<'_, 'hir> {
fn lower_exprs(&mut self, exprs: &[AstP<Expr>]) -> &'hir [hir::Expr<'hir>] {
fn lower_exprs(&mut self, exprs: &[Box<Expr>]) -> &'hir [hir::Expr<'hir>] {
self.arena.alloc_from_iter(exprs.iter().map(|x| self.lower_expr_mut(x)))
}

Expand Down Expand Up @@ -455,7 +454,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
fn lower_legacy_const_generics(
&mut self,
mut f: Expr,
args: ThinVec<AstP<Expr>>,
args: ThinVec<Box<Expr>>,
legacy_args_idx: &[usize],
) -> hir::ExprKind<'hir> {
let ExprKind::Path(None, path) = &mut f.kind else {
Expand Down Expand Up @@ -495,7 +494,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
self.create_def(node_id, None, DefKind::AnonConst, f.span);
let mut visitor = WillCreateDefIdsVisitor {};
let const_value = if let ControlFlow::Break(span) = visitor.visit_expr(&arg) {
AstP(Expr {
Box::new(Expr {
id: self.next_node_id(),
kind: ExprKind::Err(invalid_expr_error(self.tcx, span)),
span: f.span,
Expand All @@ -516,7 +515,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
// Add generic args to the last element of the path.
let last_segment = path.segments.last_mut().unwrap();
assert!(last_segment.args.is_none());
last_segment.args = Some(AstP(GenericArgs::AngleBracketed(AngleBracketedArgs {
last_segment.args = Some(Box::new(GenericArgs::AngleBracketed(AngleBracketedArgs {
span: DUMMY_SP,
args: generic_args,
})));
Expand Down Expand Up @@ -812,7 +811,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
self.lower_attrs(
inner_hir_id,
&[Attribute {
kind: AttrKind::Normal(ptr::P(NormalAttr::from_ident(Ident::new(
kind: AttrKind::Normal(Box::new(NormalAttr::from_ident(Ident::new(
sym::track_caller,
span,
)))),
Expand Down Expand Up @@ -1285,7 +1284,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
fn extract_tuple_struct_path<'a>(
&mut self,
expr: &'a Expr,
) -> Option<(&'a Option<AstP<QSelf>>, &'a Path)> {
) -> Option<(&'a Option<Box<QSelf>>, &'a Path)> {
if let ExprKind::Path(qself, path) = &expr.kind {
// Does the path resolve to something disallowed in a tuple struct/variant pattern?
if let Some(partial_res) = self.resolver.get_partial_res(expr.id) {
Expand All @@ -1307,7 +1306,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
fn extract_unit_struct_path<'a>(
&mut self,
expr: &'a Expr,
) -> Option<(&'a Option<AstP<QSelf>>, &'a Path)> {
) -> Option<(&'a Option<Box<QSelf>>, &'a Path)> {
if let ExprKind::Path(qself, path) = &expr.kind {
// Does the path resolve to something disallowed in a unit struct/variant pattern?
if let Some(partial_res) = self.resolver.get_partial_res(expr.id) {
Expand Down Expand Up @@ -1478,7 +1477,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
/// Each sub-assignment is recorded in `assignments`.
fn destructure_sequence(
&mut self,
elements: &[AstP<Expr>],
elements: &[Box<Expr>],
ctx: &str,
eq_sign_span: Span,
assignments: &mut Vec<hir::Stmt<'hir>>,
Expand Down
5 changes: 2 additions & 3 deletions compiler/rustc_ast_lowering/src/item.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
use rustc_abi::ExternAbi;
use rustc_ast::ptr::P;
use rustc_ast::visit::AssocCtxt;
use rustc_ast::*;
use rustc_errors::{E0570, ErrorGuaranteed, struct_span_code_err};
Expand Down Expand Up @@ -102,7 +101,7 @@ impl<'a, 'hir> ItemLowerer<'a, 'hir> {
impl<'hir> LoweringContext<'_, 'hir> {
pub(super) fn lower_mod(
&mut self,
items: &[P<Item>],
items: &[Box<Item>],
spans: &ModSpans,
) -> &'hir hir::Mod<'hir> {
self.arena.alloc(hir::Mod {
Expand Down Expand Up @@ -462,7 +461,7 @@ impl<'hir> LoweringContext<'_, 'hir> {
}
ItemKind::MacroDef(ident, MacroDef { body, macro_rules }) => {
let ident = self.lower_ident(*ident);
let body = P(self.lower_delim_args(body));
let body = Box::new(self.lower_delim_args(body));
let def_id = self.local_def_id(id);
let def_kind = self.tcx.def_kind(def_id);
let DefKind::Macro(macro_kind) = def_kind else {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_ast_lowering/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1217,7 +1217,7 @@ impl<'a, 'hir> LoweringContext<'a, 'hir> {
fn lower_path_ty(
&mut self,
t: &Ty,
qself: &Option<ptr::P<QSelf>>,
qself: &Option<Box<QSelf>>,
path: &Path,
param_mode: ParamMode,
itctx: ImplTraitContext,
Expand Down
Loading
Loading