Skip to content

Commit 71a1ef1

Browse files
committed
Auto merge of #53516 - petrochenkov:derregr, r=estebank
resolve: Continue search in outer scopes after applying derive resolution fallback Fixes #53263
2 parents 24bc544 + 7e8825b commit 71a1ef1

File tree

3 files changed

+38
-11
lines changed

3 files changed

+38
-11
lines changed

src/librustc_resolve/lib.rs

+12-11
Original file line numberDiff line numberDiff line change
@@ -1901,12 +1901,13 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
19011901
}
19021902

19031903
ident.span = ident.span.modern();
1904+
let mut poisoned = None;
19041905
loop {
1905-
let (opt_module, poisoned) = if let Some(node_id) = record_used_id {
1906+
let opt_module = if let Some(node_id) = record_used_id {
19061907
self.hygienic_lexical_parent_with_compatibility_fallback(module, &mut ident.span,
1907-
node_id)
1908+
node_id, &mut poisoned)
19081909
} else {
1909-
(self.hygienic_lexical_parent(module, &mut ident.span), None)
1910+
self.hygienic_lexical_parent(module, &mut ident.span)
19101911
};
19111912
module = unwrap_or!(opt_module, break);
19121913
let orig_current_module = self.current_module;
@@ -1934,7 +1935,6 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
19341935
}
19351936
return Some(LexicalScopeBinding::Item(binding))
19361937
}
1937-
_ if poisoned.is_some() => break,
19381938
Err(Determined) => continue,
19391939
Err(Undetermined) =>
19401940
span_bug!(ident.span, "undetermined resolution during main resolution pass"),
@@ -1994,12 +1994,12 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
19941994
None
19951995
}
19961996

1997-
fn hygienic_lexical_parent_with_compatibility_fallback(
1998-
&mut self, module: Module<'a>, span: &mut Span, node_id: NodeId
1999-
) -> (Option<Module<'a>>, /* poisoned */ Option<NodeId>)
2000-
{
1997+
fn hygienic_lexical_parent_with_compatibility_fallback(&mut self, module: Module<'a>,
1998+
span: &mut Span, node_id: NodeId,
1999+
poisoned: &mut Option<NodeId>)
2000+
-> Option<Module<'a>> {
20012001
if let module @ Some(..) = self.hygienic_lexical_parent(module, span) {
2002-
return (module, None);
2002+
return module;
20032003
}
20042004

20052005
// We need to support the next case under a deprecation warning
@@ -2020,13 +2020,14 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
20202020
// The macro is a proc macro derive
20212021
if module.expansion.looks_like_proc_macro_derive() {
20222022
if parent.expansion.is_descendant_of(span.ctxt().outer()) {
2023-
return (module.parent, Some(node_id));
2023+
*poisoned = Some(node_id);
2024+
return module.parent;
20242025
}
20252026
}
20262027
}
20272028
}
20282029

2029-
(None, None)
2030+
None
20302031
}
20312032

20322033
fn resolve_ident_in_module(&mut self,

src/test/ui-fulldeps/proc-macro/generate-mod.rs

+8
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,14 @@ struct S;
3131
//~| WARN this was previously accepted
3232
struct Z;
3333

34+
fn inner_block() {
35+
#[derive(generate_mod::CheckDerive)] //~ WARN cannot find type `FromOutside` in this scope
36+
//~| WARN cannot find type `OuterDerive` in this scope
37+
//~| WARN this was previously accepted
38+
//~| WARN this was previously accepted
39+
struct InnerZ;
40+
}
41+
3442
#[derive(generate_mod::CheckDeriveLint)] // OK, lint is suppressed
3543
struct W;
3644

src/test/ui-fulldeps/proc-macro/generate-mod.stderr

+18
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,24 @@ LL | #[derive(generate_mod::CheckDerive)] //~ WARN cannot find type `FromOutside
4141
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
4242
= note: for more information, see issue #50504 <https://github.com/rust-lang/rust/issues/50504>
4343

44+
warning: cannot find type `FromOutside` in this scope
45+
--> $DIR/generate-mod.rs:35:14
46+
|
47+
LL | #[derive(generate_mod::CheckDerive)] //~ WARN cannot find type `FromOutside` in this scope
48+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ names from parent modules are not accessible without an explicit import
49+
|
50+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
51+
= note: for more information, see issue #50504 <https://github.com/rust-lang/rust/issues/50504>
52+
53+
warning: cannot find type `OuterDerive` in this scope
54+
--> $DIR/generate-mod.rs:35:14
55+
|
56+
LL | #[derive(generate_mod::CheckDerive)] //~ WARN cannot find type `FromOutside` in this scope
57+
| ^^^^^^^^^^^^^^^^^^^^^^^^^ names from parent modules are not accessible without an explicit import
58+
|
59+
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
60+
= note: for more information, see issue #50504 <https://github.com/rust-lang/rust/issues/50504>
61+
4462
error: aborting due to 4 previous errors
4563

4664
For more information about this error, try `rustc --explain E0412`.

0 commit comments

Comments
 (0)