Rollup merge of #62651 - matthewjasper:rustc-macro-hygiene, r=petrochenkov
Make some rustc macros more hygienic
This commit is contained in:
commit
791ceb6a9c
14 changed files with 31 additions and 40 deletions
|
|
@ -49,7 +49,6 @@
|
|||
#![feature(optin_builtin_traits)]
|
||||
#![feature(range_is_empty)]
|
||||
#![feature(rustc_diagnostic_macros)]
|
||||
#![feature(rustc_attrs)]
|
||||
#![feature(slice_patterns)]
|
||||
#![feature(specialization)]
|
||||
#![feature(unboxed_closures)]
|
||||
|
|
@ -57,7 +56,6 @@
|
|||
#![feature(trace_macros)]
|
||||
#![feature(trusted_len)]
|
||||
#![feature(vec_remove_item)]
|
||||
#![feature(step_trait)]
|
||||
#![feature(stmt_expr_attributes)]
|
||||
#![feature(integer_atomics)]
|
||||
#![feature(test)]
|
||||
|
|
|
|||
|
|
@ -57,12 +57,13 @@ impl Idx for u32 {
|
|||
/// `u32::MAX`. You can also customize things like the `Debug` impl,
|
||||
/// what traits are derived, and so forth via the macro.
|
||||
#[macro_export]
|
||||
#[allow_internal_unstable(step_trait, rustc_attrs)]
|
||||
macro_rules! newtype_index {
|
||||
// ---- public rules ----
|
||||
|
||||
// Use default constants
|
||||
($(#[$attrs:meta])* $v:vis struct $name:ident { .. }) => (
|
||||
newtype_index!(
|
||||
$crate::newtype_index!(
|
||||
// Leave out derives marker so we can use its absence to ensure it comes first
|
||||
@attrs [$(#[$attrs])*]
|
||||
@type [$name]
|
||||
|
|
@ -74,7 +75,7 @@ macro_rules! newtype_index {
|
|||
|
||||
// Define any constants
|
||||
($(#[$attrs:meta])* $v:vis struct $name:ident { $($tokens:tt)+ }) => (
|
||||
newtype_index!(
|
||||
$crate::newtype_index!(
|
||||
// Leave out derives marker so we can use its absence to ensure it comes first
|
||||
@attrs [$(#[$attrs])*]
|
||||
@type [$name]
|
||||
|
|
@ -258,7 +259,7 @@ macro_rules! newtype_index {
|
|||
}
|
||||
}
|
||||
|
||||
newtype_index!(
|
||||
$crate::newtype_index!(
|
||||
@handle_debug
|
||||
@derives [$($derives,)*]
|
||||
@type [$type]
|
||||
|
|
@ -294,7 +295,7 @@ macro_rules! newtype_index {
|
|||
@derives [$_derive:ident, $($derives:ident,)*]
|
||||
@type [$type:ident]
|
||||
@debug_format [$debug_format:tt]) => (
|
||||
newtype_index!(
|
||||
$crate::newtype_index!(
|
||||
@handle_debug
|
||||
@derives [$($derives,)*]
|
||||
@type [$type]
|
||||
|
|
@ -309,7 +310,7 @@ macro_rules! newtype_index {
|
|||
@debug_format [$debug_format:tt]
|
||||
derive [$($derives:ident),*]
|
||||
$($tokens:tt)*) => (
|
||||
newtype_index!(
|
||||
$crate::newtype_index!(
|
||||
@attrs [$(#[$attrs])*]
|
||||
@type [$type]
|
||||
@max [$max]
|
||||
|
|
@ -329,7 +330,7 @@ macro_rules! newtype_index {
|
|||
derive [$($derives:ident,)+]
|
||||
ENCODABLE = custom
|
||||
$($tokens:tt)*) => (
|
||||
newtype_index!(
|
||||
$crate::newtype_index!(
|
||||
@attrs [$(#[$attrs])*]
|
||||
@derives [$($derives,)+]
|
||||
@type [$type]
|
||||
|
|
@ -348,7 +349,7 @@ macro_rules! newtype_index {
|
|||
@debug_format [$debug_format:tt]
|
||||
derive [$($derives:ident,)+]
|
||||
$($tokens:tt)*) => (
|
||||
newtype_index!(
|
||||
$crate::newtype_index!(
|
||||
@derives [$($derives,)+ RustcEncodable,]
|
||||
@attrs [$(#[$attrs])*]
|
||||
@type [$type]
|
||||
|
|
@ -356,7 +357,7 @@ macro_rules! newtype_index {
|
|||
@vis [$v]
|
||||
@debug_format [$debug_format]
|
||||
$($tokens)*);
|
||||
newtype_index!(@decodable $type);
|
||||
$crate::newtype_index!(@decodable $type);
|
||||
);
|
||||
|
||||
// The case where no derives are added, but encodable is overridden. Don't
|
||||
|
|
@ -368,7 +369,7 @@ macro_rules! newtype_index {
|
|||
@debug_format [$debug_format:tt]
|
||||
ENCODABLE = custom
|
||||
$($tokens:tt)*) => (
|
||||
newtype_index!(
|
||||
$crate::newtype_index!(
|
||||
@derives []
|
||||
@attrs [$(#[$attrs])*]
|
||||
@type [$type]
|
||||
|
|
@ -385,7 +386,7 @@ macro_rules! newtype_index {
|
|||
@vis [$v:vis]
|
||||
@debug_format [$debug_format:tt]
|
||||
$($tokens:tt)*) => (
|
||||
newtype_index!(
|
||||
$crate::newtype_index!(
|
||||
@derives [RustcEncodable,]
|
||||
@attrs [$(#[$attrs])*]
|
||||
@type [$type]
|
||||
|
|
@ -393,7 +394,7 @@ macro_rules! newtype_index {
|
|||
@vis [$v]
|
||||
@debug_format [$debug_format]
|
||||
$($tokens)*);
|
||||
newtype_index!(@decodable $type);
|
||||
$crate::newtype_index!(@decodable $type);
|
||||
);
|
||||
|
||||
(@decodable $type:ident) => (
|
||||
|
|
@ -420,7 +421,7 @@ macro_rules! newtype_index {
|
|||
@vis [$v:vis]
|
||||
@debug_format [$debug_format:tt]
|
||||
$name:ident = $constant:expr) => (
|
||||
newtype_index!(
|
||||
$crate::newtype_index!(
|
||||
@derives [$($derives,)*]
|
||||
@attrs [$(#[$attrs])*]
|
||||
@type [$type]
|
||||
|
|
@ -439,7 +440,7 @@ macro_rules! newtype_index {
|
|||
@debug_format [$debug_format:tt]
|
||||
$(#[doc = $doc:expr])*
|
||||
const $name:ident = $constant:expr) => (
|
||||
newtype_index!(
|
||||
$crate::newtype_index!(
|
||||
@derives [$($derives,)*]
|
||||
@attrs [$(#[$attrs])*]
|
||||
@type [$type]
|
||||
|
|
@ -458,7 +459,7 @@ macro_rules! newtype_index {
|
|||
@debug_format [$debug_format:tt]
|
||||
MAX = $max:expr,
|
||||
$($tokens:tt)*) => (
|
||||
newtype_index!(
|
||||
$crate::newtype_index!(
|
||||
@derives [$($derives,)*]
|
||||
@attrs [$(#[$attrs])*]
|
||||
@type [$type]
|
||||
|
|
@ -477,7 +478,7 @@ macro_rules! newtype_index {
|
|||
@debug_format [$_debug_format:tt]
|
||||
DEBUG_FORMAT = $debug_format:tt,
|
||||
$($tokens:tt)*) => (
|
||||
newtype_index!(
|
||||
$crate::newtype_index!(
|
||||
@derives [$($derives,)*]
|
||||
@attrs [$(#[$attrs])*]
|
||||
@type [$type]
|
||||
|
|
@ -499,7 +500,7 @@ macro_rules! newtype_index {
|
|||
$($tokens:tt)*) => (
|
||||
$(#[doc = $doc])*
|
||||
pub const $name: $type = $type::from_u32_const($constant);
|
||||
newtype_index!(
|
||||
$crate::newtype_index!(
|
||||
@derives [$($derives,)*]
|
||||
@attrs [$(#[$attrs])*]
|
||||
@type [$type]
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use syntax::{register_diagnostic, register_diagnostics};
|
||||
use syntax::register_diagnostics;
|
||||
|
||||
register_diagnostics! {
|
||||
E0721, // `await` keyword
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#![allow(non_snake_case)]
|
||||
|
||||
use syntax::{register_diagnostic, register_diagnostics, register_long_diagnostics};
|
||||
use syntax::{register_diagnostics, register_long_diagnostics};
|
||||
|
||||
register_long_diagnostics! {
|
||||
E0454: r##"
|
||||
|
|
|
|||
|
|
@ -15,12 +15,10 @@ Rust MIR: a lowered representation of Rust. Also: an experiment!
|
|||
#![feature(decl_macro)]
|
||||
#![feature(exhaustive_patterns)]
|
||||
#![feature(rustc_diagnostic_macros)]
|
||||
#![feature(rustc_attrs)]
|
||||
#![feature(never_type)]
|
||||
#![feature(specialization)]
|
||||
#![feature(try_trait)]
|
||||
#![feature(unicode_internals)]
|
||||
#![feature(step_trait)]
|
||||
#![feature(slice_concat_ext)]
|
||||
#![feature(trusted_len)]
|
||||
#![feature(try_blocks)]
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#![allow(non_snake_case)]
|
||||
|
||||
use syntax::{register_diagnostic, register_diagnostics, register_long_diagnostics};
|
||||
use syntax::{register_diagnostics, register_long_diagnostics};
|
||||
|
||||
register_long_diagnostics! {
|
||||
/*
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#![allow(non_snake_case)]
|
||||
|
||||
use syntax::{register_diagnostic, register_diagnostics, register_long_diagnostics};
|
||||
use syntax::{register_diagnostics, register_long_diagnostics};
|
||||
|
||||
register_long_diagnostics! {
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#![allow(non_snake_case)]
|
||||
|
||||
use syntax::{register_diagnostic, register_diagnostics, register_long_diagnostics};
|
||||
use syntax::{register_diagnostics, register_long_diagnostics};
|
||||
|
||||
// Error messages for EXXXX errors. Each message should start and end with a
|
||||
// new line, and be wrapped to 80 characters. In vim you can `:set tw=80` and
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use crate::spec::Target;
|
|||
use std::fmt;
|
||||
use std::ops::{Add, Deref, Sub, Mul, AddAssign, Range, RangeInclusive};
|
||||
|
||||
use rustc_data_structures::newtype_index;
|
||||
use rustc_data_structures::indexed_vec::{Idx, IndexVec};
|
||||
use syntax_pos::symbol::{sym, Symbol};
|
||||
|
||||
|
|
|
|||
|
|
@ -11,9 +11,7 @@
|
|||
|
||||
#![feature(box_syntax)]
|
||||
#![feature(nll)]
|
||||
#![feature(rustc_attrs)]
|
||||
#![feature(slice_patterns)]
|
||||
#![feature(step_trait)]
|
||||
|
||||
#![deny(rust_2018_idioms)]
|
||||
#![deny(unused_lifetimes)]
|
||||
|
|
@ -23,8 +21,5 @@
|
|||
#[allow(unused_extern_crates)]
|
||||
extern crate serialize as rustc_serialize; // used by deriving
|
||||
|
||||
#[macro_use]
|
||||
extern crate rustc_data_structures;
|
||||
|
||||
pub mod abi;
|
||||
pub mod spec;
|
||||
|
|
|
|||
|
|
@ -170,19 +170,19 @@ macro_rules! help {
|
|||
#[macro_export]
|
||||
macro_rules! register_diagnostics {
|
||||
($($code:tt),*) => (
|
||||
$(register_diagnostic! { $code })*
|
||||
$($crate::register_diagnostic! { $code })*
|
||||
);
|
||||
($($code:tt),*,) => (
|
||||
$(register_diagnostic! { $code })*
|
||||
$($crate::register_diagnostic! { $code })*
|
||||
)
|
||||
}
|
||||
|
||||
#[macro_export]
|
||||
macro_rules! register_long_diagnostics {
|
||||
($($code:tt: $description:tt),*) => (
|
||||
$(register_diagnostic! { $code, $description })*
|
||||
$($crate::register_diagnostic! { $code, $description })*
|
||||
);
|
||||
($($code:tt: $description:tt),*,) => (
|
||||
$(register_diagnostic! { $code, $description })*
|
||||
$($crate::register_diagnostic! { $code, $description })*
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,9 +18,7 @@
|
|||
#![feature(label_break_value)]
|
||||
#![feature(mem_take)]
|
||||
#![feature(nll)]
|
||||
#![feature(rustc_attrs)]
|
||||
#![feature(rustc_diagnostic_macros)]
|
||||
#![feature(step_trait)]
|
||||
#![feature(try_trait)]
|
||||
#![feature(unicode_internals)]
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#![allow(non_snake_case)]
|
||||
|
||||
use syntax::{register_diagnostic, register_long_diagnostics};
|
||||
use syntax::register_long_diagnostics;
|
||||
|
||||
// Error messages for EXXXX errors.
|
||||
// Each message should start and end with a new line, and be wrapped to 80 characters.
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
#![feature(rustc_attrs, rustc_private, step_trait)]
|
||||
#![feature(rustc_private)]
|
||||
|
||||
#[macro_use] extern crate rustc_data_structures;
|
||||
extern crate rustc_data_structures;
|
||||
extern crate serialize as rustc_serialize;
|
||||
|
||||
use rustc_data_structures::indexed_vec::Idx;
|
||||
use rustc_data_structures::{newtype_index, indexed_vec::Idx};
|
||||
|
||||
newtype_index!(struct MyIdx { MAX = 0xFFFF_FFFA });
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue