@@ -98,25 +98,26 @@ crate fn mod_dir_path(
98
98
module : & ModuleData ,
99
99
mut dir_ownership : DirOwnership ,
100
100
) -> ( PathBuf , DirOwnership ) {
101
+ if let Some ( file_path) = mod_file_path_from_attr ( sess, attrs, & module. dir_path ) {
102
+ // For inline modules file path from `#[path]` is actually the directory path
103
+ // for historical reasons, so we don't pop the last segment here.
104
+ return ( file_path, DirOwnership :: Owned { relative : None } ) ;
105
+ }
106
+
107
+ // We have to push on the current module name in the case of relative
108
+ // paths in order to ensure that any additional module paths from inline
109
+ // `mod x { ... }` come after the relative extension.
110
+ //
111
+ // For example, a `mod z { ... }` inside `x/y.rs` should set the current
112
+ // directory path to `/x/y/z`, not `/x/z` with a relative offset of `y`.
101
113
let mut dir_path = module. dir_path . clone ( ) ;
102
- if let Some ( file_path) = sess. first_attr_value_str_by_name ( attrs, sym:: path) {
103
- dir_path. push ( & * file_path. as_str ( ) ) ;
104
- dir_ownership = DirOwnership :: Owned { relative : None } ;
105
- } else {
106
- // We have to push on the current module name in the case of relative
107
- // paths in order to ensure that any additional module paths from inline
108
- // `mod x { ... }` come after the relative extension.
109
- //
110
- // For example, a `mod z { ... }` inside `x/y.rs` should set the current
111
- // directory path to `/x/y/z`, not `/x/z` with a relative offset of `y`.
112
- if let DirOwnership :: Owned { relative } = & mut dir_ownership {
113
- if let Some ( ident) = relative. take ( ) {
114
- // Remove the relative offset.
115
- dir_path. push ( & * ident. as_str ( ) ) ;
116
- }
114
+ if let DirOwnership :: Owned { relative } = & mut dir_ownership {
115
+ if let Some ( ident) = relative. take ( ) {
116
+ // Remove the relative offset.
117
+ dir_path. push ( & * ident. as_str ( ) ) ;
117
118
}
118
- dir_path. push ( & * ident. as_str ( ) ) ;
119
119
}
120
+ dir_path. push ( & * ident. as_str ( ) ) ;
120
121
121
122
( dir_path, dir_ownership)
122
123
}
@@ -179,8 +180,7 @@ fn mod_file_path_from_attr(
179
180
dir_path : & Path ,
180
181
) -> Option < PathBuf > {
181
182
// Extract path string from first `#[path = "path_string"]` attribute.
182
- let path_string = sess. first_attr_value_str_by_name ( attrs, sym:: path) ?;
183
- let path_string = path_string. as_str ( ) ;
183
+ let path_string = sess. first_attr_value_str_by_name ( attrs, sym:: path) ?. as_str ( ) ;
184
184
185
185
// On windows, the base path might have the form
186
186
// `\\?\foo\bar` in which case it does not tolerate
0 commit comments