@@ -11,7 +11,7 @@ use rustc_span::Span;
11
11
use std:: path:: { self , Path , PathBuf } ;
12
12
13
13
#[ derive( Copy , Clone ) ]
14
- pub enum DirectoryOwnership {
14
+ pub enum DirOwnership {
15
15
Owned {
16
16
// None if `mod.rs`, `Some("foo")` if we're in `foo.rs`.
17
17
relative : Option < Ident > ,
@@ -29,40 +29,40 @@ pub struct ModulePath<'a> {
29
29
30
30
// Public for rustfmt usage.
31
31
pub struct ModulePathSuccess {
32
- pub path : PathBuf ,
33
- pub ownership : DirectoryOwnership ,
32
+ pub file_path : PathBuf ,
33
+ pub dir_ownership : DirOwnership ,
34
34
}
35
35
36
36
crate struct ParsedExternalMod {
37
37
pub items : Vec < P < Item > > ,
38
38
pub inner_span : Span ,
39
39
pub file_path : PathBuf ,
40
40
pub dir_path : PathBuf ,
41
- pub dir_ownership : DirectoryOwnership ,
41
+ pub dir_ownership : DirOwnership ,
42
42
}
43
43
44
44
crate fn parse_external_mod (
45
45
sess : & Session ,
46
- id : Ident ,
46
+ ident : Ident ,
47
47
span : Span , // The span to blame on errors.
48
48
module : & ModuleData ,
49
- mut dir_ownership : DirectoryOwnership ,
49
+ mut dir_ownership : DirOwnership ,
50
50
attrs : & mut Vec < Attribute > ,
51
51
) -> ParsedExternalMod {
52
52
// We bail on the first error, but that error does not cause a fatal error... (1)
53
53
let result: PResult < ' _ , _ > = try {
54
54
// 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 ;
57
57
58
58
// 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 ) ?;
60
60
61
61
// 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) ) ;
63
63
let ( mut inner_attrs, items, inner_span) = parser. parse_mod ( & token:: Eof ) ?;
64
64
attrs. append ( & mut inner_attrs) ;
65
- ( items, inner_span, mp. path )
65
+ ( items, inner_span, mp. file_path )
66
66
} ;
67
67
// (1) ...instead, we return a dummy module.
68
68
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(
76
76
fn error_on_circular_module < ' a > (
77
77
sess : & ' a ParseSess ,
78
78
span : Span ,
79
- path : & Path ,
79
+ file_path : & Path ,
80
80
file_path_stack : & [ PathBuf ] ,
81
81
) -> 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 ) {
83
83
let mut err = String :: from ( "circular modules: " ) ;
84
84
for p in & file_path_stack[ i..] {
85
85
err. push_str ( & p. to_string_lossy ( ) ) ;
86
86
err. push_str ( " -> " ) ;
87
87
}
88
- err. push_str ( & path . to_string_lossy ( ) ) ;
88
+ err. push_str ( & file_path . to_string_lossy ( ) ) ;
89
89
return Err ( sess. span_diagnostic . struct_span_err ( span, & err[ ..] ) ) ;
90
90
}
91
91
Ok ( ( ) )
92
92
}
93
93
94
- crate fn push_directory (
94
+ crate fn mod_dir_path (
95
95
sess : & Session ,
96
- id : Ident ,
96
+ ident : Ident ,
97
97
attrs : & [ Attribute ] ,
98
98
module : & ModuleData ,
99
- mut dir_ownership : DirectoryOwnership ,
100
- ) -> ( PathBuf , DirectoryOwnership ) {
99
+ mut dir_ownership : DirOwnership ,
100
+ ) -> ( PathBuf , DirOwnership ) {
101
101
let mut dir_path = module. dir_path . clone ( ) ;
102
102
if let Some ( file_path) = sess. first_attr_value_str_by_name ( attrs, sym:: path) {
103
103
dir_path. push ( & * file_path. as_str ( ) ) ;
104
- dir_ownership = DirectoryOwnership :: Owned { relative : None } ;
104
+ dir_ownership = DirOwnership :: Owned { relative : None } ;
105
105
} else {
106
106
// We have to push on the current module name in the case of relative
107
107
// paths in order to ensure that any additional module paths from inline
108
108
// `mod x { ... }` come after the relative extension.
109
109
//
110
110
// For example, a `mod z { ... }` inside `x/y.rs` should set the current
111
111
// 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 {
113
113
if let Some ( ident) = relative. take ( ) {
114
114
// Remove the relative offset.
115
115
dir_path. push ( & * ident. as_str ( ) ) ;
116
116
}
117
117
}
118
- dir_path. push ( & * id . as_str ( ) ) ;
118
+ dir_path. push ( & * ident . as_str ( ) ) ;
119
119
}
120
120
121
121
( dir_path, dir_ownership)
122
122
}
123
123
124
- fn submod_path < ' a > (
124
+ fn mod_file_path < ' a > (
125
125
sess : & ' a Session ,
126
- id : Ident ,
126
+ ident : Ident ,
127
127
span : Span ,
128
128
attrs : & [ Attribute ] ,
129
- ownership : DirectoryOwnership ,
130
129
dir_path : & Path ,
130
+ dir_ownership : DirOwnership ,
131
131
) -> 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) {
133
133
// All `#[path]` files are treated as though they are a `mod.rs` file.
134
134
// This means that `mod foo;` declarations inside `#[path]`-included
135
135
// files are siblings,
136
136
//
137
137
// Note that this will produce weirdness when a file named `foo.rs` is
138
138
// `#[path]` included and contains a `mod foo;` declaration.
139
139
// 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 } ) ;
142
142
}
143
143
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 ,
147
147
} ;
148
148
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 => {
153
153
let _ = result. map_err ( |mut err| err. cancel ( ) ) ;
154
154
error_decl_mod_in_block ( & sess. parse_sess , span, path_exists, & name)
155
155
}
@@ -173,7 +173,7 @@ fn error_decl_mod_in_block<'a, T>(
173
173
174
174
/// Derive a submodule path from the first found `#[path = "path_string"]`.
175
175
/// 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 (
177
177
sess : & Session ,
178
178
attrs : & [ Attribute ] ,
179
179
dir_path : & Path ,
@@ -196,15 +196,15 @@ pub(super) fn submod_path_from_attr(
196
196
// Public for rustfmt usage.
197
197
pub fn default_submod_path < ' a > (
198
198
sess : & ' a ParseSess ,
199
- id : Ident ,
199
+ ident : Ident ,
200
200
span : Span ,
201
201
relative : Option < Ident > ,
202
202
dir_path : & Path ,
203
203
) -> ModulePath < ' a > {
204
204
// If we're in a foo.rs file instead of a mod.rs file,
205
205
// 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`.
208
208
let relative_prefix_string;
209
209
let relative_prefix = if let Some ( ident) = relative {
210
210
relative_prefix_string = format ! ( "{}{}" , ident. name, path:: MAIN_SEPARATOR ) ;
@@ -213,7 +213,7 @@ pub fn default_submod_path<'a>(
213
213
""
214
214
} ;
215
215
216
- let mod_name = id . name . to_string ( ) ;
216
+ let mod_name = ident . name . to_string ( ) ;
217
217
let default_path_str = format ! ( "{}{}.rs" , relative_prefix, mod_name) ;
218
218
let secondary_path_str =
219
219
format ! ( "{}{}{}mod.rs" , relative_prefix, mod_name, path:: MAIN_SEPARATOR ) ;
@@ -224,12 +224,12 @@ pub fn default_submod_path<'a>(
224
224
225
225
let result = match ( default_exists, secondary_exists) {
226
226
( 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 ) } ,
229
229
} ) ,
230
230
( 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 } ,
233
233
} ) ,
234
234
( false , false ) => {
235
235
let mut err = struct_span_err ! (
0 commit comments