Skip to content

Commit 8ef81cc

Browse files
authored
Unrolled build for rust-lang#123393
Rollup merge of rust-lang#123393 - aDotInTheVoid:ast-p-docs, r=Nilstrieb rustc_ast: Update `P<T>` docs to reflect mutable status. `P<T>` has implemented `DerefMut` since rust-lang#54277. While this was lamented at the time [1], rustc now relies on it extensively via the many implementors of MutVisitor [2]. Updates the docs to reflect that `P<T>` is fundamentally mutable, and a few other cleanups to make them nicer to browse. [1]: rust-lang#54277 (comment) [2]: https://doc.rust-lang.org/1.77.1/nightly-rustc/rustc_ast/mut_visit/trait.MutVisitor.html#implementors r? `@Nilstrieb`
2 parents ceab612 + 5075931 commit 8ef81cc

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

compiler/rustc_ast/src/ptr.rs

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
//! The AST pointer.
22
//!
3-
//! Provides `P<T>`, a frozen owned smart pointer.
3+
//! Provides [`P<T>`][struct@P], an owned smart pointer.
44
//!
55
//! # Motivations and benefits
66
//!
77
//! * **Identity**: sharing AST nodes is problematic for the various analysis
88
//! passes (e.g., one may be able to bypass the borrow checker with a shared
99
//! `ExprKind::AddrOf` node taking a mutable borrow).
1010
//!
11-
//! * **Immutability**: `P<T>` disallows mutating its inner `T`, unlike `Box<T>`
12-
//! (unless it contains an `Unsafe` interior, but that may be denied later).
13-
//! This mainly prevents mistakes, but also enforces a kind of "purity".
14-
//!
1511
//! * **Efficiency**: folding can reuse allocation space for `P<T>` and `Vec<T>`,
1612
//! the latter even when the input and output types differ (as it would be the
1713
//! case with arenas or a GADT AST using type parameters to toggle features).
1814
//!
19-
//! * **Maintainability**: `P<T>` provides a fixed interface - `Deref`,
20-
//! `and_then` and `map` - which can remain fully functional even if the
21-
//! implementation changes (using a special thread-local heap, for example).
22-
//! Moreover, a switch to, e.g., `P<'a, T>` would be easy and mostly automated.
15+
//! * **Maintainability**: `P<T>` provides an interface, which can remain fully
16+
//! functional even if the implementation changes (using a special thread-local
17+
//! heap, for example). Moreover, a switch to, e.g., `P<'a, T>` would be easy
18+
//! and mostly automated.
2319
2420
use std::fmt::{self, Debug, Display};
2521
use std::ops::{Deref, DerefMut};
@@ -29,6 +25,8 @@ use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
2925

3026
use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
3127
/// An owned smart pointer.
28+
///
29+
/// See the [module level documentation][crate::ptr] for details.
3230
pub struct P<T: ?Sized> {
3331
ptr: Box<T>,
3432
}

0 commit comments

Comments
 (0)