提交 71a1ef18 编写于 作者: B bors

Auto merge of #53516 - petrochenkov:derregr, r=estebank

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

Fixes https://github.com/rust-lang/rust/issues/53263
......@@ -1901,12 +1901,13 @@ fn resolve_ident_in_lexical_scope(&mut self,
}
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;
......@@ -1934,7 +1935,6 @@ fn resolve_ident_in_lexical_scope(&mut self,
}
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"),
......@@ -1994,12 +1994,12 @@ fn hygienic_lexical_parent(&mut self, module: Module<'a>, span: &mut Span)
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
......@@ -2020,13 +2020,14 @@ fn hygienic_lexical_parent_with_compatibility_fallback(
// 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,
......
......@@ -31,6 +31,14 @@
//~| 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;
......
......@@ -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`.
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册