Skip to content

Commit dfcefa4

Browse files
committed
extract error_on_circular_module
1 parent 7108b7f commit dfcefa4

File tree

1 file changed

+20
-10
lines changed

1 file changed

+20
-10
lines changed

src/librustc_parse/parser/module.rs

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -254,16 +254,7 @@ impl<'a> Parser<'a> {
254254
id_sp: Span,
255255
) -> PResult<'a, (Mod, Vec<Attribute>)> {
256256
let mut included_mod_stack = self.sess.included_mod_stack.borrow_mut();
257-
if let Some(i) = included_mod_stack.iter().position(|p| *p == path) {
258-
let mut err = String::from("circular modules: ");
259-
let len = included_mod_stack.len();
260-
for p in &included_mod_stack[i..len] {
261-
err.push_str(&p.to_string_lossy());
262-
err.push_str(" -> ");
263-
}
264-
err.push_str(&path.to_string_lossy());
265-
return Err(self.struct_span_err(id_sp, &err[..]));
266-
}
257+
self.error_on_circular_module(id_sp, &path, &included_mod_stack)?;
267258
included_mod_stack.push(path.clone());
268259
drop(included_mod_stack);
269260

@@ -277,6 +268,25 @@ impl<'a> Parser<'a> {
277268
Ok(module)
278269
}
279270

271+
fn error_on_circular_module(
272+
&self,
273+
span: Span,
274+
path: &Path,
275+
included_mod_stack: &[PathBuf],
276+
) -> PResult<'a, ()> {
277+
if let Some(i) = included_mod_stack.iter().position(|p| *p == path) {
278+
let mut err = String::from("circular modules: ");
279+
let len = included_mod_stack.len();
280+
for p in &included_mod_stack[i..len] {
281+
err.push_str(&p.to_string_lossy());
282+
err.push_str(" -> ");
283+
}
284+
err.push_str(&path.to_string_lossy());
285+
return Err(self.struct_span_err(span, &err[..]));
286+
}
287+
Ok(())
288+
}
289+
280290
fn push_directory(&mut self, id: Ident, attrs: &[Attribute]) {
281291
if let Some(path) = attr::first_attr_value_str_by_name(attrs, sym::path) {
282292
self.directory.path.push(&*path.as_str());

0 commit comments

Comments
 (0)