Skip to content

Commit 791ceb6

Browse files
authored
Rollup merge of rust-lang#62651 - matthewjasper:rustc-macro-hygiene, r=petrochenkov
Make some rustc macros more hygienic
2 parents bafddd4 + 199931c commit 791ceb6

File tree

14 files changed

+31
-40
lines changed

14 files changed

+31
-40
lines changed

src/librustc/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,13 @@
4949
#![feature(optin_builtin_traits)]
5050
#![feature(range_is_empty)]
5151
#![feature(rustc_diagnostic_macros)]
52-
#![feature(rustc_attrs)]
5352
#![feature(slice_patterns)]
5453
#![feature(specialization)]
5554
#![feature(unboxed_closures)]
5655
#![feature(thread_local)]
5756
#![feature(trace_macros)]
5857
#![feature(trusted_len)]
5958
#![feature(vec_remove_item)]
60-
#![feature(step_trait)]
6159
#![feature(stmt_expr_attributes)]
6260
#![feature(integer_atomics)]
6361
#![feature(test)]

src/librustc_data_structures/indexed_vec.rs

+17-16
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,13 @@ impl Idx for u32 {
5757
/// `u32::MAX`. You can also customize things like the `Debug` impl,
5858
/// what traits are derived, and so forth via the macro.
5959
#[macro_export]
60+
#[allow_internal_unstable(step_trait, rustc_attrs)]
6061
macro_rules! newtype_index {
6162
// ---- public rules ----
6263

6364
// Use default constants
6465
($(#[$attrs:meta])* $v:vis struct $name:ident { .. }) => (
65-
newtype_index!(
66+
$crate::newtype_index!(
6667
// Leave out derives marker so we can use its absence to ensure it comes first
6768
@attrs [$(#[$attrs])*]
6869
@type [$name]
@@ -74,7 +75,7 @@ macro_rules! newtype_index {
7475

7576
// Define any constants
7677
($(#[$attrs:meta])* $v:vis struct $name:ident { $($tokens:tt)+ }) => (
77-
newtype_index!(
78+
$crate::newtype_index!(
7879
// Leave out derives marker so we can use its absence to ensure it comes first
7980
@attrs [$(#[$attrs])*]
8081
@type [$name]
@@ -258,7 +259,7 @@ macro_rules! newtype_index {
258259
}
259260
}
260261

261-
newtype_index!(
262+
$crate::newtype_index!(
262263
@handle_debug
263264
@derives [$($derives,)*]
264265
@type [$type]
@@ -294,7 +295,7 @@ macro_rules! newtype_index {
294295
@derives [$_derive:ident, $($derives:ident,)*]
295296
@type [$type:ident]
296297
@debug_format [$debug_format:tt]) => (
297-
newtype_index!(
298+
$crate::newtype_index!(
298299
@handle_debug
299300
@derives [$($derives,)*]
300301
@type [$type]
@@ -309,7 +310,7 @@ macro_rules! newtype_index {
309310
@debug_format [$debug_format:tt]
310311
derive [$($derives:ident),*]
311312
$($tokens:tt)*) => (
312-
newtype_index!(
313+
$crate::newtype_index!(
313314
@attrs [$(#[$attrs])*]
314315
@type [$type]
315316
@max [$max]
@@ -329,7 +330,7 @@ macro_rules! newtype_index {
329330
derive [$($derives:ident,)+]
330331
ENCODABLE = custom
331332
$($tokens:tt)*) => (
332-
newtype_index!(
333+
$crate::newtype_index!(
333334
@attrs [$(#[$attrs])*]
334335
@derives [$($derives,)+]
335336
@type [$type]
@@ -348,15 +349,15 @@ macro_rules! newtype_index {
348349
@debug_format [$debug_format:tt]
349350
derive [$($derives:ident,)+]
350351
$($tokens:tt)*) => (
351-
newtype_index!(
352+
$crate::newtype_index!(
352353
@derives [$($derives,)+ RustcEncodable,]
353354
@attrs [$(#[$attrs])*]
354355
@type [$type]
355356
@max [$max]
356357
@vis [$v]
357358
@debug_format [$debug_format]
358359
$($tokens)*);
359-
newtype_index!(@decodable $type);
360+
$crate::newtype_index!(@decodable $type);
360361
);
361362

362363
// The case where no derives are added, but encodable is overridden. Don't
@@ -368,7 +369,7 @@ macro_rules! newtype_index {
368369
@debug_format [$debug_format:tt]
369370
ENCODABLE = custom
370371
$($tokens:tt)*) => (
371-
newtype_index!(
372+
$crate::newtype_index!(
372373
@derives []
373374
@attrs [$(#[$attrs])*]
374375
@type [$type]
@@ -385,15 +386,15 @@ macro_rules! newtype_index {
385386
@vis [$v:vis]
386387
@debug_format [$debug_format:tt]
387388
$($tokens:tt)*) => (
388-
newtype_index!(
389+
$crate::newtype_index!(
389390
@derives [RustcEncodable,]
390391
@attrs [$(#[$attrs])*]
391392
@type [$type]
392393
@max [$max]
393394
@vis [$v]
394395
@debug_format [$debug_format]
395396
$($tokens)*);
396-
newtype_index!(@decodable $type);
397+
$crate::newtype_index!(@decodable $type);
397398
);
398399

399400
(@decodable $type:ident) => (
@@ -420,7 +421,7 @@ macro_rules! newtype_index {
420421
@vis [$v:vis]
421422
@debug_format [$debug_format:tt]
422423
$name:ident = $constant:expr) => (
423-
newtype_index!(
424+
$crate::newtype_index!(
424425
@derives [$($derives,)*]
425426
@attrs [$(#[$attrs])*]
426427
@type [$type]
@@ -439,7 +440,7 @@ macro_rules! newtype_index {
439440
@debug_format [$debug_format:tt]
440441
$(#[doc = $doc:expr])*
441442
const $name:ident = $constant:expr) => (
442-
newtype_index!(
443+
$crate::newtype_index!(
443444
@derives [$($derives,)*]
444445
@attrs [$(#[$attrs])*]
445446
@type [$type]
@@ -458,7 +459,7 @@ macro_rules! newtype_index {
458459
@debug_format [$debug_format:tt]
459460
MAX = $max:expr,
460461
$($tokens:tt)*) => (
461-
newtype_index!(
462+
$crate::newtype_index!(
462463
@derives [$($derives,)*]
463464
@attrs [$(#[$attrs])*]
464465
@type [$type]
@@ -477,7 +478,7 @@ macro_rules! newtype_index {
477478
@debug_format [$_debug_format:tt]
478479
DEBUG_FORMAT = $debug_format:tt,
479480
$($tokens:tt)*) => (
480-
newtype_index!(
481+
$crate::newtype_index!(
481482
@derives [$($derives,)*]
482483
@attrs [$(#[$attrs])*]
483484
@type [$type]
@@ -499,7 +500,7 @@ macro_rules! newtype_index {
499500
$($tokens:tt)*) => (
500501
$(#[doc = $doc])*
501502
pub const $name: $type = $type::from_u32_const($constant);
502-
newtype_index!(
503+
$crate::newtype_index!(
503504
@derives [$($derives,)*]
504505
@attrs [$(#[$attrs])*]
505506
@type [$type]

src/librustc_lint/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use syntax::{register_diagnostic, register_diagnostics};
1+
use syntax::register_diagnostics;
22

33
register_diagnostics! {
44
E0721, // `await` keyword

src/librustc_metadata/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![allow(non_snake_case)]
22

3-
use syntax::{register_diagnostic, register_diagnostics, register_long_diagnostics};
3+
use syntax::{register_diagnostics, register_long_diagnostics};
44

55
register_long_diagnostics! {
66
E0454: r##"

src/librustc_mir/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,10 @@ Rust MIR: a lowered representation of Rust. Also: an experiment!
1515
#![feature(decl_macro)]
1616
#![feature(exhaustive_patterns)]
1717
#![feature(rustc_diagnostic_macros)]
18-
#![feature(rustc_attrs)]
1918
#![feature(never_type)]
2019
#![feature(specialization)]
2120
#![feature(try_trait)]
2221
#![feature(unicode_internals)]
23-
#![feature(step_trait)]
2422
#![feature(slice_concat_ext)]
2523
#![feature(trusted_len)]
2624
#![feature(try_blocks)]

src/librustc_passes/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![allow(non_snake_case)]
22

3-
use syntax::{register_diagnostic, register_diagnostics, register_long_diagnostics};
3+
use syntax::{register_diagnostics, register_long_diagnostics};
44

55
register_long_diagnostics! {
66
/*

src/librustc_plugin/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![allow(non_snake_case)]
22

3-
use syntax::{register_diagnostic, register_diagnostics, register_long_diagnostics};
3+
use syntax::{register_diagnostics, register_long_diagnostics};
44

55
register_long_diagnostics! {
66

src/librustc_resolve/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![allow(non_snake_case)]
22

3-
use syntax::{register_diagnostic, register_diagnostics, register_long_diagnostics};
3+
use syntax::{register_diagnostics, register_long_diagnostics};
44

55
// Error messages for EXXXX errors. Each message should start and end with a
66
// new line, and be wrapped to 80 characters. In vim you can `:set tw=80` and

src/librustc_target/abi/mod.rs

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ use crate::spec::Target;
66
use std::fmt;
77
use std::ops::{Add, Deref, Sub, Mul, AddAssign, Range, RangeInclusive};
88

9+
use rustc_data_structures::newtype_index;
910
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
1011
use syntax_pos::symbol::{sym, Symbol};
1112

src/librustc_target/lib.rs

-5
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@
1111

1212
#![feature(box_syntax)]
1313
#![feature(nll)]
14-
#![feature(rustc_attrs)]
1514
#![feature(slice_patterns)]
16-
#![feature(step_trait)]
1715

1816
#![deny(rust_2018_idioms)]
1917
#![deny(unused_lifetimes)]
@@ -23,8 +21,5 @@
2321
#[allow(unused_extern_crates)]
2422
extern crate serialize as rustc_serialize; // used by deriving
2523

26-
#[macro_use]
27-
extern crate rustc_data_structures;
28-
2924
pub mod abi;
3025
pub mod spec;

src/libsyntax/diagnostics/macros.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -170,19 +170,19 @@ macro_rules! help {
170170
#[macro_export]
171171
macro_rules! register_diagnostics {
172172
($($code:tt),*) => (
173-
$(register_diagnostic! { $code })*
173+
$($crate::register_diagnostic! { $code })*
174174
);
175175
($($code:tt),*,) => (
176-
$(register_diagnostic! { $code })*
176+
$($crate::register_diagnostic! { $code })*
177177
)
178178
}
179179

180180
#[macro_export]
181181
macro_rules! register_long_diagnostics {
182182
($($code:tt: $description:tt),*) => (
183-
$(register_diagnostic! { $code, $description })*
183+
$($crate::register_diagnostic! { $code, $description })*
184184
);
185185
($($code:tt: $description:tt),*,) => (
186-
$(register_diagnostic! { $code, $description })*
186+
$($crate::register_diagnostic! { $code, $description })*
187187
)
188188
}

src/libsyntax/lib.rs

-2
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
#![feature(label_break_value)]
1919
#![feature(mem_take)]
2020
#![feature(nll)]
21-
#![feature(rustc_attrs)]
2221
#![feature(rustc_diagnostic_macros)]
23-
#![feature(step_trait)]
2422
#![feature(try_trait)]
2523
#![feature(unicode_internals)]
2624

src/libsyntax_ext/error_codes.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![allow(non_snake_case)]
22

3-
use syntax::{register_diagnostic, register_long_diagnostics};
3+
use syntax::register_long_diagnostics;
44

55
// Error messages for EXXXX errors.
66
// Each message should start and end with a new line, and be wrapped to 80 characters.

src/test/run-pass-fulldeps/newtype_index.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
#![feature(rustc_attrs, rustc_private, step_trait)]
1+
#![feature(rustc_private)]
22

3-
#[macro_use] extern crate rustc_data_structures;
3+
extern crate rustc_data_structures;
44
extern crate serialize as rustc_serialize;
55

6-
use rustc_data_structures::indexed_vec::Idx;
6+
use rustc_data_structures::{newtype_index, indexed_vec::Idx};
77

88
newtype_index!(struct MyIdx { MAX = 0xFFFF_FFFA });
99

0 commit comments

Comments
 (0)