1
Fork 0

extract error_on_circular_module

This commit is contained in:
Mazdak Farrokhzad 2020-03-07 19:53:25 +01:00
parent 7108b7fbfe
commit dfcefa49ed

View file

@ -254,16 +254,7 @@ impl<'a> Parser<'a> {
id_sp: Span,
) -> PResult<'a, (Mod, Vec<Attribute>)> {
let mut included_mod_stack = self.sess.included_mod_stack.borrow_mut();
if let Some(i) = included_mod_stack.iter().position(|p| *p == path) {
let mut err = String::from("circular modules: ");
let len = included_mod_stack.len();
for p in &included_mod_stack[i..len] {
err.push_str(&p.to_string_lossy());
err.push_str(" -> ");
}
err.push_str(&path.to_string_lossy());
return Err(self.struct_span_err(id_sp, &err[..]));
}
self.error_on_circular_module(id_sp, &path, &included_mod_stack)?;
included_mod_stack.push(path.clone());
drop(included_mod_stack);
@ -277,6 +268,25 @@ impl<'a> Parser<'a> {
Ok(module)
}
fn error_on_circular_module(
&self,
span: Span,
path: &Path,
included_mod_stack: &[PathBuf],
) -> PResult<'a, ()> {
if let Some(i) = included_mod_stack.iter().position(|p| *p == path) {
let mut err = String::from("circular modules: ");
let len = included_mod_stack.len();
for p in &included_mod_stack[i..len] {
err.push_str(&p.to_string_lossy());
err.push_str(" -> ");
}
err.push_str(&path.to_string_lossy());
return Err(self.struct_span_err(span, &err[..]));
}
Ok(())
}
fn push_directory(&mut self, id: Ident, attrs: &[Attribute]) {
if let Some(path) = attr::first_attr_value_str_by_name(attrs, sym::path) {
self.directory.path.push(&*path.as_str());