@@ -16,7 +16,6 @@ use crate::{
16
16
use hir_expand:: name:: Name ;
17
17
use intern:: Interned ;
18
18
use span:: Edition ;
19
- use stdx:: thin_vec:: thin_vec_with_header_struct;
20
19
use syntax:: ast;
21
20
22
21
pub use hir_expand:: mod_path:: { ModPath , PathKind , path} ;
@@ -58,7 +57,7 @@ pub enum Path {
58
57
/// this is not a problem since many more paths have generics than a type anchor).
59
58
BarePath ( Interned < ModPath > ) ,
60
59
/// `Path::Normal` will always have either generics or type anchor.
61
- Normal ( NormalPath ) ,
60
+ Normal ( Box < NormalPath > ) ,
62
61
/// A link to a lang item. It is used in desugaring of things like `it?`. We can show these
63
62
/// links via a normal path since they might be private and not accessible in the usage place.
64
63
LangItem ( LangItemTarget , Option < Name > ) ,
@@ -71,12 +70,11 @@ const _: () = {
71
70
assert ! ( size_of:: <Option <Path >>( ) == 16 ) ;
72
71
} ;
73
72
74
- thin_vec_with_header_struct ! {
75
- pub new( pub ( crate ) ) struct NormalPath , NormalPathHeader {
76
- pub generic_args: [ Option <GenericArgs >] ,
77
- pub type_anchor: Option <TypeRefId >,
78
- pub mod_path: Interned <ModPath >; ref,
79
- }
73
+ #[ derive( Debug , Clone , PartialEq , Eq , Hash ) ]
74
+ pub struct NormalPath {
75
+ pub generic_args : Box < [ Option < GenericArgs > ] > ,
76
+ pub type_anchor : Option < TypeRefId > ,
77
+ pub mod_path : Interned < ModPath > ,
80
78
}
81
79
82
80
#[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
@@ -143,7 +141,11 @@ impl Path {
143
141
144
142
/// Converts a known mod path to `Path`.
145
143
pub fn from_known_path ( path : ModPath , generic_args : Vec < Option < GenericArgs > > ) -> Path {
146
- Path :: Normal ( NormalPath :: new ( None , Interned :: new ( path) , generic_args) )
144
+ Path :: Normal ( Box :: new ( NormalPath {
145
+ generic_args : generic_args. into_boxed_slice ( ) ,
146
+ type_anchor : None ,
147
+ mod_path : Interned :: new ( path) ,
148
+ } ) )
147
149
}
148
150
149
151
/// Converts a known mod path to `Path`.
@@ -155,23 +157,23 @@ impl Path {
155
157
pub fn kind ( & self ) -> & PathKind {
156
158
match self {
157
159
Path :: BarePath ( mod_path) => & mod_path. kind ,
158
- Path :: Normal ( path) => & path. mod_path ( ) . kind ,
160
+ Path :: Normal ( path) => & path. mod_path . kind ,
159
161
Path :: LangItem ( ..) => & PathKind :: Abs ,
160
162
}
161
163
}
162
164
163
165
#[ inline]
164
166
pub fn type_anchor ( & self ) -> Option < TypeRefId > {
165
167
match self {
166
- Path :: Normal ( path) => path. type_anchor ( ) ,
168
+ Path :: Normal ( path) => path. type_anchor ,
167
169
Path :: LangItem ( ..) | Path :: BarePath ( _) => None ,
168
170
}
169
171
}
170
172
171
173
#[ inline]
172
174
pub fn generic_args ( & self ) -> Option < & [ Option < GenericArgs > ] > {
173
175
match self {
174
- Path :: Normal ( path) => Some ( path. generic_args ( ) ) ,
176
+ Path :: Normal ( path) => Some ( & path. generic_args ) ,
175
177
Path :: LangItem ( ..) | Path :: BarePath ( _) => None ,
176
178
}
177
179
}
@@ -182,8 +184,8 @@ impl Path {
182
184
PathSegments { segments : mod_path. segments ( ) , generic_args : None }
183
185
}
184
186
Path :: Normal ( path) => PathSegments {
185
- segments : path. mod_path ( ) . segments ( ) ,
186
- generic_args : Some ( path. generic_args ( ) ) ,
187
+ segments : path. mod_path . segments ( ) ,
188
+ generic_args : Some ( & path. generic_args ) ,
187
189
} ,
188
190
Path :: LangItem ( _, seg) => PathSegments { segments : seg. as_slice ( ) , generic_args : None } ,
189
191
}
@@ -192,7 +194,7 @@ impl Path {
192
194
pub fn mod_path ( & self ) -> Option < & ModPath > {
193
195
match self {
194
196
Path :: BarePath ( mod_path) => Some ( mod_path) ,
195
- Path :: Normal ( path) => Some ( path. mod_path ( ) ) ,
197
+ Path :: Normal ( path) => Some ( & path. mod_path ) ,
196
198
Path :: LangItem ( ..) => None ,
197
199
}
198
200
}
@@ -209,12 +211,12 @@ impl Path {
209
211
) ) ) )
210
212
}
211
213
Path :: Normal ( path) => {
212
- let mod_path = path. mod_path ( ) ;
214
+ let mod_path = & path. mod_path ;
213
215
if mod_path. is_ident ( ) {
214
216
return None ;
215
217
}
216
- let type_anchor = path. type_anchor ( ) ;
217
- let generic_args = path. generic_args ( ) ;
218
+ let type_anchor = path. type_anchor ;
219
+ let generic_args = & path. generic_args ;
218
220
let qualifier_mod_path = Interned :: new ( ModPath :: from_segments (
219
221
mod_path. kind ,
220
222
mod_path. segments ( ) [ ..mod_path. segments ( ) . len ( ) - 1 ] . iter ( ) . cloned ( ) ,
@@ -223,11 +225,11 @@ impl Path {
223
225
if type_anchor. is_none ( ) && qualifier_generic_args. iter ( ) . all ( |it| it. is_none ( ) ) {
224
226
Some ( Path :: BarePath ( qualifier_mod_path) )
225
227
} else {
226
- Some ( Path :: Normal ( NormalPath :: new (
228
+ Some ( Path :: Normal ( Box :: new ( NormalPath {
227
229
type_anchor,
228
- qualifier_mod_path,
229
- qualifier_generic_args. iter ( ) . cloned ( ) ,
230
- ) ) )
230
+ mod_path : qualifier_mod_path,
231
+ generic_args : qualifier_generic_args. iter ( ) . cloned ( ) . collect ( ) ,
232
+ } ) ) )
231
233
}
232
234
}
233
235
Path :: LangItem ( ..) => None ,
@@ -238,9 +240,9 @@ impl Path {
238
240
match self {
239
241
Path :: BarePath ( mod_path) => mod_path. is_Self ( ) ,
240
242
Path :: Normal ( path) => {
241
- path. type_anchor ( ) . is_none ( )
242
- && path. mod_path ( ) . is_Self ( )
243
- && path. generic_args ( ) . iter ( ) . all ( |args| args. is_none ( ) )
243
+ path. type_anchor . is_none ( )
244
+ && path. mod_path . is_Self ( )
245
+ && path. generic_args . iter ( ) . all ( |args| args. is_none ( ) )
244
246
}
245
247
Path :: LangItem ( ..) => false ,
246
248
}
0 commit comments