Skip to content

Commit a6cb1e6

Browse files
committed
Fix mod from inline mod in non-mod-rs.
This works under the assumption that filesystem paths should match mod paths. When a mod is loaded from within an inline mod, it was using the wrong path when inside a non-mod-rs file. It was not including the path components from the non-mod-rs file. This change also includes: - Added a test to the run-pass test. - Added a test to verify the error message when missing. - Remove unused `non_modrs_mods` for feature gate diagnostics. - Fixes the run-pass test, it was accidentally removed during stabilization. - Remove the vestiges of the feature gate tests in `test/ui`. - Enable the diagnostic test on windows, there didn't seem to be a reason to disable it.
1 parent 46880f4 commit a6cb1e6

File tree

26 files changed

+44
-164
lines changed

26 files changed

+44
-164
lines changed

src/libsyntax/parse/lexer/mod.rs

-1
Original file line numberDiff line numberDiff line change
@@ -1869,7 +1869,6 @@ mod tests {
18691869
missing_fragment_specifiers: Lock::new(FxHashSet::default()),
18701870
raw_identifier_spans: Lock::new(Vec::new()),
18711871
registered_diagnostics: Lock::new(ErrorMap::new()),
1872-
non_modrs_mods: Lock::new(vec![]),
18731872
buffered_lints: Lock::new(vec![]),
18741873
}
18751874
}

src/libsyntax/parse/mod.rs

-4
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ pub struct ParseSess {
5252
pub raw_identifier_spans: Lock<Vec<Span>>,
5353
/// The registered diagnostics codes
5454
crate registered_diagnostics: Lock<ErrorMap>,
55-
// Spans where a `mod foo;` statement was included in a non-mod.rs file.
56-
// These are used to issue errors if the non_modrs_mods feature is not enabled.
57-
pub non_modrs_mods: Lock<Vec<(ast::Ident, Span)>>,
5855
/// Used to determine and report recursive mod inclusions
5956
included_mod_stack: Lock<Vec<PathBuf>>,
6057
code_map: Lrc<SourceMap>,
@@ -81,7 +78,6 @@ impl ParseSess {
8178
registered_diagnostics: Lock::new(ErrorMap::new()),
8279
included_mod_stack: Lock::new(vec![]),
8380
code_map,
84-
non_modrs_mods: Lock::new(vec![]),
8581
buffered_lints: Lock::new(vec![]),
8682
}
8783
}

src/libsyntax/parse/parser.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -6426,6 +6426,10 @@ impl<'a> Parser<'a> {
64266426
self.directory.path.to_mut().push(&path.as_str());
64276427
self.directory.ownership = DirectoryOwnership::Owned { relative: None };
64286428
} else {
6429+
if let DirectoryOwnership::Owned{ relative: Some(id) } = self.directory.ownership {
6430+
self.directory.path.to_mut().push(id.as_str());
6431+
self.directory.ownership = DirectoryOwnership::Owned { relative: None };
6432+
}
64296433
self.directory.path.to_mut().push(&id.as_str());
64306434
}
64316435
}
@@ -6533,16 +6537,7 @@ impl<'a> Parser<'a> {
65336537
}
65346538

65356539
let relative = match self.directory.ownership {
6536-
DirectoryOwnership::Owned { relative } => {
6537-
// Push the usage onto the list of non-mod.rs mod uses.
6538-
// This is used later for feature-gate error reporting.
6539-
if let Some(cur_file_ident) = relative {
6540-
self.sess
6541-
.non_modrs_mods.borrow_mut()
6542-
.push((cur_file_ident, id_sp));
6543-
}
6544-
relative
6545-
},
6540+
DirectoryOwnership::Owned { relative } => relative,
65466541
DirectoryOwnership::UnownedViaBlock |
65476542
DirectoryOwnership::UnownedViaMod(_) => None,
65486543
};

src/test/run-pass/non_modrs_mods/foors_mod.rs

+5
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@
1212

1313
pub mod inner_modrs_mod;
1414
pub mod inner_foors_mod;
15+
pub mod block {
16+
pub mod block_inner {
17+
pub mod block_inner_inner;
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
pub fn foo() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// run-pass
2+
//
3+
// ignore-pretty issue #37195
4+
pub mod modrs_mod;
5+
pub mod foors_mod;
6+
#[path = "some_crazy_attr_mod_dir/arbitrary_name.rs"]
7+
pub mod attr_mod;
8+
pub fn main() {
9+
modrs_mod::inner_modrs_mod::innest::foo();
10+
modrs_mod::inner_foors_mod::innest::foo();
11+
foors_mod::inner_modrs_mod::innest::foo();
12+
foors_mod::inner_foors_mod::innest::foo();
13+
foors_mod::block::block_inner::block_inner_inner::foo();
14+
attr_mod::inner_modrs_mod::innest::foo();
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// ignore-test this is just a helper for the real test in this dir
2+
3+
mod inline {
4+
mod missing;
5+
}

src/test/ui/missing_non_modrs_mod/missing_non_modrs_mod.rs

-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,5 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11-
// ignore-windows
12-
1311
mod foo;
1412
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
mod foo_inline;
2+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
error[E0583]: file not found for module `missing`
2+
--> $DIR/foo_inline.rs:4:9
3+
|
4+
LL | mod missing;
5+
| ^^^^^^^
6+
|
7+
= help: name the file either missing.rs or missing/mod.rs inside the directory "$DIR/foo_inline/inline"
8+
9+
error: aborting due to previous error
10+
11+
For more information about this error, try `rustc --explain E0583`.

src/test/ui/non_modrs_mods/foors_mod.rs

-14
This file was deleted.

src/test/ui/non_modrs_mods/foors_mod/compiletest-ignore-dir

Whitespace-only changes.

src/test/ui/non_modrs_mods/foors_mod/inner_foors_mod.rs

-11
This file was deleted.

src/test/ui/non_modrs_mods/foors_mod/inner_foors_mod/innest.rs

-11
This file was deleted.

src/test/ui/non_modrs_mods/foors_mod/inner_modrs_mod/innest.rs

-11
This file was deleted.

src/test/ui/non_modrs_mods/foors_mod/inner_modrs_mod/mod.rs

-11
This file was deleted.

src/test/ui/non_modrs_mods/modrs_mod/compiletest-ignore-dir

Whitespace-only changes.

src/test/ui/non_modrs_mods/modrs_mod/inner_foors_mod.rs

-11
This file was deleted.

src/test/ui/non_modrs_mods/modrs_mod/inner_foors_mod/innest.rs

-11
This file was deleted.

src/test/ui/non_modrs_mods/modrs_mod/inner_modrs_mod/innest.rs

-11
This file was deleted.

src/test/ui/non_modrs_mods/modrs_mod/inner_modrs_mod/mod.rs

-11
This file was deleted.

src/test/ui/non_modrs_mods/modrs_mod/mod.rs

-12
This file was deleted.

src/test/ui/non_modrs_mods/some_crazy_attr_mod_dir/arbitrary_name.rs

-11
This file was deleted.

src/test/ui/non_modrs_mods/some_crazy_attr_mod_dir/compiletest-ignore-dir

Whitespace-only changes.

src/test/ui/non_modrs_mods/some_crazy_attr_mod_dir/inner_modrs_mod/innest.rs

-11
This file was deleted.

src/test/ui/non_modrs_mods/some_crazy_attr_mod_dir/inner_modrs_mod/mod.rs

-11
This file was deleted.

0 commit comments

Comments
 (0)