Skip to content

Commit cbcb550

Browse files
committed
extract error_on_circular_module
1 parent 3eb86cf commit cbcb550

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
@@ -257,16 +257,7 @@ impl<'a> Parser<'a> {
257257
id_sp: Span,
258258
) -> PResult<'a, (Mod, Vec<Attribute>)> {
259259
let mut included_mod_stack = self.sess.included_mod_stack.borrow_mut();
260-
if let Some(i) = included_mod_stack.iter().position(|p| *p == path) {
261-
let mut err = String::from("circular modules: ");
262-
let len = included_mod_stack.len();
263-
for p in &included_mod_stack[i..len] {
264-
err.push_str(&p.to_string_lossy());
265-
err.push_str(" -> ");
266-
}
267-
err.push_str(&path.to_string_lossy());
268-
return Err(self.struct_span_err(id_sp, &err[..]));
269-
}
260+
self.error_on_circular_module(id_sp, &path, &included_mod_stack)?;
270261
included_mod_stack.push(path.clone());
271262
drop(included_mod_stack);
272263

@@ -280,6 +271,25 @@ impl<'a> Parser<'a> {
280271
Ok(module)
281272
}
282273

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

0 commit comments

Comments
 (0)