Skip to content

Commit

Permalink
resolve: Continue search in outer scopes after applying derive resolu…
Browse files Browse the repository at this point in the history
…tion fallback
  • Loading branch information
petrochenkov authored and pietroalbini committed Aug 25, 2018
1 parent 21ef152 commit ef2b1f1
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 13 deletions.
28 changes: 15 additions & 13 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1889,12 +1889,13 @@ impl<'a> Resolver<'a> {
}

ident.span = ident.span.modern();
let mut poisoned = None;
loop {
let (opt_module, poisoned) = if let Some(node_id) = record_used_id {
let opt_module = if let Some(node_id) = record_used_id {
self.hygienic_lexical_parent_with_compatibility_fallback(module, &mut ident.span,
node_id)
node_id, &mut poisoned)
} else {
(self.hygienic_lexical_parent(module, &mut ident.span), None)
self.hygienic_lexical_parent(module, &mut ident.span)
};
module = unwrap_or!(opt_module, break);
let orig_current_module = self.current_module;
Expand All @@ -1917,9 +1918,9 @@ impl<'a> Resolver<'a> {
}
return Some(LexicalScopeBinding::Item(binding))
}
_ if poisoned.is_some() => break,
Err(Undetermined) => return None,
Err(Determined) => {}
Err(Determined) => continue,
Err(Undetermined) =>
span_bug!(ident.span, "undetermined resolution during main resolution pass"),
}
}

Expand Down Expand Up @@ -1965,12 +1966,12 @@ impl<'a> Resolver<'a> {
None
}

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

// We need to support the next case under a deprecation warning
Expand All @@ -1991,13 +1992,14 @@ impl<'a> Resolver<'a> {
// The macro is a proc macro derive
if module.expansion.looks_like_proc_macro_derive() {
if parent.expansion.is_descendant_of(span.ctxt().outer()) {
return (module.parent, Some(node_id));
*poisoned = Some(node_id);
return module.parent;
}
}
}
}

(None, None)
None
}

fn resolve_ident_in_module(&mut self,
Expand Down
8 changes: 8 additions & 0 deletions src/test/ui-fulldeps/proc-macro/generate-mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,14 @@ struct S;
//~| WARN this was previously accepted
struct Z;

fn inner_block() {
#[derive(generate_mod::CheckDerive)] //~ WARN cannot find type `FromOutside` in this scope
//~| WARN cannot find type `OuterDerive` in this scope
//~| WARN this was previously accepted
//~| WARN this was previously accepted
struct InnerZ;
}

#[derive(generate_mod::CheckDeriveLint)] // OK, lint is suppressed
struct W;

Expand Down
18 changes: 18 additions & 0 deletions src/test/ui-fulldeps/proc-macro/generate-mod.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,24 @@ LL | #[derive(generate_mod::CheckDerive)] //~ WARN cannot find type `FromOutside
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #50504 <https://github.com/rust-lang/rust/issues/50504>

warning: cannot find type `FromOutside` in this scope
--> $DIR/generate-mod.rs:35:14
|
LL | #[derive(generate_mod::CheckDerive)] //~ WARN cannot find type `FromOutside` in this scope
| ^^^^^^^^^^^^^^^^^^^^^^^^^ names from parent modules are not accessible without an explicit import
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #50504 <https://github.com/rust-lang/rust/issues/50504>

warning: cannot find type `OuterDerive` in this scope
--> $DIR/generate-mod.rs:35:14
|
LL | #[derive(generate_mod::CheckDerive)] //~ WARN cannot find type `FromOutside` in this scope
| ^^^^^^^^^^^^^^^^^^^^^^^^^ names from parent modules are not accessible without an explicit import
|
= warning: this was previously accepted by the compiler but is being phased out; it will become a hard error in a future release!
= note: for more information, see issue #50504 <https://github.com/rust-lang/rust/issues/50504>

error: aborting due to 4 previous errors

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

0 comments on commit ef2b1f1

Please sign in to comment.