@@ -11,7 +11,7 @@ use rustc_span::Span;
1111use std:: path:: { self , Path , PathBuf } ;
1212
1313#[ derive( Copy , Clone ) ]
14- pub enum DirectoryOwnership {
14+ pub enum DirOwnership {
1515 Owned {
1616 // None if `mod.rs`, `Some("foo")` if we're in `foo.rs`.
1717 relative : Option < Ident > ,
@@ -29,40 +29,40 @@ pub struct ModulePath<'a> {
2929
3030// Public for rustfmt usage.
3131pub struct ModulePathSuccess {
32- pub path : PathBuf ,
33- pub ownership : DirectoryOwnership ,
32+ pub file_path : PathBuf ,
33+ pub dir_ownership : DirOwnership ,
3434}
3535
3636crate struct ParsedExternalMod {
3737 pub items : Vec < P < Item > > ,
3838 pub inner_span : Span ,
3939 pub file_path : PathBuf ,
4040 pub dir_path : PathBuf ,
41- pub dir_ownership : DirectoryOwnership ,
41+ pub dir_ownership : DirOwnership ,
4242}
4343
4444crate fn parse_external_mod (
4545 sess : & Session ,
46- id : Ident ,
46+ ident : Ident ,
4747 span : Span , // The span to blame on errors.
4848 module : & ModuleData ,
49- mut dir_ownership : DirectoryOwnership ,
49+ mut dir_ownership : DirOwnership ,
5050 attrs : & mut Vec < Attribute > ,
5151) -> ParsedExternalMod {
5252 // We bail on the first error, but that error does not cause a fatal error... (1)
5353 let result: PResult < ' _ , _ > = try {
5454 // Extract the file path and the new ownership.
55- let mp = submod_path ( sess, id , span, & attrs, dir_ownership , & module. dir_path ) ?;
56- dir_ownership = mp. ownership ;
55+ let mp = mod_file_path ( sess, ident , span, & attrs, & module. dir_path , dir_ownership ) ?;
56+ dir_ownership = mp. dir_ownership ;
5757
5858 // Ensure file paths are acyclic.
59- error_on_circular_module ( & sess. parse_sess , span, & mp. path , & module. file_path_stack ) ?;
59+ error_on_circular_module ( & sess. parse_sess , span, & mp. file_path , & module. file_path_stack ) ?;
6060
6161 // Actually parse the external file as a module.
62- let mut parser = new_parser_from_file ( & sess. parse_sess , & mp. path , Some ( span) ) ;
62+ let mut parser = new_parser_from_file ( & sess. parse_sess , & mp. file_path , Some ( span) ) ;
6363 let ( mut inner_attrs, items, inner_span) = parser. parse_mod ( & token:: Eof ) ?;
6464 attrs. append ( & mut inner_attrs) ;
65- ( items, inner_span, mp. path )
65+ ( items, inner_span, mp. file_path )
6666 } ;
6767 // (1) ...instead, we return a dummy module.
6868 let ( items, inner_span, file_path) = result. map_err ( |mut err| err. emit ( ) ) . unwrap_or_default ( ) ;
@@ -76,80 +76,80 @@ crate fn parse_external_mod(
7676fn error_on_circular_module < ' a > (
7777 sess : & ' a ParseSess ,
7878 span : Span ,
79- path : & Path ,
79+ file_path : & Path ,
8080 file_path_stack : & [ PathBuf ] ,
8181) -> PResult < ' a , ( ) > {
82- if let Some ( i) = file_path_stack. iter ( ) . position ( |p| * p == path ) {
82+ if let Some ( i) = file_path_stack. iter ( ) . position ( |p| * p == file_path ) {
8383 let mut err = String :: from ( "circular modules: " ) ;
8484 for p in & file_path_stack[ i..] {
8585 err. push_str ( & p. to_string_lossy ( ) ) ;
8686 err. push_str ( " -> " ) ;
8787 }
88- err. push_str ( & path . to_string_lossy ( ) ) ;
88+ err. push_str ( & file_path . to_string_lossy ( ) ) ;
8989 return Err ( sess. span_diagnostic . struct_span_err ( span, & err[ ..] ) ) ;
9090 }
9191 Ok ( ( ) )
9292}
9393
94- crate fn push_directory (
94+ crate fn mod_dir_path (
9595 sess : & Session ,
96- id : Ident ,
96+ ident : Ident ,
9797 attrs : & [ Attribute ] ,
9898 module : & ModuleData ,
99- mut dir_ownership : DirectoryOwnership ,
100- ) -> ( PathBuf , DirectoryOwnership ) {
99+ mut dir_ownership : DirOwnership ,
100+ ) -> ( PathBuf , DirOwnership ) {
101101 let mut dir_path = module. dir_path . clone ( ) ;
102102 if let Some ( file_path) = sess. first_attr_value_str_by_name ( attrs, sym:: path) {
103103 dir_path. push ( & * file_path. as_str ( ) ) ;
104- dir_ownership = DirectoryOwnership :: Owned { relative : None } ;
104+ dir_ownership = DirOwnership :: Owned { relative : None } ;
105105 } else {
106106 // We have to push on the current module name in the case of relative
107107 // paths in order to ensure that any additional module paths from inline
108108 // `mod x { ... }` come after the relative extension.
109109 //
110110 // For example, a `mod z { ... }` inside `x/y.rs` should set the current
111111 // directory path to `/x/y/z`, not `/x/z` with a relative offset of `y`.
112- if let DirectoryOwnership :: Owned { relative } = & mut dir_ownership {
112+ if let DirOwnership :: Owned { relative } = & mut dir_ownership {
113113 if let Some ( ident) = relative. take ( ) {
114114 // Remove the relative offset.
115115 dir_path. push ( & * ident. as_str ( ) ) ;
116116 }
117117 }
118- dir_path. push ( & * id . as_str ( ) ) ;
118+ dir_path. push ( & * ident . as_str ( ) ) ;
119119 }
120120
121121 ( dir_path, dir_ownership)
122122}
123123
124- fn submod_path < ' a > (
124+ fn mod_file_path < ' a > (
125125 sess : & ' a Session ,
126- id : Ident ,
126+ ident : Ident ,
127127 span : Span ,
128128 attrs : & [ Attribute ] ,
129- ownership : DirectoryOwnership ,
130129 dir_path : & Path ,
130+ dir_ownership : DirOwnership ,
131131) -> PResult < ' a , ModulePathSuccess > {
132- if let Some ( path ) = submod_path_from_attr ( sess, attrs, dir_path) {
132+ if let Some ( file_path ) = mod_file_path_from_attr ( sess, attrs, dir_path) {
133133 // All `#[path]` files are treated as though they are a `mod.rs` file.
134134 // This means that `mod foo;` declarations inside `#[path]`-included
135135 // files are siblings,
136136 //
137137 // Note that this will produce weirdness when a file named `foo.rs` is
138138 // `#[path]` included and contains a `mod foo;` declaration.
139139 // If you encounter this, it's your own darn fault :P
140- let ownership = DirectoryOwnership :: Owned { relative : None } ;
141- return Ok ( ModulePathSuccess { ownership , path } ) ;
140+ let dir_ownership = DirOwnership :: Owned { relative : None } ;
141+ return Ok ( ModulePathSuccess { file_path , dir_ownership } ) ;
142142 }
143143
144- let relative = match ownership {
145- DirectoryOwnership :: Owned { relative } => relative,
146- DirectoryOwnership :: UnownedViaBlock => None ,
144+ let relative = match dir_ownership {
145+ DirOwnership :: Owned { relative } => relative,
146+ DirOwnership :: UnownedViaBlock => None ,
147147 } ;
148148 let ModulePath { path_exists, name, result } =
149- default_submod_path ( & sess. parse_sess , id , span, relative, dir_path) ;
150- match ownership {
151- DirectoryOwnership :: Owned { .. } => Ok ( result?) ,
152- DirectoryOwnership :: UnownedViaBlock => {
149+ default_submod_path ( & sess. parse_sess , ident , span, relative, dir_path) ;
150+ match dir_ownership {
151+ DirOwnership :: Owned { .. } => Ok ( result?) ,
152+ DirOwnership :: UnownedViaBlock => {
153153 let _ = result. map_err ( |mut err| err. cancel ( ) ) ;
154154 error_decl_mod_in_block ( & sess. parse_sess , span, path_exists, & name)
155155 }
@@ -173,7 +173,7 @@ fn error_decl_mod_in_block<'a, T>(
173173
174174/// Derive a submodule path from the first found `#[path = "path_string"]`.
175175/// The provided `dir_path` is joined with the `path_string`.
176- pub ( super ) fn submod_path_from_attr (
176+ fn mod_file_path_from_attr (
177177 sess : & Session ,
178178 attrs : & [ Attribute ] ,
179179 dir_path : & Path ,
@@ -196,15 +196,15 @@ pub(super) fn submod_path_from_attr(
196196// Public for rustfmt usage.
197197pub fn default_submod_path < ' a > (
198198 sess : & ' a ParseSess ,
199- id : Ident ,
199+ ident : Ident ,
200200 span : Span ,
201201 relative : Option < Ident > ,
202202 dir_path : & Path ,
203203) -> ModulePath < ' a > {
204204 // If we're in a foo.rs file instead of a mod.rs file,
205205 // we need to look for submodules in
206- // `./foo/<id >.rs` and `./foo/<id >/mod.rs` rather than
207- // `./<id >.rs` and `./<id >/mod.rs`.
206+ // `./foo/<ident >.rs` and `./foo/<ident >/mod.rs` rather than
207+ // `./<ident >.rs` and `./<ident >/mod.rs`.
208208 let relative_prefix_string;
209209 let relative_prefix = if let Some ( ident) = relative {
210210 relative_prefix_string = format ! ( "{}{}" , ident. name, path:: MAIN_SEPARATOR ) ;
@@ -213,7 +213,7 @@ pub fn default_submod_path<'a>(
213213 ""
214214 } ;
215215
216- let mod_name = id . name . to_string ( ) ;
216+ let mod_name = ident . name . to_string ( ) ;
217217 let default_path_str = format ! ( "{}{}.rs" , relative_prefix, mod_name) ;
218218 let secondary_path_str =
219219 format ! ( "{}{}{}mod.rs" , relative_prefix, mod_name, path:: MAIN_SEPARATOR ) ;
@@ -224,12 +224,12 @@ pub fn default_submod_path<'a>(
224224
225225 let result = match ( default_exists, secondary_exists) {
226226 ( true , false ) => Ok ( ModulePathSuccess {
227- path : default_path,
228- ownership : DirectoryOwnership :: Owned { relative : Some ( id ) } ,
227+ file_path : default_path,
228+ dir_ownership : DirOwnership :: Owned { relative : Some ( ident ) } ,
229229 } ) ,
230230 ( false , true ) => Ok ( ModulePathSuccess {
231- path : secondary_path,
232- ownership : DirectoryOwnership :: Owned { relative : None } ,
231+ file_path : secondary_path,
232+ dir_ownership : DirOwnership :: Owned { relative : None } ,
233233 } ) ,
234234 ( false , false ) => {
235235 let mut err = struct_span_err ! (
0 commit comments