Skip to content

resolve: Continue search in outer scopes after applying derive resolution fallback #53516

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 22, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 12 additions & 11 deletions src/librustc_resolve/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1900,12 +1900,13 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
}

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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find mutable arguments to be a bit stylistically unappealing, in Rust in particular. You could do something like the following:

if let ... {
    let (module, poisoned_opt) = self.hygienic_lexical_parent_with_compatibility_fallback(...);
    poisoned = poisoned_opt;
    module
} else {

although I'm not seeing it as much of an improvement...

} 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 Down Expand Up @@ -1933,7 +1934,6 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
}
return Some(LexicalScopeBinding::Item(binding))
}
_ if poisoned.is_some() => break,
Err(Determined) => continue,
Err(Undetermined) =>
span_bug!(ident.span, "undetermined resolution during main resolution pass"),
Expand Down Expand Up @@ -1993,12 +1993,12 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
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 @@ -2019,13 +2019,14 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
// 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`.