Skip to content

Commit b4804a0

Browse files
committed
#[rustc_transparent_macro] -> #[rustc_macro_transparency = ...]
1 parent 6fc4fe4 commit b4804a0

9 files changed

+83
-25
lines changed

src/libsyntax/ext/tt/macro_rules.rs

+11-7
Original file line numberDiff line numberDiff line change
@@ -380,13 +380,17 @@ pub fn compile(
380380
let expander: Box<_> =
381381
Box::new(MacroRulesMacroExpander { name: def.ident, lhses, rhses, valid });
382382

383-
let default_transparency = if attr::contains_name(&def.attrs, sym::rustc_transparent_macro) {
384-
Transparency::Transparent
385-
} else if body.legacy {
386-
Transparency::SemiTransparent
387-
} else {
388-
Transparency::Opaque
389-
};
383+
let value_str = attr::first_attr_value_str_by_name(&def.attrs, sym::rustc_macro_transparency);
384+
let default_transparency = value_str.and_then(|s| Some(match &*s.as_str() {
385+
"transparent" => Transparency::Transparent,
386+
"semitransparent" => Transparency::SemiTransparent,
387+
"opaque" => Transparency::Opaque,
388+
_ => {
389+
let msg = format!("unknown macro transparency: `{}`", s);
390+
sess.span_diagnostic.span_err(def.span, &msg);
391+
return None;
392+
}
393+
})).unwrap_or(if body.legacy { Transparency::SemiTransparent } else { Transparency::Opaque });
390394

391395
let allow_internal_unstable =
392396
attr::find_by_name(&def.attrs, sym::allow_internal_unstable).map(|attr| {

src/libsyntax/feature_gate.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -1313,7 +1313,9 @@ pub const BUILTIN_ATTRIBUTES: &[BuiltinAttribute] = &[
13131313
"the `#[rustc_test_marker]` attribute \
13141314
is used internally to track tests",
13151315
cfg_fn!(rustc_attrs))),
1316-
(sym::rustc_transparent_macro, Whitelisted, template!(Word), Gated(Stability::Unstable,
1316+
(sym::rustc_macro_transparency, Whitelisted, template!(NameValueStr:
1317+
"transparent|semitransparent|opaque"),
1318+
Gated(Stability::Unstable,
13171319
sym::rustc_attrs,
13181320
"used internally for testing macro hygiene",
13191321
cfg_fn!(rustc_attrs))),

src/libsyntax_pos/symbol.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,7 @@ symbols! {
557557
rustc_layout,
558558
rustc_layout_scalar_valid_range_end,
559559
rustc_layout_scalar_valid_range_start,
560+
rustc_macro_transparency,
560561
rustc_mir,
561562
rustc_nonnull_optimization_guaranteed,
562563
rustc_object_lifetime_default,
@@ -579,7 +580,6 @@ symbols! {
579580
rustc_synthetic,
580581
rustc_test_marker,
581582
rustc_then_this_would_need,
582-
rustc_transparent_macro,
583583
rustc_variance,
584584
rustdoc,
585585
rust_eh_personality,
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![feature(decl_macro, rustc_attrs)]
22

3-
#[rustc_transparent_macro]
3+
#[rustc_macro_transparency = "transparent"]
44
pub macro dollar_crate() {
55
let s = $crate::S;
66
}

src/test/ui/hygiene/generate-mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ macro genmod($FromOutside: ident, $Outer: ident) {
1111
}
1212
}
1313

14-
#[rustc_transparent_macro]
14+
#[rustc_macro_transparency = "transparent"]
1515
macro genmod_transparent() {
1616
type A = FromOutside;
1717
struct Outer;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#![feature(decl_macro, rustc_attrs)]
2+
3+
#[rustc_macro_transparency = "transparent"]
4+
macro transparent() {
5+
struct Transparent;
6+
let transparent = 0;
7+
}
8+
#[rustc_macro_transparency = "semitransparent"]
9+
macro semitransparent() {
10+
struct SemiTransparent;
11+
let semitransparent = 0;
12+
}
13+
#[rustc_macro_transparency = "opaque"]
14+
macro opaque() {
15+
struct Opaque;
16+
let opaque = 0;
17+
}
18+
19+
fn main() {
20+
transparent!();
21+
semitransparent!();
22+
opaque!();
23+
24+
Transparent; // OK
25+
SemiTransparent; // OK
26+
Opaque; //~ ERROR cannot find value `Opaque` in this scope
27+
28+
transparent; // OK
29+
semitransparent; //~ ERROR cannot find value `semitransparent` in this scope
30+
opaque; //~ ERROR cannot find value `opaque` in this scope
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error[E0425]: cannot find value `Opaque` in this scope
2+
--> $DIR/rustc-macro-transparency.rs:26:5
3+
|
4+
LL | Opaque;
5+
| ^^^^^^ help: a local variable with a similar name exists: `opaque`
6+
7+
error[E0425]: cannot find value `semitransparent` in this scope
8+
--> $DIR/rustc-macro-transparency.rs:29:5
9+
|
10+
LL | semitransparent;
11+
| ^^^^^^^^^^^^^^^ not found in this scope
12+
13+
error[E0425]: cannot find value `opaque` in this scope
14+
--> $DIR/rustc-macro-transparency.rs:30:5
15+
|
16+
LL | opaque;
17+
| ^^^^^^ not found in this scope
18+
19+
error: aborting due to 3 previous errors
20+
21+
For more information about this error, try `rustc --explain E0425`.

src/test/ui/hygiene/transparent-basic.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55

66
extern crate transparent_basic;
77

8-
#[rustc_transparent_macro]
8+
#[rustc_macro_transparency = "transparent"]
99
macro binding() {
1010
let x = 10;
1111
}
1212

13-
#[rustc_transparent_macro]
13+
#[rustc_macro_transparency = "transparent"]
1414
macro label() {
1515
break 'label
1616
}

src/test/ui/macros/restricted-shadowing-modern.rs

+12-12
Original file line numberDiff line numberDiff line change
@@ -80,17 +80,17 @@
8080
struct Right;
8181
// struct Wrong; // not defined
8282

83-
#[rustc_transparent_macro]
83+
#[rustc_macro_transparency = "transparent"]
8484
macro include() {
85-
#[rustc_transparent_macro]
85+
#[rustc_macro_transparency = "transparent"]
8686
macro gen_outer() {
8787
macro m() { Wrong }
8888
}
89-
#[rustc_transparent_macro]
89+
#[rustc_macro_transparency = "transparent"]
9090
macro gen_inner() {
9191
macro m() { Right }
9292
}
93-
#[rustc_transparent_macro]
93+
#[rustc_macro_transparency = "transparent"]
9494
macro gen_invoc() {
9595
m!()
9696
}
@@ -100,7 +100,7 @@ macro include() {
100100
fn check1() {
101101
macro m() {}
102102
{
103-
#[rustc_transparent_macro]
103+
#[rustc_macro_transparency = "transparent"]
104104
macro gen_gen_inner_invoc() {
105105
gen_inner!();
106106
m!(); //~ ERROR `m` is ambiguous
@@ -112,7 +112,7 @@ macro include() {
112112
fn check5() {
113113
macro m() { Wrong }
114114
{
115-
#[rustc_transparent_macro]
115+
#[rustc_macro_transparency = "transparent"]
116116
macro gen_inner_invoc() {
117117
macro m() { Right }
118118
m!(); // OK
@@ -124,7 +124,7 @@ macro include() {
124124
fn check9() {
125125
macro m() { Wrong }
126126
{
127-
#[rustc_transparent_macro]
127+
#[rustc_macro_transparency = "transparent"]
128128
macro gen_inner_gen_invoc() {
129129
macro m() { Right }
130130
gen_invoc!(); // OK
@@ -145,7 +145,7 @@ macro include() {
145145
macro m() {}
146146
{
147147
gen_inner!();
148-
#[rustc_transparent_macro]
148+
#[rustc_macro_transparency = "transparent"]
149149
macro gen_invoc() { m!() } //~ ERROR `m` is ambiguous
150150
gen_invoc!();
151151
}
@@ -186,7 +186,7 @@ macro include() {
186186
fn check52() {
187187
gen_outer!();
188188
{
189-
#[rustc_transparent_macro]
189+
#[rustc_macro_transparency = "transparent"]
190190
macro gen_gen_inner_invoc() {
191191
gen_inner!();
192192
m!(); //~ ERROR `m` is ambiguous
@@ -198,7 +198,7 @@ macro include() {
198198
fn check56() {
199199
gen_outer!();
200200
{
201-
#[rustc_transparent_macro]
201+
#[rustc_macro_transparency = "transparent"]
202202
macro gen_inner_invoc() {
203203
macro m() { Right }
204204
m!(); // OK
@@ -218,7 +218,7 @@ macro include() {
218218
fn check60() {
219219
gen_outer!();
220220
{
221-
#[rustc_transparent_macro]
221+
#[rustc_macro_transparency = "transparent"]
222222
macro gen_inner_gen_invoc() {
223223
macro m() { Right }
224224
gen_invoc!(); // OK
@@ -231,7 +231,7 @@ macro include() {
231231
gen_outer!();
232232
{
233233
gen_inner!();
234-
#[rustc_transparent_macro]
234+
#[rustc_macro_transparency = "transparent"]
235235
macro gen_invoc() { m!() } //~ ERROR `m` is ambiguous
236236
gen_invoc!();
237237
}

0 commit comments

Comments
 (0)