@@ -58,7 +58,7 @@ impl<'a> Parser<'a> {
58
58
}
59
59
} else {
60
60
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 ) ;
62
62
63
63
self . expect ( & token:: OpenDelim ( token:: Brace ) ) ?;
64
64
let module = self . parse_mod ( & token:: CloseDelim ( token:: Brace ) ) ?;
@@ -142,26 +142,31 @@ impl<'a> Parser<'a> {
142
142
}
143
143
Ok ( ( ) )
144
144
}
145
+ }
145
146
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 ( ) ) ;
162
167
}
163
- self . directory . path . push ( & * id. as_str ( ) ) ;
164
168
}
169
+ dir_path. push ( & * id. as_str ( ) ) ;
165
170
}
166
171
}
167
172
0 commit comments