From 56f635304b7a2689cfe5e98577428d67f059b413 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Sat, 7 Sep 2019 17:33:50 +0300 Subject: [PATCH] resolve: Adjust `hygienic_lexical_parent` to account for enum and trait modules --- src/librustc_resolve/lib.rs | 2 +- src/test/ui/resolve/block-with-trait-parent.rs | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 src/test/ui/resolve/block-with-trait-parent.rs diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 29676f96ce7a8..efb64c9341f13 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -1644,7 +1644,7 @@ impl<'a> Resolver<'a> { } if let ModuleKind::Block(..) = module.kind { - return Some(module.parent.unwrap()); + return Some(module.parent.unwrap().nearest_item_scope()); } None diff --git a/src/test/ui/resolve/block-with-trait-parent.rs b/src/test/ui/resolve/block-with-trait-parent.rs new file mode 100644 index 0000000000000..bc86f94e921cb --- /dev/null +++ b/src/test/ui/resolve/block-with-trait-parent.rs @@ -0,0 +1,14 @@ +// check-pass + +trait Trait { + fn method(&self) { + // Items inside a block turn it into a module internally. + struct S; + impl Trait for S {} + + // OK, `Trait` is in scope here from method resolution point of view. + S.method(); + } +} + +fn main() {}