Skip to content

Commit 1a9137e

Browse files
deps: apply rustc module loading changes
1 parent 2ed1a45 commit 1a9137e

File tree

4 files changed

+37
-37
lines changed

4 files changed

+37
-37
lines changed

Diff for: src/formatting.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ fn format_project(
117117

118118
let files = modules::ModResolver::new(
119119
&parse_session,
120-
directory_ownership.unwrap_or(DirectoryOwnership::UnownedViaMod),
120+
directory_ownership.unwrap_or(DirectoryOwnership::UnownedViaBlock),
121121
!input_is_stdin && operation_setting.recursive,
122122
)
123123
.visit_crate(&krate)?;

Diff for: src/formatting/modules.rs

+32-27
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@ use crate::config::FileName;
1313
use crate::formatting::{
1414
attr::MetaVisitor,
1515
items::is_mod_decl,
16-
syntux::parser::{Directory, DirectoryOwnership, ModulePathSuccess, Parser, ParserError},
16+
syntux::parser::{
17+
Directory, DirectoryOwnership, ModError, ModulePathSuccess, Parser, ParserError,
18+
},
1719
syntux::session::ParseSess,
1820
utils::contains_skip,
1921
};
@@ -104,6 +106,9 @@ impl<'a> AstLike for Module<'a> {
104106
fn visit_attrs(&mut self, f: impl FnOnce(&mut Vec<ast::Attribute>)) {
105107
f(&mut self.inner_attr)
106108
}
109+
fn tokens_mut(&mut self) -> Option<&mut Option<rustc_ast::tokenstream::LazyTokenStream>> {
110+
unimplemented!()
111+
}
107112
}
108113

109114
/// Maps each module to the corresponding file.
@@ -371,7 +376,7 @@ impl<'ast, 'sess> ModResolver<'ast, 'sess> {
371376
) -> Result<Option<SubModKind<'ast>>, ModuleResolutionError> {
372377
let relative = match self.directory.ownership {
373378
DirectoryOwnership::Owned { relative } => relative,
374-
DirectoryOwnership::UnownedViaBlock | DirectoryOwnership::UnownedViaMod => None,
379+
DirectoryOwnership::UnownedViaBlock => None,
375380
};
376381
if let Some(path) =
377382
Parser::submod_path_from_attr(sub_mod.outer_attrs(), &self.directory.path)
@@ -412,34 +417,35 @@ impl<'ast, 'sess> ModResolver<'ast, 'sess> {
412417
match self
413418
.parse_sess
414419
.default_submod_path(sub_mod.ident(), relative, &self.directory.path)
415-
.result
416420
{
417421
Ok(ModulePathSuccess {
418-
path, ownership, ..
422+
file_path,
423+
dir_ownership,
424+
..
419425
}) => {
420426
let outside_mods_empty = mods_outside_ast.is_empty();
421427
let should_insert = !mods_outside_ast
422428
.iter()
423-
.any(|(outside_path, _, _)| outside_path == &path);
424-
if self.parse_sess.is_file_parsed(&path) {
429+
.any(|(outside_path, _, _)| outside_path == &file_path);
430+
if self.parse_sess.is_file_parsed(&file_path) {
425431
if outside_mods_empty {
426432
return Ok(None);
427433
} else {
428434
if should_insert {
429-
mods_outside_ast.push((path, ownership, sub_mod.clone()));
435+
mods_outside_ast.push((file_path, dir_ownership, sub_mod.clone()));
430436
}
431437
return Ok(Some(SubModKind::MultiExternal(mods_outside_ast)));
432438
}
433439
}
434440
match Parser::parse_file_as_module(
435441
self.parse_sess,
436-
&path,
442+
&file_path,
437443
sub_mod.outside_ast_mod_span(),
438444
) {
439445
Ok((attrs, items, span)) if outside_mods_empty => {
440446
Ok(Some(SubModKind::External(
441-
path,
442-
ownership,
447+
file_path,
448+
dir_ownership,
443449
Module::new(
444450
span,
445451
Some(Cow::Owned(ast::ModKind::Unloaded)),
@@ -451,8 +457,8 @@ impl<'ast, 'sess> ModResolver<'ast, 'sess> {
451457
}
452458
Ok((attrs, items, span)) => {
453459
mods_outside_ast.push((
454-
path.clone(),
455-
ownership,
460+
file_path.clone(),
461+
dir_ownership,
456462
Module::new(
457463
span,
458464
Some(Cow::Owned(ast::ModKind::Unloaded)),
@@ -462,39 +468,38 @@ impl<'ast, 'sess> ModResolver<'ast, 'sess> {
462468
),
463469
));
464470
if should_insert {
465-
mods_outside_ast.push((path, ownership, sub_mod.clone()));
471+
mods_outside_ast.push((file_path, dir_ownership, sub_mod.clone()));
466472
}
467473
Ok(Some(SubModKind::MultiExternal(mods_outside_ast)))
468474
}
469475
Err(ParserError::ParseError) => Err(ModuleResolutionError {
470476
module: sub_mod.name(),
471-
kind: ModuleResolutionErrorKind::ParseError { file: path },
477+
kind: ModuleResolutionErrorKind::ParseError { file: file_path },
472478
}),
473479
Err(..) if outside_mods_empty => Err(ModuleResolutionError {
474480
module: sub_mod.name(),
475-
kind: ModuleResolutionErrorKind::NotFound { file: path },
481+
kind: ModuleResolutionErrorKind::NotFound { file: file_path },
476482
}),
477483
Err(..) => {
478484
if should_insert {
479-
mods_outside_ast.push((path, ownership, sub_mod.clone()));
485+
mods_outside_ast.push((file_path, dir_ownership, sub_mod.clone()));
480486
}
481487
Ok(Some(SubModKind::MultiExternal(mods_outside_ast)))
482488
}
483489
}
484490
}
485-
Err(mut e) if !mods_outside_ast.is_empty() => {
486-
e.cancel();
491+
Err(mod_err) if !mods_outside_ast.is_empty() => {
492+
if let ModError::ParserError(mut e) = mod_err {
493+
e.cancel();
494+
}
487495
Ok(Some(SubModKind::MultiExternal(mods_outside_ast)))
488496
}
489-
Err(mut e) => {
490-
e.cancel();
491-
Err(ModuleResolutionError {
492-
module: sub_mod.name(),
493-
kind: ModuleResolutionErrorKind::NotFound {
494-
file: self.directory.path.clone(),
495-
},
496-
})
497-
}
497+
Err(_) => Err(ModuleResolutionError {
498+
module: sub_mod.name(),
499+
kind: ModuleResolutionErrorKind::NotFound {
500+
file: self.directory.path.clone(),
501+
},
502+
}),
498503
}
499504
}
500505

Diff for: src/formatting/syntux/parser.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ use crate::formatting::attr::first_attr_value_str_by_name;
1414
use crate::formatting::syntux::session::ParseSess;
1515
use crate::{Config, 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 {

Diff for: src/formatting/syntux/session.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -146,14 +146,8 @@ impl ParseSess {
146146
id: symbol::Ident,
147147
relative: Option<symbol::Ident>,
148148
dir_path: &Path,
149-
) -> rustc_expand::module::ModulePath<'_> {
150-
rustc_expand::module::default_submod_path(
151-
&self.parse_sess,
152-
id,
153-
rustc_span::DUMMY_SP,
154-
relative,
155-
dir_path,
156-
)
149+
) -> Result<rustc_expand::module::ModulePathSuccess, rustc_expand::module::ModError<'_>> {
150+
rustc_expand::module::default_submod_path(&self.parse_sess, id, relative, dir_path)
157151
}
158152

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

0 commit comments

Comments
 (0)