Skip to content

Commit ef2b1f1

Browse files
petrochenkovpietroalbini
authored andcommitted
resolve: Continue search in outer scopes after applying derive resolution fallback
1 parent 21ef152 commit ef2b1f1

File tree

3 files changed

+41
-13
lines changed

3 files changed

+41
-13
lines changed

src/librustc_resolve/lib.rs

+15-13
Original file line numberDiff line numberDiff line change
@@ -1889,12 +1889,13 @@ impl<'a> Resolver<'a> {
18891889
}
18901890

18911891
ident.span = ident.span.modern();
1892+
let mut poisoned = None;
18921893
loop {
1893-
let (opt_module, poisoned) = if let Some(node_id) = record_used_id {
1894+
let opt_module = if let Some(node_id) = record_used_id {
18941895
self.hygienic_lexical_parent_with_compatibility_fallback(module, &mut ident.span,
1895-
node_id)
1896+
node_id, &mut poisoned)
18961897
} else {
1897-
(self.hygienic_lexical_parent(module, &mut ident.span), None)
1898+
self.hygienic_lexical_parent(module, &mut ident.span)
18981899
};
18991900
module = unwrap_or!(opt_module, break);
19001901
let orig_current_module = self.current_module;
@@ -1917,9 +1918,9 @@ impl<'a> Resolver<'a> {
19171918
}
19181919
return Some(LexicalScopeBinding::Item(binding))
19191920
}
1920-
_ if poisoned.is_some() => break,
1921-
Err(Undetermined) => return None,
1922-
Err(Determined) => {}
1921+
Err(Determined) => continue,
1922+
Err(Undetermined) =>
1923+
span_bug!(ident.span, "undetermined resolution during main resolution pass"),
19231924
}
19241925
}
19251926

@@ -1965,12 +1966,12 @@ impl<'a> Resolver<'a> {
19651966
None
19661967
}
19671968

1968-
fn hygienic_lexical_parent_with_compatibility_fallback(
1969-
&mut self, module: Module<'a>, span: &mut Span, node_id: NodeId
1970-
) -> (Option<Module<'a>>, /* poisoned */ Option<NodeId>)
1971-
{
1969+
fn hygienic_lexical_parent_with_compatibility_fallback(&mut self, module: Module<'a>,
1970+
span: &mut Span, node_id: NodeId,
1971+
poisoned: &mut Option<NodeId>)
1972+
-> Option<Module<'a>> {
19721973
if let module @ Some(..) = self.hygienic_lexical_parent(module, span) {
1973-
return (module, None);
1974+
return module;
19741975
}
19751976

19761977
// We need to support the next case under a deprecation warning
@@ -1991,13 +1992,14 @@ impl<'a> Resolver<'a> {
19911992
// The macro is a proc macro derive
19921993
if module.expansion.looks_like_proc_macro_derive() {
19931994
if parent.expansion.is_descendant_of(span.ctxt().outer()) {
1994-
return (module.parent, Some(node_id));
1995+
*poisoned = Some(node_id);
1996+
return module.parent;
19951997
}
19961998
}
19971999
}
19982000
}
19992001

2000-
(None, None)
2002+
None
20012003
}
20022004

20032005
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)