@@ -16,7 +16,6 @@ use crate::{
1616use hir_expand:: name:: Name ;
1717use intern:: Interned ;
1818use span:: Edition ;
19- use stdx:: thin_vec:: thin_vec_with_header_struct;
2019use syntax:: ast;
2120
2221pub use hir_expand:: mod_path:: { ModPath , PathKind , path} ;
@@ -58,7 +57,7 @@ pub enum Path {
5857 /// this is not a problem since many more paths have generics than a type anchor).
5958 BarePath ( Interned < ModPath > ) ,
6059 /// `Path::Normal` will always have either generics or type anchor.
61- Normal ( NormalPath ) ,
60+ Normal ( Box < NormalPath > ) ,
6261 /// A link to a lang item. It is used in desugaring of things like `it?`. We can show these
6362 /// links via a normal path since they might be private and not accessible in the usage place.
6463 LangItem ( LangItemTarget , Option < Name > ) ,
@@ -71,12 +70,11 @@ const _: () = {
7170 assert ! ( size_of:: <Option <Path >>( ) == 16 ) ;
7271} ;
7372
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 > ,
8078}
8179
8280#[ derive( Debug , Clone , Copy , PartialEq , Eq , Hash ) ]
@@ -143,7 +141,11 @@ impl Path {
143141
144142 /// Converts a known mod path to `Path`.
145143 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+ } ) )
147149 }
148150
149151 /// Converts a known mod path to `Path`.
@@ -155,23 +157,23 @@ impl Path {
155157 pub fn kind ( & self ) -> & PathKind {
156158 match self {
157159 Path :: BarePath ( mod_path) => & mod_path. kind ,
158- Path :: Normal ( path) => & path. mod_path ( ) . kind ,
160+ Path :: Normal ( path) => & path. mod_path . kind ,
159161 Path :: LangItem ( ..) => & PathKind :: Abs ,
160162 }
161163 }
162164
163165 #[ inline]
164166 pub fn type_anchor ( & self ) -> Option < TypeRefId > {
165167 match self {
166- Path :: Normal ( path) => path. type_anchor ( ) ,
168+ Path :: Normal ( path) => path. type_anchor ,
167169 Path :: LangItem ( ..) | Path :: BarePath ( _) => None ,
168170 }
169171 }
170172
171173 #[ inline]
172174 pub fn generic_args ( & self ) -> Option < & [ Option < GenericArgs > ] > {
173175 match self {
174- Path :: Normal ( path) => Some ( path. generic_args ( ) ) ,
176+ Path :: Normal ( path) => Some ( & path. generic_args ) ,
175177 Path :: LangItem ( ..) | Path :: BarePath ( _) => None ,
176178 }
177179 }
@@ -182,8 +184,8 @@ impl Path {
182184 PathSegments { segments : mod_path. segments ( ) , generic_args : None }
183185 }
184186 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 ) ,
187189 } ,
188190 Path :: LangItem ( _, seg) => PathSegments { segments : seg. as_slice ( ) , generic_args : None } ,
189191 }
@@ -192,7 +194,7 @@ impl Path {
192194 pub fn mod_path ( & self ) -> Option < & ModPath > {
193195 match self {
194196 Path :: BarePath ( mod_path) => Some ( mod_path) ,
195- Path :: Normal ( path) => Some ( path. mod_path ( ) ) ,
197+ Path :: Normal ( path) => Some ( & path. mod_path ) ,
196198 Path :: LangItem ( ..) => None ,
197199 }
198200 }
@@ -209,12 +211,12 @@ impl Path {
209211 ) ) ) )
210212 }
211213 Path :: Normal ( path) => {
212- let mod_path = path. mod_path ( ) ;
214+ let mod_path = & path. mod_path ;
213215 if mod_path. is_ident ( ) {
214216 return None ;
215217 }
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 ;
218220 let qualifier_mod_path = Interned :: new ( ModPath :: from_segments (
219221 mod_path. kind ,
220222 mod_path. segments ( ) [ ..mod_path. segments ( ) . len ( ) - 1 ] . iter ( ) . cloned ( ) ,
@@ -223,11 +225,11 @@ impl Path {
223225 if type_anchor. is_none ( ) && qualifier_generic_args. iter ( ) . all ( |it| it. is_none ( ) ) {
224226 Some ( Path :: BarePath ( qualifier_mod_path) )
225227 } else {
226- Some ( Path :: Normal ( NormalPath :: new (
228+ Some ( Path :: Normal ( Box :: new ( NormalPath {
227229 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+ } ) ) )
231233 }
232234 }
233235 Path :: LangItem ( ..) => None ,
@@ -238,9 +240,9 @@ impl Path {
238240 match self {
239241 Path :: BarePath ( mod_path) => mod_path. is_Self ( ) ,
240242 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 ( ) )
244246 }
245247 Path :: LangItem ( ..) => false ,
246248 }
0 commit comments