Skip to content

Commit c9c79b7

Browse files
committed
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
1 parent 1cbf339 commit c9c79b7

File tree

3 files changed

+56
-1
lines changed

3 files changed

+56
-1
lines changed

src/librustc_resolve/macros.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -611,6 +611,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
611611
);
612612
self.current_module = orig_current_module;
613613
binding.map(|binding| (binding, FromPrelude(false)))
614+
.map_err(|d| Determinacy::determined(d == Determinacy::Determined || force))
614615
}
615616
WhereToResolve::MacroPrelude => {
616617
match self.macro_prelude.get(&ident.name).cloned() {
@@ -756,7 +757,7 @@ impl<'a, 'cl> Resolver<'a, 'cl> {
756757
Err(Determinacy::Determined) => {
757758
continue_search!();
758759
}
759-
Err(Determinacy::Undetermined) => return Err(Determinacy::determined(force)),
760+
Err(Determinacy::Undetermined) => return Err(Determinacy::Undetermined),
760761
}
761762
}
762763

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// no-prefer-dynamic
12+
13+
#![crate_type = "proc-macro"]
14+
15+
extern crate proc_macro;
16+
17+
use proc_macro::*;
18+
19+
#[proc_macro_derive(MyTrait, attributes(my_attr))]
20+
pub fn foo(_: TokenStream) -> TokenStream {
21+
TokenStream::new()
22+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2018 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
// compile-pass
12+
// aux-build:issue-53481.rs
13+
14+
#[macro_use]
15+
extern crate issue_53481;
16+
17+
mod m1 {
18+
use m2::MyTrait;
19+
20+
#[derive(MyTrait)]
21+
struct A {}
22+
}
23+
24+
mod m2 {
25+
pub type MyTrait = u8;
26+
27+
#[derive(MyTrait)]
28+
#[my_attr]
29+
struct B {}
30+
}
31+
32+
fn main() {}

0 commit comments

Comments
 (0)