Skip to content

Commit c2788a8

Browse files
committed
resolve: Refactor away MacroBinding
`fn resolve_legacy_scope` can now resolve only to `macro_rules!` items, `fn resolve_lexical_macro_path_segment` is for everything else - modularized macros, preludes
1 parent 23e9a1d commit c2788a8

File tree

9 files changed

+160
-116
lines changed

9 files changed

+160
-116
lines changed

src/librustc_resolve/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ use std::mem::replace;
8080
use rustc_data_structures::sync::Lrc;
8181

8282
use resolve_imports::{ImportDirective, ImportDirectiveSubclass, NameResolution, ImportResolver};
83-
use macros::{InvocationData, LegacyBinding, MacroBinding};
83+
use macros::{InvocationData, LegacyBinding};
8484

8585
// NB: This module needs to be declared first so diagnostics are
8686
// registered before they are used.
@@ -3529,7 +3529,7 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
35293529
} else if opt_ns == Some(MacroNS) {
35303530
assert!(ns == TypeNS);
35313531
self.resolve_lexical_macro_path_segment(ident, ns, record_used, record_used,
3532-
false, path_span).map(MacroBinding::binding)
3532+
false, path_span).map(|(b, _)| b)
35333533
} else {
35343534
let record_used_id =
35353535
if record_used { crate_lint.node_id().or(Some(CRATE_NODE_ID)) } else { None };

src/librustc_resolve/macros.rs

+71-105
Large diffs are not rendered by default.

src/test/ui-fulldeps/proc-macro/macro-namespace-reserved-2.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@ LL | MyTrait!(); //~ ERROR can't use a procedural macro from the same crate
1717
| ^^^^^^^
1818

1919
error: can't use a procedural macro from the same crate that defines it
20-
--> $DIR/macro-namespace-reserved-2.rs:44:3
20+
--> $DIR/macro-namespace-reserved-2.rs:43:3
2121
|
2222
LL | #[my_macro] //~ ERROR can't use a procedural macro from the same crate that defines it
2323
| ^^^^^^^^
2424

2525
error: can't use a procedural macro from the same crate that defines it
26-
--> $DIR/macro-namespace-reserved-2.rs:46:3
26+
--> $DIR/macro-namespace-reserved-2.rs:45:3
2727
|
2828
LL | #[my_macro_attr] //~ ERROR can't use a procedural macro from the same crate that defines it
2929
| ^^^^^^^^^^^^^
3030

3131
error: can't use a procedural macro from the same crate that defines it
32-
--> $DIR/macro-namespace-reserved-2.rs:48:3
32+
--> $DIR/macro-namespace-reserved-2.rs:47:3
3333
|
3434
LL | #[MyTrait] //~ ERROR can't use a procedural macro from the same crate that defines it
3535
| ^^^^^^^

src/test/ui/imports/issue-53269.rs

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
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+
// Ambiguity between a `macro_rules` macro and a non-existent import recovered as `Def::Err`
12+
13+
macro_rules! mac { () => () }
14+
15+
mod m {
16+
use nonexistent_module::mac; //~ ERROR unresolved import `nonexistent_module`
17+
18+
mac!(); //~ ERROR `mac` is ambiguous
19+
}
20+
21+
fn main() {}
+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
error[E0432]: unresolved import `nonexistent_module`
2+
--> $DIR/issue-53269.rs:16:9
3+
|
4+
LL | use nonexistent_module::mac; //~ ERROR unresolved import `nonexistent_module`
5+
| ^^^^^^^^^^^^^^^^^^ Maybe a missing `extern crate nonexistent_module;`?
6+
7+
error: `mac` is ambiguous
8+
--> $DIR/issue-53269.rs:18:5
9+
|
10+
LL | mac!(); //~ ERROR `mac` is ambiguous
11+
| ^^^
12+
|
13+
note: `mac` could refer to the macro defined here
14+
--> $DIR/issue-53269.rs:13:1
15+
|
16+
LL | macro_rules! mac { () => () }
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
18+
note: `mac` could also refer to the macro imported here
19+
--> $DIR/issue-53269.rs:16:9
20+
|
21+
LL | use nonexistent_module::mac; //~ ERROR unresolved import `nonexistent_module`
22+
| ^^^^^^^^^^^^^^^^^^^^^^^
23+
24+
error: aborting due to 2 previous errors
25+
26+
For more information about this error, try `rustc --explain E0432`.

src/test/ui/imports/issue-53512.rs

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
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+
// Macro from prelude is shadowed by non-existent import recovered as `Def::Err`.
12+
13+
use std::assert; //~ ERROR unresolved import `std::assert`
14+
15+
fn main() {
16+
assert!(true);
17+
}
+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0432]: unresolved import `std::assert`
2+
--> $DIR/issue-53512.rs:13:5
3+
|
4+
LL | use std::assert; //~ ERROR unresolved import `std::assert`
5+
| ^^^^^^^^^^^ no `assert` in the root
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0432`.

src/test/ui/imports/shadow_builtin_macros.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@ mod m4 {
3737

3838
mod m5 {
3939
macro_rules! m { () => {
40-
macro_rules! panic { () => {} } //~ ERROR `panic` is already in scope
40+
macro_rules! panic { () => {} }
4141
} }
4242
m!();
43-
panic!();
43+
panic!(); //~ ERROR `panic` is ambiguous
4444
}
4545

4646
#[macro_use(n)]

src/test/ui/imports/shadow_builtin_macros.stderr

+9-4
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
1-
error: `panic` is already in scope
1+
error: `panic` is ambiguous
2+
--> $DIR/shadow_builtin_macros.rs:43:5
3+
|
4+
LL | panic!(); //~ ERROR `panic` is ambiguous
5+
| ^^^^^
6+
|
7+
note: `panic` could refer to the macro defined here
28
--> $DIR/shadow_builtin_macros.rs:40:9
39
|
4-
LL | macro_rules! panic { () => {} } //~ ERROR `panic` is already in scope
10+
LL | macro_rules! panic { () => {} }
511
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
612
LL | } }
713
LL | m!();
814
| ----- in this macro invocation
9-
|
10-
= note: macro-expanded `macro_rules!`s may not shadow existing macros (see RFC 1560)
15+
note: `panic` could also refer to the macro imported here
1116

1217
error[E0659]: `panic` is ambiguous
1318
--> $DIR/shadow_builtin_macros.rs:25:14

0 commit comments

Comments
 (0)