@@ -142,41 +142,41 @@ impl<'a> Parser<'a> {
142
142
}
143
143
Err ( err)
144
144
}
145
- DirectoryOwnership :: UnownedViaMod => {
146
- let mut err =
147
- self . struct_span_err ( id_sp, "cannot declare a new module at this location" ) ;
148
- if !id_sp. is_dummy ( ) {
149
- let src_path = self . sess . source_map ( ) . span_to_filename ( id_sp) ;
150
- if let FileName :: Real ( src_path) = src_path {
151
- if let Some ( stem) = src_path. file_stem ( ) {
152
- let mut dest_path = src_path. clone ( ) ;
153
- dest_path. set_file_name ( stem) ;
154
- dest_path. push ( "mod.rs" ) ;
155
- err. span_note (
156
- id_sp,
157
- & format ! (
158
- "maybe move this module `{}` to its own \
159
- directory via `{}`",
160
- src_path. display( ) ,
161
- dest_path. display( )
162
- ) ,
163
- ) ;
164
- }
165
- }
166
- }
167
- if paths. path_exists {
145
+ DirectoryOwnership :: UnownedViaMod => self . error_cannot_declare_mod_here ( id_sp, paths) ,
146
+ }
147
+ }
148
+
149
+ fn error_cannot_declare_mod_here < T > ( & self , id_sp : Span , paths : ModulePath ) -> PResult < ' a , T > {
150
+ let mut err = self . struct_span_err ( id_sp, "cannot declare a new module at this location" ) ;
151
+ if !id_sp. is_dummy ( ) {
152
+ if let FileName :: Real ( src_path) = self . sess . source_map ( ) . span_to_filename ( id_sp) {
153
+ if let Some ( stem) = src_path. file_stem ( ) {
154
+ let mut dest_path = src_path. clone ( ) ;
155
+ dest_path. set_file_name ( stem) ;
156
+ dest_path. push ( "mod.rs" ) ;
168
157
err. span_note (
169
158
id_sp,
170
159
& format ! (
171
- "... or maybe `use` the module `{}` instead \
172
- of possibly redeclaring it",
173
- paths. name
160
+ "maybe move this module `{}` to its own \
161
+ directory via `{}`",
162
+ src_path. display( ) ,
163
+ dest_path. display( )
174
164
) ,
175
165
) ;
176
166
}
177
- Err ( err)
178
167
}
179
168
}
169
+ if paths. path_exists {
170
+ err. span_note (
171
+ id_sp,
172
+ & format ! (
173
+ "... or maybe `use` the module `{}` instead \
174
+ of possibly redeclaring it",
175
+ paths. name
176
+ ) ,
177
+ ) ;
178
+ }
179
+ Err ( err)
180
180
}
181
181
182
182
/// Derive a submodule path from the first found `#[path = "path_string"]`.
0 commit comments