@@ -58,7 +58,7 @@ impl<'a> Parser<'a> {
5858 }
5959 } else {
6060 let old_directory = self . directory . clone ( ) ;
61- self . push_directory ( id, & attrs) ;
61+ push_directory ( id, & attrs, & mut self . directory . ownership , & mut self . directory . path ) ;
6262
6363 self . expect ( & token:: OpenDelim ( token:: Brace ) ) ?;
6464 let module = self . parse_mod ( & token:: CloseDelim ( token:: Brace ) ) ?;
@@ -142,26 +142,31 @@ impl<'a> Parser<'a> {
142142 }
143143 Ok ( ( ) )
144144 }
145+ }
145146
146- fn push_directory ( & mut self , id : Ident , attrs : & [ Attribute ] ) {
147- if let Some ( path) = attr:: first_attr_value_str_by_name ( attrs, sym:: path) {
148- self . directory . path . push ( & * path. as_str ( ) ) ;
149- self . directory . ownership = DirectoryOwnership :: Owned { relative : None } ;
150- } else {
151- // We have to push on the current module name in the case of relative
152- // paths in order to ensure that any additional module paths from inline
153- // `mod x { ... }` come after the relative extension.
154- //
155- // For example, a `mod z { ... }` inside `x/y.rs` should set the current
156- // directory path to `/x/y/z`, not `/x/z` with a relative offset of `y`.
157- if let DirectoryOwnership :: Owned { relative } = & mut self . directory . ownership {
158- if let Some ( ident) = relative. take ( ) {
159- // remove the relative offset
160- self . directory . path . push ( & * ident. as_str ( ) ) ;
161- }
147+ fn push_directory (
148+ id : Ident ,
149+ attrs : & [ Attribute ] ,
150+ dir_ownership : & mut DirectoryOwnership ,
151+ dir_path : & mut PathBuf ,
152+ ) {
153+ if let Some ( path) = attr:: first_attr_value_str_by_name ( attrs, sym:: path) {
154+ dir_path. push ( & * path. as_str ( ) ) ;
155+ * dir_ownership = DirectoryOwnership :: Owned { relative : None } ;
156+ } else {
157+ // We have to push on the current module name in the case of relative
158+ // paths in order to ensure that any additional module paths from inline
159+ // `mod x { ... }` come after the relative extension.
160+ //
161+ // For example, a `mod z { ... }` inside `x/y.rs` should set the current
162+ // directory path to `/x/y/z`, not `/x/z` with a relative offset of `y`.
163+ if let DirectoryOwnership :: Owned { relative } = dir_ownership {
164+ if let Some ( ident) = relative. take ( ) {
165+ // Remove the relative offset.
166+ dir_path. push ( & * ident. as_str ( ) ) ;
162167 }
163- self . directory . path . push ( & * id. as_str ( ) ) ;
164168 }
169+ dir_path. push ( & * id. as_str ( ) ) ;
165170 }
166171}
167172
0 commit comments