1
1
//! The AST pointer.
2
2
//!
3
- //! Provides `P<T>`, a frozen owned smart pointer.
3
+ //! Provides [ `P<T>`][struct@P], an owned smart pointer.
4
4
//!
5
5
//! # Motivations and benefits
6
6
//!
7
7
//! * **Identity**: sharing AST nodes is problematic for the various analysis
8
8
//! passes (e.g., one may be able to bypass the borrow checker with a shared
9
9
//! `ExprKind::AddrOf` node taking a mutable borrow).
10
10
//!
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
- //!
15
11
//! * **Efficiency**: folding can reuse allocation space for `P<T>` and `Vec<T>`,
16
12
//! the latter even when the input and output types differ (as it would be the
17
13
//! case with arenas or a GADT AST using type parameters to toggle features).
18
14
//!
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.
23
19
24
20
use std:: fmt:: { self , Debug , Display } ;
25
21
use std:: ops:: { Deref , DerefMut } ;
@@ -29,6 +25,8 @@ use rustc_serialize::{Decodable, Decoder, Encodable, Encoder};
29
25
30
26
use rustc_data_structures:: stable_hasher:: { HashStable , StableHasher } ;
31
27
/// An owned smart pointer.
28
+ ///
29
+ /// See the [module level documentation][crate::ptr] for details.
32
30
pub struct P < T : ?Sized > {
33
31
ptr : Box < T > ,
34
32
}
0 commit comments