Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use ? Kleene operator again #56357

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/librustc/lint/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,14 @@ impl Lint {
/// Declare a static item of type `&'static Lint`.
#[macro_export]
macro_rules! declare_lint {
($vis: vis $NAME: ident, $Level: ident, $desc: expr) => (
($vis: vis $NAME: ident, $Level: ident, $desc: expr $(,)?) => (
declare_lint!{$vis $NAME, $Level, $desc, false}
);
($vis: vis $NAME: ident, $Level: ident, $desc: expr, report_in_external_macro: $rep: expr) => (
($vis: vis $NAME: ident, $Level: ident, $desc: expr,
report_in_external_macro: $rep: expr $(,)?) => (
declare_lint!{$vis $NAME, $Level, $desc, $rep}
);
($vis: vis $NAME: ident, $Level: ident, $desc: expr, $external: expr) => (
($vis: vis $NAME: ident, $Level: ident, $desc: expr, $external: expr $(,)?) => (
$vis static $NAME: &$crate::lint::Lint = &$crate::lint::Lint {
name: stringify!($NAME),
default_level: $crate::lint::$Level,
Expand All @@ -127,7 +128,7 @@ macro_rules! declare_lint {
};
);
($vis: vis $NAME: ident, $Level: ident, $desc: expr,
$lint_edition: expr => $edition_level: ident
$lint_edition: expr => $edition_level: ident $(,)?
) => (
$vis static $NAME: &$crate::lint::Lint = &$crate::lint::Lint {
name: stringify!($NAME),
Expand All @@ -141,14 +142,14 @@ macro_rules! declare_lint {

#[macro_export]
macro_rules! declare_tool_lint {
($vis: vis $tool: ident ::$NAME: ident, $Level: ident, $desc: expr) => (
($vis: vis $tool: ident ::$NAME: ident, $Level: ident, $desc: expr $(,)?) => (
declare_tool_lint!{$vis $tool::$NAME, $Level, $desc, false}
);
($vis: vis $tool: ident ::$NAME: ident, $Level: ident, $desc: expr,
report_in_external_macro: $rep: expr) => (
report_in_external_macro: $rep: expr $(,)?) => (
declare_tool_lint!{$vis $tool::$NAME, $Level, $desc, $rep}
);
($vis: vis $tool: ident ::$NAME: ident, $Level: ident, $desc: expr, $external: expr) => (
($vis: vis $tool: ident ::$NAME: ident, $Level: ident, $desc: expr, $external: expr $(,)?) => (
$vis static $NAME: &$crate::lint::Lint = &$crate::lint::Lint {
name: &concat!(stringify!($tool), "::", stringify!($NAME)),
default_level: $crate::lint::$Level,
Expand All @@ -162,8 +163,7 @@ macro_rules! declare_tool_lint {
/// Declare a static `LintArray` and return it as an expression.
#[macro_export]
macro_rules! lint_array {
($( $lint:expr ),* ,) => { lint_array!( $($lint),* ) };
($( $lint:expr ),*) => {{
($( $lint:expr ),* $(,)?) => {{
vec![$($lint),*]
}}
}
Expand Down
54 changes: 25 additions & 29 deletions src/librustc/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,38 +72,36 @@ macro_rules! __impl_stable_hash_field {
#[macro_export]
macro_rules! impl_stable_hash_for {
// Enums
// FIXME(mark-i-m): Some of these should be `?` rather than `*`. See the git blame and change
// them back when `?` is supported again.
(enum $enum_name:path {
$( $variant:ident
// this incorrectly allows specifying both tuple-like and struct-like fields, as in `Variant(a,b){c,d}`,
// when it should be only one or the other
$( ( $($field:ident $(-> $delegate:tt)*),* ) )*
$( ( $($field:ident $(-> $delegate:tt)?),* ) )*
$( { $($named_field:ident $(-> $named_delegate:tt)*),* } )*
),* $(,)*
),* $(,)?
}) => {
impl_stable_hash_for!(
impl<> for enum $enum_name [ $enum_name ] { $( $variant
$( ( $($field $(-> $delegate)*),* ) )*
$( ( $($field $(-> $delegate)?),* ) )*
$( { $($named_field $(-> $named_delegate)*),* } )*
),* }
),? }
);
};
// We want to use the enum name both in the `impl ... for $enum_name` as well as for
// importing all the variants. Unfortunately it seems we have to take the name
// twice for this purpose
(impl<$($lt:lifetime $(: $lt_bound:lifetime)* ),* $(,)* $($T:ident),* $(,)*>
(impl<$($lt:lifetime $(: $lt_bound:lifetime)? ),* $(,)? $($T:ident),* $(,)?>
for enum $enum_name:path
[ $enum_path:path ]
{
$( $variant:ident
// this incorrectly allows specifying both tuple-like and struct-like fields, as in `Variant(a,b){c,d}`,
// when it should be only one or the other
$( ( $($field:ident $(-> $delegate:tt)*),* ) )*
$( { $($named_field:ident $(-> $named_delegate:tt)*),* } )*
),* $(,)*
$( ( $($field:ident $(-> $delegate:tt)?),* ) )?
$( { $($named_field:ident $(-> $named_delegate:tt)?),* } )?
),* $(,)?
}) => {
impl<'a, $($lt $(: $lt_bound)*,)* $($T,)*>
impl<'a, $($lt $(: $lt_bound)?,)* $($T,)*>
::rustc_data_structures::stable_hasher::HashStable<$crate::ich::StableHashingContext<'a>>
for $enum_name
where $($T: ::rustc_data_structures::stable_hasher::HashStable<$crate::ich::StableHashingContext<'a>>),*
Expand All @@ -117,26 +115,25 @@ macro_rules! impl_stable_hash_for {

match *self {
$(
$variant $( ( $(ref $field),* ) )* $( { $(ref $named_field),* } )* => {
$($( __impl_stable_hash_field!($field, __ctx, __hasher $(, $delegate)*) );*)*
$($( __impl_stable_hash_field!($named_field, __ctx, __hasher $(, $named_delegate)*) );*)*
$variant $( ( $(ref $field),* ) )? $( { $(ref $named_field),* } )? => {
$($( __impl_stable_hash_field!($field, __ctx, __hasher $(, $delegate)?) );?)*
$($( __impl_stable_hash_field!($named_field, __ctx, __hasher $(, $named_delegate)?) );?)*
}
)*
}
}
}
};
// Structs
// FIXME(mark-i-m): same here.
(struct $struct_name:path { $($field:ident $(-> $delegate:tt)*),* $(,)* }) => {
(struct $struct_name:path { $($field:ident $(-> $delegate:tt)?),* $(,)? }) => {
impl_stable_hash_for!(
impl<'tcx> for struct $struct_name { $($field $(-> $delegate)*),* }
impl<'tcx> for struct $struct_name { $($field $(-> $delegate)?),* }
);
};
(impl<$($lt:lifetime $(: $lt_bound:lifetime)* ),* $(,)* $($T:ident),* $(,)*> for struct $struct_name:path {
$($field:ident $(-> $delegate:tt)*),* $(,)*
(impl<$($lt:lifetime $(: $lt_bound:lifetime)? ),* $(,)? $($T:ident),* $(,)?> for struct $struct_name:path {
$($field:ident $(-> $delegate:tt)?),* $(,)?
}) => {
impl<'a, $($lt $(: $lt_bound)*,)* $($T,)*>
impl<'a, $($lt $(: $lt_bound)?,)* $($T,)*>
::rustc_data_structures::stable_hasher::HashStable<$crate::ich::StableHashingContext<'a>> for $struct_name
where $($T: ::rustc_data_structures::stable_hasher::HashStable<$crate::ich::StableHashingContext<'a>>),*
{
Expand All @@ -148,21 +145,20 @@ macro_rules! impl_stable_hash_for {
$(ref $field),*
} = *self;

$( __impl_stable_hash_field!($field, __ctx, __hasher $(, $delegate)*) );*
$( __impl_stable_hash_field!($field, __ctx, __hasher $(, $delegate)?) );*
}
}
};
// Tuple structs
// We cannot use normale parentheses here, the parser won't allow it
// FIXME(mark-i-m): same here.
(tuple_struct $struct_name:path { $($field:ident $(-> $delegate:tt)*),* $(,)* }) => {
// We cannot use normal parentheses here, the parser won't allow it
(tuple_struct $struct_name:path { $($field:ident $(-> $delegate:tt)?),* $(,)? }) => {
impl_stable_hash_for!(
impl<'tcx> for tuple_struct $struct_name { $($field $(-> $delegate)*),* }
impl<'tcx> for tuple_struct $struct_name { $($field $(-> $delegate)?),* }
);
};
(impl<$($lt:lifetime $(: $lt_bound:lifetime)* ),* $(,)* $($T:ident),* $(,)*>
for tuple_struct $struct_name:path { $($field:ident $(-> $delegate:tt)*),* $(,)* }) => {
impl<'a, $($lt $(: $lt_bound)*,)* $($T,)*>
(impl<$($lt:lifetime $(: $lt_bound:lifetime)? ),* $(,)? $($T:ident),* $(,)?>
for tuple_struct $struct_name:path { $($field:ident $(-> $delegate:tt)?),* $(,)? }) => {
impl<'a, $($lt $(: $lt_bound)?,)* $($T,)*>
::rustc_data_structures::stable_hasher::HashStable<$crate::ich::StableHashingContext<'a>> for $struct_name
where $($T: ::rustc_data_structures::stable_hasher::HashStable<$crate::ich::StableHashingContext<'a>>),*
{
Expand All @@ -174,7 +170,7 @@ macro_rules! impl_stable_hash_for {
$(ref $field),*
) = *self;

$( __impl_stable_hash_field!($field, __ctx, __hasher $(, $delegate)*) );*
$( __impl_stable_hash_field!($field, __ctx, __hasher $(, $delegate)?) );*
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_lint/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1389,7 +1389,7 @@ impl LintPass for SoftLints {
UNIONS_WITH_DROP_FIELDS,
UNREACHABLE_PUB,
TYPE_ALIAS_BOUNDS,
TRIVIAL_BOUNDS
TRIVIAL_BOUNDS,
)
}
}
Expand Down
14 changes: 6 additions & 8 deletions src/libsyntax/ext/expand.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ macro_rules! ast_fragments {
(
$($Kind:ident($AstTy:ty) {
$kind_name:expr;
// FIXME: HACK: this should be `$(one ...)?` and `$(many ...)?` but `?` macro
// repetition was removed from 2015 edition in #51587 because of ambiguities.
$(one fn $fold_ast:ident; fn $visit_ast:ident;)*
$(many fn $fold_ast_elt:ident; fn $visit_ast_elt:ident;)*
$(one fn $fold_ast:ident; fn $visit_ast:ident;)?
$(many fn $fold_ast_elt:ident; fn $visit_ast_elt:ident;)?
fn $make_ast:ident;
})*
) => {
Expand Down Expand Up @@ -102,11 +100,11 @@ macro_rules! ast_fragments {
AstFragment::OptExpr(expr) =>
AstFragment::OptExpr(expr.and_then(|expr| folder.fold_opt_expr(expr))),
$($(AstFragment::$Kind(ast) =>
AstFragment::$Kind(folder.$fold_ast(ast)),)*)*
AstFragment::$Kind(folder.$fold_ast(ast)),)?)*
$($(AstFragment::$Kind(ast) =>
AstFragment::$Kind(ast.into_iter()
.flat_map(|ast| folder.$fold_ast_elt(ast))
.collect()),)*)*
.collect()),)?)*
}
}

Expand All @@ -128,10 +126,10 @@ macro_rules! ast_fragments {
}
$($(fn $fold_ast(&mut self, ast: $AstTy) -> $AstTy {
self.expand_fragment(AstFragment::$Kind(ast)).$make_ast()
})*)*
})?)*
$($(fn $fold_ast_elt(&mut self, ast_elt: <$AstTy as IntoIterator>::Item) -> $AstTy {
self.expand_fragment(AstFragment::$Kind(smallvec![ast_elt])).$make_ast()
})*)*
})?)*
}

impl<'a> MacResult for ::ext::tt::macro_rules::ParserAnyMacro<'a> {
Expand Down