From a35675d38f10cf19c9512d5d621338fc00530ad3 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 27 May 2025 01:57:43 +1000 Subject: [PATCH 1/6] Remove `'static` bounds on `P`. These date back to 2014. I don't think they're needed any more. --- compiler/rustc_ast/src/ptr.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/compiler/rustc_ast/src/ptr.rs b/compiler/rustc_ast/src/ptr.rs index dd923305cdfd9..1e6a5e91f2320 100644 --- a/compiler/rustc_ast/src/ptr.rs +++ b/compiler/rustc_ast/src/ptr.rs @@ -32,11 +32,11 @@ pub struct P { /// Construct a `P` from a `T` value. #[allow(non_snake_case)] -pub fn P(value: T) -> P { +pub fn P(value: T) -> P { P { ptr: Box::new(value) } } -impl P { +impl P { /// Move out of the pointer. /// Intended for chaining transformations not covered by `map`. pub fn and_then(self, f: F) -> U @@ -86,7 +86,7 @@ impl DerefMut for P { } } -impl Clone for P { +impl Clone for P { fn clone(&self) -> P { P((**self).clone()) } @@ -110,7 +110,7 @@ impl fmt::Pointer for P { } } -impl> Decodable for P { +impl> Decodable for P { fn decode(d: &mut D) -> P { P(Decodable::decode(d)) } From 6973fa08a3a4044c87b9da9e66cb1ca17f89b889 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 27 May 2025 01:42:51 +1000 Subject: [PATCH 2/6] Remove `P::map`. It's barely used, and the places that use it are better if they don't. --- compiler/rustc_ast/src/ast.rs | 7 ++-- compiler/rustc_ast/src/ptr.rs | 11 ------ .../src/proc_macro_harness.rs | 36 +++++++++---------- compiler/rustc_builtin_macros/src/test.rs | 5 +-- 4 files changed, 21 insertions(+), 38 deletions(-) diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index a16219361c051..c4be07ba06816 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -1123,10 +1123,9 @@ impl Stmt { pub fn add_trailing_semicolon(mut self) -> Self { self.kind = match self.kind { StmtKind::Expr(expr) => StmtKind::Semi(expr), - StmtKind::MacCall(mac) => { - StmtKind::MacCall(mac.map(|MacCallStmt { mac, style: _, attrs, tokens }| { - MacCallStmt { mac, style: MacStmtStyle::Semicolon, attrs, tokens } - })) + StmtKind::MacCall(mut mac) => { + mac.style = MacStmtStyle::Semicolon; + StmtKind::MacCall(mac) } kind => kind, }; diff --git a/compiler/rustc_ast/src/ptr.rs b/compiler/rustc_ast/src/ptr.rs index 1e6a5e91f2320..a1b265cf0a949 100644 --- a/compiler/rustc_ast/src/ptr.rs +++ b/compiler/rustc_ast/src/ptr.rs @@ -51,17 +51,6 @@ impl P { *self.ptr } - /// Produce a new `P` from `self` without reallocating. - pub fn map(mut self, f: F) -> P - where - F: FnOnce(T) -> T, - { - let x = f(*self.ptr); - *self.ptr = x; - - self - } - /// Optionally produce a new `P` from `self` without reallocating. pub fn filter_map(mut self, f: F) -> Option> where diff --git a/compiler/rustc_builtin_macros/src/proc_macro_harness.rs b/compiler/rustc_builtin_macros/src/proc_macro_harness.rs index a91f2d38a93ae..daf480a9ce472 100644 --- a/compiler/rustc_builtin_macros/src/proc_macro_harness.rs +++ b/compiler/rustc_builtin_macros/src/proc_macro_harness.rs @@ -354,30 +354,28 @@ fn mk_decls(cx: &mut ExtCtxt<'_>, macros: &[ProcMacro]) -> P { }) .collect(); - let decls_static = cx - .item_static( + let mut decls_static = cx.item_static( + span, + Ident::new(sym::_DECLS, span), + cx.ty_ref( span, - Ident::new(sym::_DECLS, span), - cx.ty_ref( + cx.ty( span, - cx.ty( - span, - ast::TyKind::Slice( - cx.ty_path(cx.path(span, vec![proc_macro, bridge, client, proc_macro_ty])), - ), + ast::TyKind::Slice( + cx.ty_path(cx.path(span, vec![proc_macro, bridge, client, proc_macro_ty])), ), - None, - ast::Mutability::Not, ), + None, ast::Mutability::Not, - cx.expr_array_ref(span, decls), - ) - .map(|mut i| { - i.attrs.push(cx.attr_word(sym::rustc_proc_macro_decls, span)); - i.attrs.push(cx.attr_word(sym::used, span)); - i.attrs.push(cx.attr_nested_word(sym::allow, sym::deprecated, span)); - i - }); + ), + ast::Mutability::Not, + cx.expr_array_ref(span, decls), + ); + decls_static.attrs.extend([ + cx.attr_word(sym::rustc_proc_macro_decls, span), + cx.attr_word(sym::used, span), + cx.attr_nested_word(sym::allow, sym::deprecated, span), + ]); let block = cx.expr_block( cx.block(span, thin_vec![cx.stmt_item(span, krate), cx.stmt_item(span, decls_static)]), diff --git a/compiler/rustc_builtin_macros/src/test.rs b/compiler/rustc_builtin_macros/src/test.rs index 1cef4f9514cd7..fbe91531e5a33 100644 --- a/compiler/rustc_builtin_macros/src/test.rs +++ b/compiler/rustc_builtin_macros/src/test.rs @@ -381,10 +381,7 @@ pub(crate) fn expand_test_or_bench( .into(), ), ); - test_const = test_const.map(|mut tc| { - tc.vis.kind = ast::VisibilityKind::Public; - tc - }); + test_const.vis.kind = ast::VisibilityKind::Public; // extern crate test let test_extern = From 0f285e346f0432b08d82e85fc51419994b76504b Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 27 May 2025 02:14:33 +1000 Subject: [PATCH 3/6] Remove the one use of `P<[T]>`. A `Vec` is fine, the additional word (vector vs. boxed slice) doesn't matter here. --- compiler/rustc_ast/src/ast.rs | 2 +- compiler/rustc_parse/src/parser/expr.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/compiler/rustc_ast/src/ast.rs b/compiler/rustc_ast/src/ast.rs index c4be07ba06816..4c821c00ad64c 100644 --- a/compiler/rustc_ast/src/ast.rs +++ b/compiler/rustc_ast/src/ast.rs @@ -1714,7 +1714,7 @@ pub enum ExprKind { /// /// Usually not written directly in user code but /// indirectly via the macro `core::mem::offset_of!(...)`. - OffsetOf(P, P<[Ident]>), + OffsetOf(P, Vec), /// A macro invocation; pre-expansion. MacCall(P), diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 2a7910a6af4dd..6e134bad7bdae 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -1119,7 +1119,7 @@ impl<'a> Parser<'a> { /// Parse the field access used in offset_of, matched by `$(e:expr)+`. /// Currently returns a list of idents. However, it should be possible in /// future to also do array indices, which might be arbitrary expressions. - fn parse_floating_field_access(&mut self) -> PResult<'a, P<[Ident]>> { + fn parse_floating_field_access(&mut self) -> PResult<'a, Vec> { let mut fields = Vec::new(); let mut trailing_dot = None; From 68597509aa1e50f67000f7c36ccc3378b58e5f5d Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 27 May 2025 02:16:52 +1000 Subject: [PATCH 4/6] Remove support for `P<[T]>`. It's no longer used. --- compiler/rustc_ast/src/ptr.rs | 79 +---------------------------------- 1 file changed, 1 insertion(+), 78 deletions(-) diff --git a/compiler/rustc_ast/src/ptr.rs b/compiler/rustc_ast/src/ptr.rs index a1b265cf0a949..899d8eb7ca99a 100644 --- a/compiler/rustc_ast/src/ptr.rs +++ b/compiler/rustc_ast/src/ptr.rs @@ -19,10 +19,10 @@ use std::fmt::{self, Debug, Display}; use std::ops::{Deref, DerefMut}; -use std::{slice, vec}; use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; + /// An owned smart pointer. /// /// See the [module level documentation][crate::ptr] for details. @@ -111,83 +111,6 @@ impl> Encodable for P { } } -impl P<[T]> { - // FIXME(const-hack) make this const again - pub fn new() -> P<[T]> { - P { ptr: Box::default() } - } - - #[inline(never)] - pub fn from_vec(v: Vec) -> P<[T]> { - P { ptr: v.into_boxed_slice() } - } - - #[inline(never)] - pub fn into_vec(self) -> Vec { - self.ptr.into_vec() - } -} - -impl Default for P<[T]> { - /// Creates an empty `P<[T]>`. - fn default() -> P<[T]> { - P::new() - } -} - -impl Clone for P<[T]> { - fn clone(&self) -> P<[T]> { - P::from_vec(self.to_vec()) - } -} - -impl From> for P<[T]> { - fn from(v: Vec) -> Self { - P::from_vec(v) - } -} - -impl From> for Vec { - fn from(val: P<[T]>) -> Self { - val.into_vec() - } -} - -impl FromIterator for P<[T]> { - fn from_iter>(iter: I) -> P<[T]> { - P::from_vec(iter.into_iter().collect()) - } -} - -impl IntoIterator for P<[T]> { - type Item = T; - type IntoIter = vec::IntoIter; - - fn into_iter(self) -> Self::IntoIter { - self.into_vec().into_iter() - } -} - -impl<'a, T> IntoIterator for &'a P<[T]> { - type Item = &'a T; - type IntoIter = slice::Iter<'a, T>; - fn into_iter(self) -> Self::IntoIter { - self.ptr.iter() - } -} - -impl> Encodable for P<[T]> { - fn encode(&self, s: &mut S) { - Encodable::encode(&**self, s); - } -} - -impl> Decodable for P<[T]> { - fn decode(d: &mut D) -> P<[T]> { - P::from_vec(Decodable::decode(d)) - } -} - impl HashStable for P where T: ?Sized + HashStable, From c42d1fc2c6ea5a35d8d74f909a1f69dee5d9ce56 Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 27 May 2025 01:20:48 +1000 Subject: [PATCH 5/6] Remove unused `P` stuff. --- compiler/rustc_ast/src/ptr.rs | 44 ++--------------------------------- 1 file changed, 2 insertions(+), 42 deletions(-) diff --git a/compiler/rustc_ast/src/ptr.rs b/compiler/rustc_ast/src/ptr.rs index 899d8eb7ca99a..91f29a4c289f6 100644 --- a/compiler/rustc_ast/src/ptr.rs +++ b/compiler/rustc_ast/src/ptr.rs @@ -17,10 +17,9 @@ //! heap, for example). Moreover, a switch to, e.g., `P<'a, T>` would be easy //! and mostly automated. -use std::fmt::{self, Debug, Display}; +use std::fmt::{self, Debug}; use std::ops::{Deref, DerefMut}; -use rustc_data_structures::stable_hasher::{HashStable, StableHasher}; use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; /// An owned smart pointer. @@ -37,28 +36,10 @@ pub fn P(value: T) -> P { } impl P { - /// Move out of the pointer. - /// Intended for chaining transformations not covered by `map`. - pub fn and_then(self, f: F) -> U - where - F: FnOnce(T) -> U, - { - f(*self.ptr) - } - - /// Equivalent to `and_then(|x| x)`. + /// Consume the `P` and return the wrapped value. pub fn into_inner(self) -> T { *self.ptr } - - /// Optionally produce a new `P` from `self` without reallocating. - pub fn filter_map(mut self, f: F) -> Option> - where - F: FnOnce(T) -> Option, - { - *self.ptr = f(*self.ptr)?; - Some(self) - } } impl Deref for P { @@ -87,18 +68,6 @@ impl Debug for P { } } -impl Display for P { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - Display::fmt(&**self, f) - } -} - -impl fmt::Pointer for P { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - fmt::Pointer::fmt(&self.ptr, f) - } -} - impl> Decodable for P { fn decode(d: &mut D) -> P { P(Decodable::decode(d)) @@ -110,12 +79,3 @@ impl> Encodable for P { (**self).encode(s); } } - -impl HashStable for P -where - T: ?Sized + HashStable, -{ - fn hash_stable(&self, hcx: &mut CTX, hasher: &mut StableHasher) { - (**self).hash_stable(hcx, hasher); - } -} From 991c91fdaa5862835799abfd9c2349e06277097e Mon Sep 17 00:00:00 2001 From: Nicholas Nethercote Date: Tue, 27 May 2025 02:32:22 +1000 Subject: [PATCH 6/6] Reduce `P` to a typedef of `Box`. Keep the `P` constructor function for now, to minimize immediate churn. All the `into_inner` calls are removed, which is nice. --- compiler/rustc_ast/src/attr/mod.rs | 2 +- compiler/rustc_ast/src/ptr.rs | 80 ++----------------- .../rustc_builtin_macros/src/deriving/mod.rs | 2 +- .../rustc_builtin_macros/src/pattern_type.rs | 20 +++-- compiler/rustc_builtin_macros/src/test.rs | 8 +- compiler/rustc_expand/src/base.rs | 2 +- compiler/rustc_expand/src/expand.rs | 37 ++++----- .../rustc_parse/src/parser/diagnostics.rs | 4 +- compiler/rustc_parse/src/parser/expr.rs | 6 +- compiler/rustc_parse/src/parser/item.rs | 4 +- compiler/rustc_parse/src/parser/pat.rs | 2 +- compiler/rustc_parse/src/parser/ty.rs | 6 +- .../clippy_lints/src/unnested_or_patterns.rs | 2 +- src/tools/rustfmt/src/modules.rs | 2 +- src/tools/rustfmt/src/parse/macros/cfg_if.rs | 2 +- 15 files changed, 48 insertions(+), 131 deletions(-) diff --git a/compiler/rustc_ast/src/attr/mod.rs b/compiler/rustc_ast/src/attr/mod.rs index f165c4ddcdd4d..621e3042b62e1 100644 --- a/compiler/rustc_ast/src/attr/mod.rs +++ b/compiler/rustc_ast/src/attr/mod.rs @@ -63,7 +63,7 @@ impl Attribute { pub fn unwrap_normal_item(self) -> AttrItem { match self.kind { - AttrKind::Normal(normal) => normal.into_inner().item, + AttrKind::Normal(normal) => normal.item, AttrKind::DocComment(..) => panic!("unexpected doc comment"), } } diff --git a/compiler/rustc_ast/src/ptr.rs b/compiler/rustc_ast/src/ptr.rs index 91f29a4c289f6..fffeab8bbca66 100644 --- a/compiler/rustc_ast/src/ptr.rs +++ b/compiler/rustc_ast/src/ptr.rs @@ -1,81 +1,11 @@ -//! The AST pointer. -//! -//! Provides [`P`][struct@P], an owned smart pointer. -//! -//! # Motivations and benefits -//! -//! * **Identity**: sharing AST nodes is problematic for the various analysis -//! passes (e.g., one may be able to bypass the borrow checker with a shared -//! `ExprKind::AddrOf` node taking a mutable borrow). -//! -//! * **Efficiency**: folding can reuse allocation space for `P` and `Vec`, -//! the latter even when the input and output types differ (as it would be the -//! case with arenas or a GADT AST using type parameters to toggle features). -//! -//! * **Maintainability**: `P` provides an interface, which can remain fully -//! functional even if the implementation changes (using a special thread-local -//! heap, for example). Moreover, a switch to, e.g., `P<'a, T>` would be easy -//! and mostly automated. - -use std::fmt::{self, Debug}; -use std::ops::{Deref, DerefMut}; - -use rustc_serialize::{Decodable, Decoder, Encodable, Encoder}; - -/// An owned smart pointer. +/// A pointer type that uniquely owns a heap allocation of type T. /// -/// See the [module level documentation][crate::ptr] for details. -pub struct P { - ptr: Box, -} +/// This used to be its own type, but now it's just a typedef for `Box` and we are planning to +/// remove it soon. +pub type P = Box; /// Construct a `P` from a `T` value. #[allow(non_snake_case)] pub fn P(value: T) -> P { - P { ptr: Box::new(value) } -} - -impl P { - /// Consume the `P` and return the wrapped value. - pub fn into_inner(self) -> T { - *self.ptr - } -} - -impl Deref for P { - type Target = T; - - fn deref(&self) -> &T { - &self.ptr - } -} - -impl DerefMut for P { - fn deref_mut(&mut self) -> &mut T { - &mut self.ptr - } -} - -impl Clone for P { - fn clone(&self) -> P { - P((**self).clone()) - } -} - -impl Debug for P { - fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - Debug::fmt(&self.ptr, f) - } -} - -impl> Decodable for P { - fn decode(d: &mut D) -> P { - P(Decodable::decode(d)) - } -} - -impl> Encodable for P { - fn encode(&self, s: &mut S) { - (**self).encode(s); - } + Box::new(value) } diff --git a/compiler/rustc_builtin_macros/src/deriving/mod.rs b/compiler/rustc_builtin_macros/src/deriving/mod.rs index 50e7b989ed8ab..e45d09b57960c 100644 --- a/compiler/rustc_builtin_macros/src/deriving/mod.rs +++ b/compiler/rustc_builtin_macros/src/deriving/mod.rs @@ -57,7 +57,7 @@ impl MultiItemModifier for BuiltinDerive { let mut items = Vec::new(); match item { Annotatable::Stmt(stmt) => { - if let ast::StmtKind::Item(item) = stmt.into_inner().kind { + if let ast::StmtKind::Item(item) = stmt.kind { (self.0)( ecx, span, diff --git a/compiler/rustc_builtin_macros/src/pattern_type.rs b/compiler/rustc_builtin_macros/src/pattern_type.rs index 3529e5525fcd2..b61af0b0aaa12 100644 --- a/compiler/rustc_builtin_macros/src/pattern_type.rs +++ b/compiler/rustc_builtin_macros/src/pattern_type.rs @@ -30,14 +30,12 @@ fn parse_pat_ty<'a>(cx: &mut ExtCtxt<'a>, stream: TokenStream) -> PResult<'a, (P let pat = pat_to_ty_pat( cx, - parser - .parse_pat_no_top_guard( - None, - RecoverComma::No, - RecoverColon::No, - CommaRecoveryMode::EitherTupleOrPipe, - )? - .into_inner(), + *parser.parse_pat_no_top_guard( + None, + RecoverComma::No, + RecoverColon::No, + CommaRecoveryMode::EitherTupleOrPipe, + )?, ); if parser.token != token::Eof { @@ -58,9 +56,9 @@ fn pat_to_ty_pat(cx: &mut ExtCtxt<'_>, pat: ast::Pat) -> P { end.map(|value| P(AnonConst { id: DUMMY_NODE_ID, value })), include_end, ), - ast::PatKind::Or(variants) => TyPatKind::Or( - variants.into_iter().map(|pat| pat_to_ty_pat(cx, pat.into_inner())).collect(), - ), + ast::PatKind::Or(variants) => { + TyPatKind::Or(variants.into_iter().map(|pat| pat_to_ty_pat(cx, *pat)).collect()) + } ast::PatKind::Err(guar) => TyPatKind::Err(guar), _ => TyPatKind::Err(cx.dcx().span_err(pat.span, "pattern not supported in pattern types")), }; diff --git a/compiler/rustc_builtin_macros/src/test.rs b/compiler/rustc_builtin_macros/src/test.rs index fbe91531e5a33..b439fa34f5b12 100644 --- a/compiler/rustc_builtin_macros/src/test.rs +++ b/compiler/rustc_builtin_macros/src/test.rs @@ -40,7 +40,7 @@ pub(crate) fn expand_test_case( let (mut item, is_stmt) = match anno_item { Annotatable::Item(item) => (item, false), Annotatable::Stmt(stmt) if let ast::StmtKind::Item(_) = stmt.kind => { - if let ast::StmtKind::Item(i) = stmt.into_inner().kind { + if let ast::StmtKind::Item(i) = stmt.kind { (i, true) } else { unreachable!() @@ -120,11 +120,7 @@ pub(crate) fn expand_test_or_bench( Annotatable::Item(i) => (i, false), Annotatable::Stmt(stmt) if matches!(stmt.kind, ast::StmtKind::Item(_)) => { // FIXME: Use an 'if let' guard once they are implemented - if let ast::StmtKind::Item(i) = stmt.into_inner().kind { - (i, true) - } else { - unreachable!() - } + if let ast::StmtKind::Item(i) = stmt.kind { (i, true) } else { unreachable!() } } other => { not_testable_error(cx, attr_sp, None); diff --git a/compiler/rustc_expand/src/base.rs b/compiler/rustc_expand/src/base.rs index 55751aa49089b..058e45cdc4cf5 100644 --- a/compiler/rustc_expand/src/base.rs +++ b/compiler/rustc_expand/src/base.rs @@ -167,7 +167,7 @@ impl Annotatable { pub fn expect_stmt(self) -> ast::Stmt { match self { - Annotatable::Stmt(stmt) => stmt.into_inner(), + Annotatable::Stmt(stmt) => *stmt, _ => panic!("expected statement"), } } diff --git a/compiler/rustc_expand/src/expand.rs b/compiler/rustc_expand/src/expand.rs index 81d4d59ee0451..4c7bc912f8fda 100644 --- a/compiler/rustc_expand/src/expand.rs +++ b/compiler/rustc_expand/src/expand.rs @@ -1188,9 +1188,8 @@ impl InvocationCollectorNode for P { matches!(self.kind, ItemKind::MacCall(..)) } fn take_mac_call(self) -> (P, ast::AttrVec, AddSemicolon) { - let node = self.into_inner(); - match node.kind { - ItemKind::MacCall(mac) => (mac, node.attrs, AddSemicolon::No), + match self.kind { + ItemKind::MacCall(mac) => (mac, self.attrs, AddSemicolon::No), _ => unreachable!(), } } @@ -1344,7 +1343,7 @@ impl InvocationCollectorNode for AstNodeWrapper, TraitItemTag> matches!(self.wrapped.kind, AssocItemKind::MacCall(..)) } fn take_mac_call(self) -> (P, ast::AttrVec, AddSemicolon) { - let item = self.wrapped.into_inner(); + let item = self.wrapped; match item.kind { AssocItemKind::MacCall(mac) => (mac, item.attrs, AddSemicolon::No), _ => unreachable!(), @@ -1385,7 +1384,7 @@ impl InvocationCollectorNode for AstNodeWrapper, ImplItemTag> matches!(self.wrapped.kind, AssocItemKind::MacCall(..)) } fn take_mac_call(self) -> (P, ast::AttrVec, AddSemicolon) { - let item = self.wrapped.into_inner(); + let item = self.wrapped; match item.kind { AssocItemKind::MacCall(mac) => (mac, item.attrs, AddSemicolon::No), _ => unreachable!(), @@ -1426,7 +1425,7 @@ impl InvocationCollectorNode for AstNodeWrapper, TraitImplItem matches!(self.wrapped.kind, AssocItemKind::MacCall(..)) } fn take_mac_call(self) -> (P, ast::AttrVec, AddSemicolon) { - let item = self.wrapped.into_inner(); + let item = self.wrapped; match item.kind { AssocItemKind::MacCall(mac) => (mac, item.attrs, AddSemicolon::No), _ => unreachable!(), @@ -1464,9 +1463,8 @@ impl InvocationCollectorNode for P { matches!(self.kind, ForeignItemKind::MacCall(..)) } fn take_mac_call(self) -> (P, ast::AttrVec, AddSemicolon) { - let node = self.into_inner(); - match node.kind { - ForeignItemKind::MacCall(mac) => (mac, node.attrs, AddSemicolon::No), + match self.kind { + ForeignItemKind::MacCall(mac) => (mac, self.attrs, AddSemicolon::No), _ => unreachable!(), } } @@ -1601,16 +1599,16 @@ impl InvocationCollectorNode for ast::Stmt { // `StmtKind`s and treat them as statement macro invocations, not as items or expressions. let (add_semicolon, mac, attrs) = match self.kind { StmtKind::MacCall(mac) => { - let ast::MacCallStmt { mac, style, attrs, .. } = mac.into_inner(); + let ast::MacCallStmt { mac, style, attrs, .. } = *mac; (style == MacStmtStyle::Semicolon, mac, attrs) } - StmtKind::Item(item) => match item.into_inner() { + StmtKind::Item(item) => match *item { ast::Item { kind: ItemKind::MacCall(mac), attrs, .. } => { (mac.args.need_semicolon(), mac, attrs) } _ => unreachable!(), }, - StmtKind::Semi(expr) => match expr.into_inner() { + StmtKind::Semi(expr) => match *expr { ast::Expr { kind: ExprKind::MacCall(mac), attrs, .. } => { (mac.args.need_semicolon(), mac, attrs) } @@ -1691,8 +1689,7 @@ impl InvocationCollectorNode for P { matches!(self.kind, ast::TyKind::MacCall(..)) } fn take_mac_call(self) -> (P, ast::AttrVec, AddSemicolon) { - let node = self.into_inner(); - match node.kind { + match self.kind { TyKind::MacCall(mac) => (mac, AttrVec::new(), AddSemicolon::No), _ => unreachable!(), } @@ -1715,8 +1712,7 @@ impl InvocationCollectorNode for P { matches!(self.kind, PatKind::MacCall(..)) } fn take_mac_call(self) -> (P, ast::AttrVec, AddSemicolon) { - let node = self.into_inner(); - match node.kind { + match self.kind { PatKind::MacCall(mac) => (mac, AttrVec::new(), AddSemicolon::No), _ => unreachable!(), } @@ -1742,9 +1738,8 @@ impl InvocationCollectorNode for P { matches!(self.kind, ExprKind::MacCall(..)) } fn take_mac_call(self) -> (P, ast::AttrVec, AddSemicolon) { - let node = self.into_inner(); - match node.kind { - ExprKind::MacCall(mac) => (mac, node.attrs, AddSemicolon::No), + match self.kind { + ExprKind::MacCall(mac) => (mac, self.attrs, AddSemicolon::No), _ => unreachable!(), } } @@ -1768,7 +1763,7 @@ impl InvocationCollectorNode for AstNodeWrapper, OptExprTag> { matches!(self.wrapped.kind, ast::ExprKind::MacCall(..)) } fn take_mac_call(self) -> (P, ast::AttrVec, AddSemicolon) { - let node = self.wrapped.into_inner(); + let node = self.wrapped; match node.kind { ExprKind::MacCall(mac) => (mac, node.attrs, AddSemicolon::No), _ => unreachable!(), @@ -1806,7 +1801,7 @@ impl InvocationCollectorNode for AstNodeWrapper, MethodReceiverTag> matches!(self.wrapped.kind, ast::ExprKind::MacCall(..)) } fn take_mac_call(self) -> (P, ast::AttrVec, AddSemicolon) { - let node = self.wrapped.into_inner(); + let node = self.wrapped; match node.kind { ExprKind::MacCall(mac) => (mac, node.attrs, AddSemicolon::No), _ => unreachable!(), diff --git a/compiler/rustc_parse/src/parser/diagnostics.rs b/compiler/rustc_parse/src/parser/diagnostics.rs index 6277dde7c974c..b49a13ce584fb 100644 --- a/compiler/rustc_parse/src/parser/diagnostics.rs +++ b/compiler/rustc_parse/src/parser/diagnostics.rs @@ -2273,9 +2273,9 @@ impl<'a> Parser<'a> { ), // Also catches `fn foo(&a)`. PatKind::Ref(ref inner_pat, mutab) - if matches!(inner_pat.clone().into_inner().kind, PatKind::Ident(..)) => + if matches!(inner_pat.clone().kind, PatKind::Ident(..)) => { - match inner_pat.clone().into_inner().kind { + match inner_pat.clone().kind { PatKind::Ident(_, ident, _) => { let mutab = mutab.prefix_str(); ( diff --git a/compiler/rustc_parse/src/parser/expr.rs b/compiler/rustc_parse/src/parser/expr.rs index 6e134bad7bdae..5824c2aa4057c 100644 --- a/compiler/rustc_parse/src/parser/expr.rs +++ b/compiler/rustc_parse/src/parser/expr.rs @@ -3450,10 +3450,8 @@ impl<'a> Parser<'a> { // Detect and recover from `($pat if $cond) => $arm`. // FIXME(guard_patterns): convert this to a normal guard instead let span = pat.span; - let ast::PatKind::Paren(subpat) = pat.into_inner().kind else { unreachable!() }; - let ast::PatKind::Guard(_, mut cond) = subpat.into_inner().kind else { - unreachable!() - }; + let ast::PatKind::Paren(subpat) = pat.kind else { unreachable!() }; + let ast::PatKind::Guard(_, mut cond) = subpat.kind else { unreachable!() }; self.psess.gated_spans.ungate_last(sym::guard_patterns, cond.span); CondChecker::new(self, LetChainsPolicy::AlwaysAllowed).visit_expr(&mut cond); let right = self.prev_token.span; diff --git a/compiler/rustc_parse/src/parser/item.rs b/compiler/rustc_parse/src/parser/item.rs index babc55ccc0f9e..e9654e61eb83f 100644 --- a/compiler/rustc_parse/src/parser/item.rs +++ b/compiler/rustc_parse/src/parser/item.rs @@ -145,7 +145,7 @@ impl<'a> Parser<'a> { { let mut item = item.expect("an actual item"); attrs.prepend_to_nt_inner(&mut item.attrs); - return Ok(Some(item.into_inner())); + return Ok(Some(*item)); } self.collect_tokens(None, attrs, force_collect, |this, mut attrs| { @@ -637,7 +637,7 @@ impl<'a> Parser<'a> { self.dcx().emit_err(errors::MissingForInTraitImpl { span: missing_for_span }); } - let ty_first = ty_first.into_inner(); + 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, diff --git a/compiler/rustc_parse/src/parser/pat.rs b/compiler/rustc_parse/src/parser/pat.rs index d6ff80b2eb4c6..7a226136e2353 100644 --- a/compiler/rustc_parse/src/parser/pat.rs +++ b/compiler/rustc_parse/src/parser/pat.rs @@ -1086,7 +1086,7 @@ impl<'a> Parser<'a> { if matches!(pat.kind, PatKind::Ident(BindingMode(ByRef::Yes(_), Mutability::Mut), ..)) { self.psess.gated_spans.gate(sym::mut_ref, pat.span); } - Ok(pat.into_inner().kind) + Ok(pat.kind) } /// Turn all by-value immutable bindings in a pattern into mutable bindings. diff --git a/compiler/rustc_parse/src/parser/ty.rs b/compiler/rustc_parse/src/parser/ty.rs index 17481731b1107..460cf23c393fe 100644 --- a/compiler/rustc_parse/src/parser/ty.rs +++ b/compiler/rustc_parse/src/parser/ty.rs @@ -404,7 +404,7 @@ impl<'a> Parser<'a> { })?; if ts.len() == 1 && matches!(trailing, Trailing::No) { - let ty = ts.into_iter().next().unwrap().into_inner(); + let ty = ts.into_iter().next().unwrap(); let maybe_bounds = allow_plus == AllowPlus::Yes && self.token.is_like_plus(); match ty.kind { // `(TY_BOUND_NOPAREN) + BOUND + ...`. @@ -420,7 +420,7 @@ impl<'a> Parser<'a> { self.parse_remaining_bounds(bounds, true) } // `(TYPE)` - _ => Ok(TyKind::Paren(P(ty))), + _ => Ok(TyKind::Paren(ty)), } } else { Ok(TyKind::Tup(ts)) @@ -1295,7 +1295,7 @@ impl<'a> Parser<'a> { ) -> PResult<'a, ()> { let fn_path_segment = fn_path.segments.last_mut().unwrap(); let generic_args = if let Some(p_args) = &fn_path_segment.args { - p_args.clone().into_inner() + *p_args.clone() } else { // Normally it wouldn't come here because the upstream should have parsed // generic parameters (otherwise it's impossible to call this function). diff --git a/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs b/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs index 9ad184450de43..b839b6f56728c 100644 --- a/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs +++ b/src/tools/clippy/clippy_lints/src/unnested_or_patterns.rs @@ -426,7 +426,7 @@ fn drain_matching( // Check if we should extract, but only if `idx >= start`. if idx > start && predicate(&alternatives[i].kind) { let pat = alternatives.remove(i); - tail_or.push(extract(pat.into_inner().kind)); + tail_or.push(extract(pat.kind)); } else { i += 1; } diff --git a/src/tools/rustfmt/src/modules.rs b/src/tools/rustfmt/src/modules.rs index bc5a6d3e70402..44c8123517c56 100644 --- a/src/tools/rustfmt/src/modules.rs +++ b/src/tools/rustfmt/src/modules.rs @@ -174,7 +174,7 @@ impl<'ast, 'psess, 'c> ModResolver<'ast, 'psess> { ) -> Result<(), ModuleResolutionError> { for item in items { if is_cfg_if(&item) { - self.visit_cfg_if(Cow::Owned(item.into_inner()))?; + self.visit_cfg_if(Cow::Owned(*item))?; continue; } diff --git a/src/tools/rustfmt/src/parse/macros/cfg_if.rs b/src/tools/rustfmt/src/parse/macros/cfg_if.rs index 30b83373c1702..26bf6c5326f5f 100644 --- a/src/tools/rustfmt/src/parse/macros/cfg_if.rs +++ b/src/tools/rustfmt/src/parse/macros/cfg_if.rs @@ -62,7 +62,7 @@ fn parse_cfg_if_inner<'a>( while parser.token != TokenKind::CloseBrace && parser.token.kind != TokenKind::Eof { let item = match parser.parse_item(ForceCollect::No) { - Ok(Some(item_ptr)) => item_ptr.into_inner(), + Ok(Some(item_ptr)) => *item_ptr, Ok(None) => continue, Err(err) => { err.cancel();