Skip to content

Commit 4c617e8

Browse files
deps: apply rustc module loading changes
1 parent f2bc4b5 commit 4c617e8

File tree

4 files changed

+35
-37
lines changed

4 files changed

+35
-37
lines changed

src/formatting.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ fn format_project<T: FormatHandler>(
9292
let mut context = FormatContext::new(&krate, report, parse_session, config, handler);
9393
let files = modules::ModResolver::new(
9494
&context.parse_session,
95-
directory_ownership.unwrap_or(DirectoryOwnership::UnownedViaMod),
95+
directory_ownership.unwrap_or(DirectoryOwnership::UnownedViaBlock),
9696
!input_is_stdin && !config.skip_children(),
9797
)
9898
.visit_crate(&krate)?;

src/modules.rs

Lines changed: 30 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use crate::attr::MetaVisitor;
1313
use crate::config::FileName;
1414
use crate::items::is_mod_decl;
1515
use crate::syntux::parser::{
16-
Directory, DirectoryOwnership, ModulePathSuccess, Parser, ParserError,
16+
Directory, DirectoryOwnership, ModError, ModulePathSuccess, Parser, ParserError,
1717
};
1818
use crate::syntux::session::ParseSess;
1919
use crate::utils::contains_skip;
@@ -61,6 +61,9 @@ impl<'a> AstLike for Module<'a> {
6161
fn visit_attrs(&mut self, f: impl FnOnce(&mut Vec<ast::Attribute>)) {
6262
f(&mut self.inner_attr)
6363
}
64+
fn tokens_mut(&mut self) -> Option<&mut Option<rustc_ast::tokenstream::LazyTokenStream>> {
65+
unimplemented!()
66+
}
6467
}
6568

6669
/// Maps each module to the corresponding file.
@@ -331,7 +334,7 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
331334
) -> Result<Option<SubModKind<'c, 'ast>>, ModuleResolutionError> {
332335
let relative = match self.directory.ownership {
333336
DirectoryOwnership::Owned { relative } => relative,
334-
DirectoryOwnership::UnownedViaBlock | DirectoryOwnership::UnownedViaMod => None,
337+
DirectoryOwnership::UnownedViaBlock => None,
335338
};
336339
if let Some(path) = Parser::submod_path_from_attr(attrs, &self.directory.path) {
337340
if self.parse_sess.is_file_parsed(&path) {
@@ -366,31 +369,32 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
366369
match self
367370
.parse_sess
368371
.default_submod_path(mod_name, relative, &self.directory.path)
369-
.result
370372
{
371373
Ok(ModulePathSuccess {
372-
path, ownership, ..
374+
file_path,
375+
dir_ownership,
376+
..
373377
}) => {
374378
let outside_mods_empty = mods_outside_ast.is_empty();
375379
let should_insert = !mods_outside_ast
376380
.iter()
377-
.any(|(outside_path, _, _)| outside_path == &path);
378-
if self.parse_sess.is_file_parsed(&path) {
381+
.any(|(outside_path, _, _)| outside_path == &file_path);
382+
if self.parse_sess.is_file_parsed(&file_path) {
379383
if outside_mods_empty {
380384
return Ok(None);
381385
} else {
382386
if should_insert {
383-
mods_outside_ast.push((path, ownership, sub_mod.clone()));
387+
mods_outside_ast.push((file_path, dir_ownership, sub_mod.clone()));
384388
}
385389
return Ok(Some(SubModKind::MultiExternal(mods_outside_ast)));
386390
}
387391
}
388-
match Parser::parse_file_as_module(self.parse_sess, &path, sub_mod.span) {
392+
match Parser::parse_file_as_module(self.parse_sess, &file_path, sub_mod.span) {
389393
Ok((ref attrs, _, _)) if contains_skip(attrs) => Ok(None),
390394
Ok((attrs, items, span)) if outside_mods_empty => {
391395
Ok(Some(SubModKind::External(
392-
path,
393-
ownership,
396+
file_path,
397+
dir_ownership,
394398
Module::new(
395399
span,
396400
Some(Cow::Owned(ast::ModKind::Unloaded)),
@@ -401,8 +405,8 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
401405
}
402406
Ok((attrs, items, span)) => {
403407
mods_outside_ast.push((
404-
path.clone(),
405-
ownership,
408+
file_path.clone(),
409+
dir_ownership,
406410
Module::new(
407411
span,
408412
Some(Cow::Owned(ast::ModKind::Unloaded)),
@@ -411,39 +415,38 @@ impl<'ast, 'sess, 'c> ModResolver<'ast, 'sess> {
411415
),
412416
));
413417
if should_insert {
414-
mods_outside_ast.push((path, ownership, sub_mod.clone()));
418+
mods_outside_ast.push((file_path, dir_ownership, sub_mod.clone()));
415419
}
416420
Ok(Some(SubModKind::MultiExternal(mods_outside_ast)))
417421
}
418422
Err(ParserError::ParseError) => Err(ModuleResolutionError {
419423
module: mod_name.to_string(),
420-
kind: ModuleResolutionErrorKind::ParseError { file: path },
424+
kind: ModuleResolutionErrorKind::ParseError { file: file_path },
421425
}),
422426
Err(..) if outside_mods_empty => Err(ModuleResolutionError {
423427
module: mod_name.to_string(),
424-
kind: ModuleResolutionErrorKind::NotFound { file: path },
428+
kind: ModuleResolutionErrorKind::NotFound { file: file_path },
425429
}),
426430
Err(..) => {
427431
if should_insert {
428-
mods_outside_ast.push((path, ownership, sub_mod.clone()));
432+
mods_outside_ast.push((file_path, dir_ownership, sub_mod.clone()));
429433
}
430434
Ok(Some(SubModKind::MultiExternal(mods_outside_ast)))
431435
}
432436
}
433437
}
434-
Err(mut e) if !mods_outside_ast.is_empty() => {
435-
e.cancel();
438+
Err(mod_err) if !mods_outside_ast.is_empty() => {
439+
if let ModError::ParserError(mut e) = mod_err {
440+
e.cancel();
441+
}
436442
Ok(Some(SubModKind::MultiExternal(mods_outside_ast)))
437443
}
438-
Err(mut e) => {
439-
e.cancel();
440-
Err(ModuleResolutionError {
441-
module: mod_name.to_string(),
442-
kind: ModuleResolutionErrorKind::NotFound {
443-
file: self.directory.path.clone(),
444-
},
445-
})
446-
}
444+
Err(_) => Err(ModuleResolutionError {
445+
module: mod_name.to_string(),
446+
kind: ModuleResolutionErrorKind::NotFound {
447+
file: self.directory.path.clone(),
448+
},
449+
}),
447450
}
448451
}
449452

src/syntux/parser.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ use crate::attr::first_attr_value_str_by_name;
1414
use crate::syntux::session::ParseSess;
1515
use crate::Input;
1616

17-
pub(crate) type DirectoryOwnership = rustc_expand::module::DirectoryOwnership;
17+
pub(crate) type DirectoryOwnership = rustc_expand::module::DirOwnership;
1818
pub(crate) type ModulePathSuccess = rustc_expand::module::ModulePathSuccess;
19+
pub(crate) type ModError<'a> = rustc_expand::module::ModError<'a>;
1920

2021
#[derive(Clone)]
2122
pub(crate) struct Directory {

src/syntux/session.rs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,8 @@ impl ParseSess {
150150
id: symbol::Ident,
151151
relative: Option<symbol::Ident>,
152152
dir_path: &Path,
153-
) -> rustc_expand::module::ModulePath<'_> {
154-
rustc_expand::module::default_submod_path(
155-
&self.parse_sess,
156-
id,
157-
rustc_span::DUMMY_SP,
158-
relative,
159-
dir_path,
160-
)
153+
) -> Result<rustc_expand::module::ModulePathSuccess, rustc_expand::module::ModError<'_>> {
154+
rustc_expand::module::default_submod_path(&self.parse_sess, id, relative, dir_path)
161155
}
162156

163157
pub(crate) fn is_file_parsed(&self, path: &Path) -> bool {

0 commit comments

Comments
 (0)