Skip to content

Commit 81e4cbd

Browse files
committed
Attempt to be more precise when looking for poinsoned module
1 parent 6b39f6e commit 81e4cbd

File tree

3 files changed

+62
-12
lines changed

3 files changed

+62
-12
lines changed

compiler/rustc_resolve/src/ident.rs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1835,6 +1835,14 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
18351835
}
18361836

18371837
let binding = if let Some(module) = module {
1838+
if !self.mods_with_parse_errors.is_empty()
1839+
&& let ModuleOrUniformRoot::Module(m) = module
1840+
&& m.res()
1841+
.and_then(|r| r.module_like_def_id())
1842+
.is_some_and(|def_id| self.mods_with_parse_errors.contains(&def_id))
1843+
{
1844+
module_had_parse_errors = true;
1845+
}
18381846
self.reborrow().resolve_ident_in_module(
18391847
module,
18401848
ident,
@@ -1867,7 +1875,19 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
18671875
path.len() - 1,
18681876
));
18691877
}
1870-
_ => Err(Determinacy::determined(finalize.is_some())),
1878+
_ => {
1879+
for rib in &ribs[ns] {
1880+
if let RibKind::Module(module) = rib.kind
1881+
&& module.res().and_then(|r| r.module_like_def_id()).is_some_and(
1882+
|def_id| self.mods_with_parse_errors.contains(&def_id),
1883+
)
1884+
{
1885+
module_had_parse_errors = true;
1886+
break;
1887+
}
1888+
}
1889+
Err(Determinacy::determined(finalize.is_some()))
1890+
}
18711891
}
18721892
} else {
18731893
self.reborrow().resolve_ident_in_scope_set(
@@ -1904,9 +1924,6 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
19041924

19051925
let maybe_assoc = opt_ns != Some(MacroNS) && PathSource::Type.is_expected(res);
19061926
if let Some(def_id) = binding.res().module_like_def_id() {
1907-
if self.mods_with_parse_errors.contains(&def_id) {
1908-
module_had_parse_errors = true;
1909-
}
19101927
module = Some(ModuleOrUniformRoot::Module(self.expect_module(def_id)));
19111928
record_segment_res(self.reborrow(), finalize, res, id);
19121929
} else if res == Res::ToolMod && !is_last && opt_ns.is_some() {

tests/ui/macros/compile_error_macro-suppress-errors.rs

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,28 @@
1-
mod some_module {
1+
pub mod some_module {
22
compile_error!("Error in a module"); //~ ERROR: Error in a module
33

4-
fn abc() {
4+
fn abc() -> Hello {
55
let _: self::SomeType = self::Hello::new();
66
let _: SomeType = Hello::new();
77
}
8+
9+
mod inner_module {
10+
use super::Hello;
11+
use crate::another_module::NotExist; //~ ERROR: unresolved import `crate::another_module::NotExist`
12+
use crate::some_module::World;
13+
struct Foo {
14+
bar: super::Xyz,
15+
error: self::MissingType, //~ ERROR: cannot find type `MissingType` in module `self`
16+
}
17+
}
818
}
919

10-
mod another_module {}
20+
pub mod another_module {
21+
use crate::some_module::NotExist;
22+
fn error_in_this_function() {
23+
compile_error!("Error in a function"); //~ ERROR: Error in a function
24+
}
25+
}
1126

1227
fn main() {
1328
// these errors are suppressed because of the compile_error! macro

tests/ui/macros/compile_error_macro-suppress-errors.stderr

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,25 +4,43 @@ error: Error in a module
44
LL | compile_error!("Error in a module");
55
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
66

7+
error: Error in a function
8+
--> $DIR/compile_error_macro-suppress-errors.rs:23:9
9+
|
10+
LL | compile_error!("Error in a function");
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
13+
error[E0432]: unresolved import `crate::another_module::NotExist`
14+
--> $DIR/compile_error_macro-suppress-errors.rs:11:13
15+
|
16+
LL | use crate::another_module::NotExist;
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ no `NotExist` in `another_module`
18+
719
error[E0433]: failed to resolve: could not find `Hello` in `another_module`
8-
--> $DIR/compile_error_macro-suppress-errors.rs:22:55
20+
--> $DIR/compile_error_macro-suppress-errors.rs:37:55
921
|
1022
LL | let _: another_module::SomeType = another_module::Hello::new();
1123
| ^^^^^ could not find `Hello` in `another_module`
1224

25+
error[E0412]: cannot find type `MissingType` in module `self`
26+
--> $DIR/compile_error_macro-suppress-errors.rs:15:26
27+
|
28+
LL | error: self::MissingType,
29+
| ^^^^^^^^^^^ not found in `self`
30+
1331
error[E0425]: cannot find function `some_function` in module `another_module`
14-
--> $DIR/compile_error_macro-suppress-errors.rs:20:29
32+
--> $DIR/compile_error_macro-suppress-errors.rs:35:29
1533
|
1634
LL | let _ = another_module::some_function();
1735
| ^^^^^^^^^^^^^ not found in `another_module`
1836

1937
error[E0412]: cannot find type `SomeType` in module `another_module`
20-
--> $DIR/compile_error_macro-suppress-errors.rs:22:28
38+
--> $DIR/compile_error_macro-suppress-errors.rs:37:28
2139
|
2240
LL | let _: another_module::SomeType = another_module::Hello::new();
2341
| ^^^^^^^^ not found in `another_module`
2442

25-
error: aborting due to 4 previous errors
43+
error: aborting due to 7 previous errors
2644

27-
Some errors have detailed explanations: E0412, E0425, E0433.
45+
Some errors have detailed explanations: E0412, E0425, E0432, E0433.
2846
For more information about an error, try `rustc --explain E0412`.

0 commit comments

Comments
 (0)