1
1
//! A mini version of ast::Ty, which is easier to use, and features an explicit `Self` type to use
2
2
//! when specifying impls to be derived.
3
3
4
- pub use PtrTy :: * ;
5
4
pub use Ty :: * ;
6
5
7
6
use rustc_ast:: ptr:: P ;
@@ -11,16 +10,6 @@ use rustc_span::source_map::{respan, DUMMY_SP};
11
10
use rustc_span:: symbol:: { kw, Ident , Symbol } ;
12
11
use rustc_span:: Span ;
13
12
14
- /// The types of pointers
15
- #[ derive( Clone ) ]
16
- pub enum PtrTy {
17
- /// &'lifetime mut
18
- Borrowed ( Option < Ident > , ast:: Mutability ) ,
19
- /// *mut
20
- #[ allow( dead_code) ]
21
- Raw ( ast:: Mutability ) ,
22
- }
23
-
24
13
/// A path, e.g., `::std::option::Option::<i32>` (global). Has support
25
14
/// for type parameters and a lifetime.
26
15
#[ derive( Clone ) ]
@@ -92,28 +81,17 @@ impl Path {
92
81
#[ derive( Clone ) ]
93
82
pub enum Ty {
94
83
Self_ ,
95
- /// &/Box/ Ty
96
- Ptr ( Box < Ty > , PtrTy ) ,
84
+ /// A reference.
85
+ Ref ( Box < Ty > , ast :: Mutability ) ,
97
86
/// `mod::mod::Type<[lifetime], [Params...]>`, including a plain type
98
87
/// parameter, and things like `i32`
99
88
Literal ( Path ) ,
100
89
/// includes unit
101
90
Tuple ( Vec < Ty > ) ,
102
91
}
103
92
104
- pub fn borrowed_ptrty ( ) -> PtrTy {
105
- Borrowed ( None , ast:: Mutability :: Not )
106
- }
107
- pub fn borrowed ( ty : Box < Ty > ) -> Ty {
108
- Ptr ( ty, borrowed_ptrty ( ) )
109
- }
110
-
111
- pub fn borrowed_explicit_self ( ) -> Option < Option < PtrTy > > {
112
- Some ( Some ( borrowed_ptrty ( ) ) )
113
- }
114
-
115
- pub fn borrowed_self ( ) -> Ty {
116
- borrowed ( Box :: new ( Self_ ) )
93
+ pub fn self_ref ( ) -> Ty {
94
+ Ref ( Box :: new ( Self_ ) , ast:: Mutability :: Not )
117
95
}
118
96
119
97
pub fn nil_ty ( ) -> Ty {
@@ -136,20 +114,14 @@ impl Ty {
136
114
self_ty : Ident ,
137
115
self_generics : & Generics ,
138
116
) -> P < ast:: Ty > {
139
- match * self {
140
- Ptr ( ref ty, ref ptr ) => {
117
+ match self {
118
+ Ref ( ty, mutbl ) => {
141
119
let raw_ty = ty. to_ty ( cx, span, self_ty, self_generics) ;
142
- match * ptr {
143
- Borrowed ( ref lt, mutbl) => {
144
- let lt = mk_lifetime ( cx, span, lt) ;
145
- cx. ty_rptr ( span, raw_ty, lt, mutbl)
146
- }
147
- Raw ( mutbl) => cx. ty_ptr ( span, raw_ty, mutbl) ,
148
- }
120
+ cx. ty_rptr ( span, raw_ty, None , * mutbl)
149
121
}
150
- Literal ( ref p) => p. to_ty ( cx, span, self_ty, self_generics) ,
122
+ Literal ( p) => p. to_ty ( cx, span, self_ty, self_generics) ,
151
123
Self_ => cx. ty_path ( self . to_path ( cx, span, self_ty, self_generics) ) ,
152
- Tuple ( ref fields) => {
124
+ Tuple ( fields) => {
153
125
let ty = ast:: TyKind :: Tup (
154
126
fields. iter ( ) . map ( |f| f. to_ty ( cx, span, self_ty, self_generics) ) . collect ( ) ,
155
127
) ;
@@ -186,7 +158,7 @@ impl Ty {
186
158
cx. path_all ( span, false , vec ! [ self_ty] , params)
187
159
}
188
160
Literal ( ref p) => p. to_path ( cx, span, self_ty, generics) ,
189
- Ptr ( ..) => cx. span_bug ( span, "pointer in a path in generic `derive`" ) ,
161
+ Ref ( ..) => cx. span_bug ( span, "ref in a path in generic `derive`" ) ,
190
162
Tuple ( ..) => cx. span_bug ( span, "tuple in a path in generic `derive`" ) ,
191
163
}
192
164
}
@@ -245,28 +217,10 @@ impl Bounds {
245
217
}
246
218
}
247
219
248
- pub fn get_explicit_self (
249
- cx : & ExtCtxt < ' _ > ,
250
- span : Span ,
251
- self_ptr : & Option < PtrTy > ,
252
- ) -> ( P < Expr > , ast:: ExplicitSelf ) {
220
+ pub fn get_explicit_self ( cx : & ExtCtxt < ' _ > , span : Span ) -> ( P < Expr > , ast:: ExplicitSelf ) {
253
221
// this constructs a fresh `self` path
254
222
let self_path = cx. expr_self ( span) ;
255
- match * self_ptr {
256
- None => ( self_path, respan ( span, SelfKind :: Value ( ast:: Mutability :: Not ) ) ) ,
257
- Some ( ref ptr) => {
258
- let self_ty = respan (
259
- span,
260
- match * ptr {
261
- Borrowed ( ref lt, mutbl) => {
262
- let lt = lt. map ( |s| cx. lifetime ( span, s) ) ;
263
- SelfKind :: Region ( lt, mutbl)
264
- }
265
- Raw ( _) => cx. span_bug ( span, "attempted to use *self in deriving definition" ) ,
266
- } ,
267
- ) ;
268
- let self_expr = cx. expr_deref ( span, self_path) ;
269
- ( self_expr, self_ty)
270
- }
271
- }
223
+ let self_ty = respan ( span, SelfKind :: Region ( None , ast:: Mutability :: Not ) ) ;
224
+ let self_expr = cx. expr_deref ( span, self_path) ;
225
+ ( self_expr, self_ty)
272
226
}
0 commit comments