From 4c617e8fb32045e1d60940ba4c79942ef0301566 Mon Sep 17 00:00:00 2001 From: Caleb Cartwright Date: Mon, 15 Mar 2021 20:07:44 -0500 Subject: [PATCH] deps: apply rustc module loading changes --- src/formatting.rs | 2 +- src/modules.rs | 57 +++++++++++++++++++++++-------------------- src/syntux/parser.rs | 3 ++- src/syntux/session.rs | 10 ++------ 4 files changed, 35 insertions(+), 37 deletions(-) diff --git a/src/formatting.rs b/src/formatting.rs index ce28f6bfea3..caf24476e61 100644 --- a/src/formatting.rs +++ b/src/formatting.rs @@ -92,7 +92,7 @@ fn format_project( let mut context = FormatContext::new(&krate, report, parse_session, config, handler); let files = modules::ModResolver::new( &context.parse_session, - directory_ownership.unwrap_or(DirectoryOwnership::UnownedViaMod), + directory_ownership.unwrap_or(DirectoryOwnership::UnownedViaBlock), !input_is_stdin && !config.skip_children(), ) .visit_crate(&krate)?; diff --git a/src/modules.rs b/src/modules.rs index feffd6e4a77..ed4316974db 100644 --- a/src/modules.rs +++ b/src/modules.rs @@ -13,7 +13,7 @@ use crate::attr::MetaVisitor; use crate::config::FileName; use crate::items::is_mod_decl; use crate::syntux::parser::{ - Directory, DirectoryOwnership, ModulePathSuccess, Parser, ParserError, + Directory, DirectoryOwnership, ModError, ModulePathSuccess, Parser, ParserError, }; use crate::syntux::session::ParseSess; use crate::utils::contains_skip; @@ -61,6 +61,9 @@ impl<'a> AstLike for Module<'a> { fn visit_attrs(&mut self, f: impl FnOnce(&mut Vec)) { f(&mut self.inner_attr) } + fn tokens_mut(&mut self) -> Option<&mut Option> { + unimplemented!() + } } /// Maps each module to the corresponding file. @@ -331,7 +334,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> { ) -> Result>, ModuleResolutionError> { let relative = match self.directory.ownership { DirectoryOwnership::Owned { relative } => relative, - DirectoryOwnership::UnownedViaBlock | DirectoryOwnership::UnownedViaMod => None, + DirectoryOwnership::UnownedViaBlock => None, }; if let Some(path) = Parser::submod_path_from_attr(attrs, &self.directory.path) { if self.parse_sess.is_file_parsed(&path) { @@ -366,31 +369,32 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> { match self .parse_sess .default_submod_path(mod_name, relative, &self.directory.path) - .result { Ok(ModulePathSuccess { - path, ownership, .. + file_path, + dir_ownership, + .. }) => { let outside_mods_empty = mods_outside_ast.is_empty(); let should_insert = !mods_outside_ast .iter() - .any(|(outside_path, _, _)| outside_path == &path); - if self.parse_sess.is_file_parsed(&path) { + .any(|(outside_path, _, _)| outside_path == &file_path); + if self.parse_sess.is_file_parsed(&file_path) { if outside_mods_empty { return Ok(None); } else { if should_insert { - mods_outside_ast.push((path, ownership, sub_mod.clone())); + mods_outside_ast.push((file_path, dir_ownership, sub_mod.clone())); } return Ok(Some(SubModKind::MultiExternal(mods_outside_ast))); } } - match Parser::parse_file_as_module(self.parse_sess, &path, sub_mod.span) { + match Parser::parse_file_as_module(self.parse_sess, &file_path, sub_mod.span) { Ok((ref attrs, _, _)) if contains_skip(attrs) => Ok(None), Ok((attrs, items, span)) if outside_mods_empty => { Ok(Some(SubModKind::External( - path, - ownership, + file_path, + dir_ownership, Module::new( span, Some(Cow::Owned(ast::ModKind::Unloaded)), @@ -401,8 +405,8 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> { } Ok((attrs, items, span)) => { mods_outside_ast.push(( - path.clone(), - ownership, + file_path.clone(), + dir_ownership, Module::new( span, Some(Cow::Owned(ast::ModKind::Unloaded)), @@ -411,39 +415,38 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> { ), )); if should_insert { - mods_outside_ast.push((path, ownership, sub_mod.clone())); + mods_outside_ast.push((file_path, dir_ownership, sub_mod.clone())); } Ok(Some(SubModKind::MultiExternal(mods_outside_ast))) } Err(ParserError::ParseError) => Err(ModuleResolutionError { module: mod_name.to_string(), - kind: ModuleResolutionErrorKind::ParseError { file: path }, + kind: ModuleResolutionErrorKind::ParseError { file: file_path }, }), Err(..) if outside_mods_empty => Err(ModuleResolutionError { module: mod_name.to_string(), - kind: ModuleResolutionErrorKind::NotFound { file: path }, + kind: ModuleResolutionErrorKind::NotFound { file: file_path }, }), Err(..) => { if should_insert { - mods_outside_ast.push((path, ownership, sub_mod.clone())); + mods_outside_ast.push((file_path, dir_ownership, sub_mod.clone())); } Ok(Some(SubModKind::MultiExternal(mods_outside_ast))) } } } - Err(mut e) if !mods_outside_ast.is_empty() => { - e.cancel(); + Err(mod_err) if !mods_outside_ast.is_empty() => { + if let ModError::ParserError(mut e) = mod_err { + e.cancel(); + } Ok(Some(SubModKind::MultiExternal(mods_outside_ast))) } - Err(mut e) => { - e.cancel(); - Err(ModuleResolutionError { - module: mod_name.to_string(), - kind: ModuleResolutionErrorKind::NotFound { - file: self.directory.path.clone(), - }, - }) - } + Err(_) => Err(ModuleResolutionError { + module: mod_name.to_string(), + kind: ModuleResolutionErrorKind::NotFound { + file: self.directory.path.clone(), + }, + }), } } diff --git a/src/syntux/parser.rs b/src/syntux/parser.rs index 29248ced2ff..0b94749f3c6 100644 --- a/src/syntux/parser.rs +++ b/src/syntux/parser.rs @@ -14,8 +14,9 @@ use crate::attr::first_attr_value_str_by_name; use crate::syntux::session::ParseSess; use crate::Input; -pub(crate) type DirectoryOwnership = rustc_expand::module::DirectoryOwnership; +pub(crate) type DirectoryOwnership = rustc_expand::module::DirOwnership; pub(crate) type ModulePathSuccess = rustc_expand::module::ModulePathSuccess; +pub(crate) type ModError<'a> = rustc_expand::module::ModError<'a>; #[derive(Clone)] pub(crate) struct Directory { diff --git a/src/syntux/session.rs b/src/syntux/session.rs index ef5ad62674e..374d08f7f23 100644 --- a/src/syntux/session.rs +++ b/src/syntux/session.rs @@ -150,14 +150,8 @@ impl ParseSess { id: symbol::Ident, relative: Option, dir_path: &Path, - ) -> rustc_expand::module::ModulePath<'_> { - rustc_expand::module::default_submod_path( - &self.parse_sess, - id, - rustc_span::DUMMY_SP, - relative, - dir_path, - ) + ) -> Result> { + rustc_expand::module::default_submod_path(&self.parse_sess, id, relative, dir_path) } pub(crate) fn is_file_parsed(&self, path: &Path) -> bool {