From c9c79b704ad75963fa2aa2ff528e5b31a9629470 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Wed, 22 Aug 2018 05:13:16 +0300 Subject: [PATCH] resolve: Recover from indeterminate macro resolutions more agressively If we are in "forced resolution" mode and in-module resolution is indeterminate, don't give up and continue searching in outer scopes --- src/librustc_resolve/macros.rs | 3 +- .../proc-macro/auxiliary/issue-53481.rs | 22 +++++++++++++ .../ui-fulldeps/proc-macro/issue-53481.rs | 32 +++++++++++++++++++ 3 files changed, 56 insertions(+), 1 deletion(-) create mode 100644 src/test/ui-fulldeps/proc-macro/auxiliary/issue-53481.rs create mode 100644 src/test/ui-fulldeps/proc-macro/issue-53481.rs diff --git a/src/librustc_resolve/macros.rs b/src/librustc_resolve/macros.rs index 1161d57417b18..97a83f5be0d60 100644 --- a/src/librustc_resolve/macros.rs +++ b/src/librustc_resolve/macros.rs @@ -611,6 +611,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> { ); self.current_module = orig_current_module; binding.map(|binding| (binding, FromPrelude(false))) + .map_err(|d| Determinacy::determined(d == Determinacy::Determined || force)) } WhereToResolve::MacroPrelude => { match self.macro_prelude.get(&ident.name).cloned() { @@ -756,7 +757,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> { Err(Determinacy::Determined) => { continue_search!(); } - Err(Determinacy::Undetermined) => return Err(Determinacy::determined(force)), + Err(Determinacy::Undetermined) => return Err(Determinacy::Undetermined), } } diff --git a/src/test/ui-fulldeps/proc-macro/auxiliary/issue-53481.rs b/src/test/ui-fulldeps/proc-macro/auxiliary/issue-53481.rs new file mode 100644 index 0000000000000..6bb80ae27d04b --- /dev/null +++ b/src/test/ui-fulldeps/proc-macro/auxiliary/issue-53481.rs @@ -0,0 +1,22 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// no-prefer-dynamic + +#![crate_type = "proc-macro"] + +extern crate proc_macro; + +use proc_macro::*; + +#[proc_macro_derive(MyTrait, attributes(my_attr))] +pub fn foo(_: TokenStream) -> TokenStream { + TokenStream::new() +} diff --git a/src/test/ui-fulldeps/proc-macro/issue-53481.rs b/src/test/ui-fulldeps/proc-macro/issue-53481.rs new file mode 100644 index 0000000000000..c6ac0623934bc --- /dev/null +++ b/src/test/ui-fulldeps/proc-macro/issue-53481.rs @@ -0,0 +1,32 @@ +// Copyright 2018 The Rust Project Developers. See the COPYRIGHT +// file at the top-level directory of this distribution and at +// http://rust-lang.org/COPYRIGHT. +// +// Licensed under the Apache License, Version 2.0 or the MIT license +// , at your +// option. This file may not be copied, modified, or distributed +// except according to those terms. + +// compile-pass +// aux-build:issue-53481.rs + +#[macro_use] +extern crate issue_53481; + +mod m1 { + use m2::MyTrait; + + #[derive(MyTrait)] + struct A {} +} + +mod m2 { + pub type MyTrait = u8; + + #[derive(MyTrait)] + #[my_attr] + struct B {} +} + +fn main() {}