Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 0f7d817

Browse files
committedNov 22, 2022
Auto merge of #104696 - matthiaskrgr:rollup-gi1pdb0, r=matthiaskrgr
Rollup of 11 pull requests Successful merges: - #103396 (Pin::new_unchecked: discuss pinning closure captures) - #104416 (Fix using `include_bytes` in pattern position) - #104557 (Add a test case for async dyn* traits) - #104559 (Split `MacArgs` in two.) - #104597 (Probe + better error messsage for `need_migrate_deref_output_trait_object`) - #104656 (Move tests) - #104657 (Do not check transmute if has non region infer) - #104663 (rustdoc: factor out common button CSS) - #104666 (Migrate alias search result to CSS variables) - #104674 (Make negative_impl and negative_impl_exists take the right types) - #104692 (Update test's cfg-if dependency to 1.0) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
2 parents 28a53cd + 04e8ebe commit 0f7d817

File tree

68 files changed

+496
-359
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

68 files changed

+496
-359
lines changed
 

‎Cargo.lock

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -498,10 +498,6 @@ name = "cfg-if"
498498
version = "0.1.10"
499499
source = "registry+https://github.com/rust-lang/crates.io-index"
500500
checksum = "4785bdd1c96b2a846b2bd7cc02e86b6b3dbf14e7e53446c4f54c92a361040822"
501-
dependencies = [
502-
"compiler_builtins",
503-
"rustc-std-workspace-core",
504-
]
505501

506502
[[package]]
507503
name = "cfg-if"
@@ -4934,7 +4930,7 @@ dependencies = [
49344930
name = "test"
49354931
version = "0.0.0"
49364932
dependencies = [
4937-
"cfg-if 0.1.10",
4933+
"cfg-if 1.0.0",
49384934
"core",
49394935
"getopts",
49404936
"libc",

‎compiler/rustc_ast/src/ast.rs

Lines changed: 57 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,55 +1544,48 @@ pub enum ClosureBinder {
15441544
#[derive(Clone, Encodable, Decodable, Debug)]
15451545
pub struct MacCall {
15461546
pub path: Path,
1547-
pub args: P<MacArgs>,
1547+
pub args: P<DelimArgs>,
15481548
pub prior_type_ascription: Option<(Span, bool)>,
15491549
}
15501550

15511551
impl MacCall {
15521552
pub fn span(&self) -> Span {
1553-
self.path.span.to(self.args.span().unwrap_or(self.path.span))
1553+
self.path.span.to(self.args.dspan.entire())
15541554
}
15551555
}
15561556

1557-
/// Arguments passed to an attribute or a function-like macro.
1557+
/// Arguments passed to an attribute macro.
15581558
#[derive(Clone, Encodable, Decodable, Debug)]
1559-
pub enum MacArgs {
1560-
/// No arguments - `#[attr]`.
1559+
pub enum AttrArgs {
1560+
/// No arguments: `#[attr]`.
15611561
Empty,
1562-
/// Delimited arguments - `#[attr()/[]/{}]` or `mac!()/[]/{}`.
1563-
Delimited(DelimSpan, MacDelimiter, TokenStream),
1564-
/// Arguments of a key-value attribute - `#[attr = "value"]`.
1562+
/// Delimited arguments: `#[attr()/[]/{}]`.
1563+
Delimited(DelimArgs),
1564+
/// Arguments of a key-value attribute: `#[attr = "value"]`.
15651565
Eq(
15661566
/// Span of the `=` token.
15671567
Span,
15681568
/// The "value".
1569-
MacArgsEq,
1569+
AttrArgsEq,
15701570
),
15711571
}
15721572

1573-
// The RHS of a `MacArgs::Eq` starts out as an expression. Once macro expansion
1574-
// is completed, all cases end up either as a literal, which is the form used
1575-
// after lowering to HIR, or as an error.
1573+
// The RHS of an `AttrArgs::Eq` starts out as an expression. Once macro
1574+
// expansion is completed, all cases end up either as a literal, which is the
1575+
// form used after lowering to HIR, or as an error.
15761576
#[derive(Clone, Encodable, Decodable, Debug)]
1577-
pub enum MacArgsEq {
1577+
pub enum AttrArgsEq {
15781578
Ast(P<Expr>),
15791579
Hir(Lit),
15801580
}
15811581

1582-
impl MacArgs {
1583-
pub fn delim(&self) -> Option<Delimiter> {
1584-
match self {
1585-
MacArgs::Delimited(_, delim, _) => Some(delim.to_token()),
1586-
MacArgs::Empty | MacArgs::Eq(..) => None,
1587-
}
1588-
}
1589-
1582+
impl AttrArgs {
15901583
pub fn span(&self) -> Option<Span> {
15911584
match self {
1592-
MacArgs::Empty => None,
1593-
MacArgs::Delimited(dspan, ..) => Some(dspan.entire()),
1594-
MacArgs::Eq(eq_span, MacArgsEq::Ast(expr)) => Some(eq_span.to(expr.span)),
1595-
MacArgs::Eq(_, MacArgsEq::Hir(lit)) => {
1585+
AttrArgs::Empty => None,
1586+
AttrArgs::Delimited(args) => Some(args.dspan.entire()),
1587+
AttrArgs::Eq(eq_span, AttrArgsEq::Ast(expr)) => Some(eq_span.to(expr.span)),
1588+
AttrArgs::Eq(_, AttrArgsEq::Hir(lit)) => {
15961589
unreachable!("in literal form when getting span: {:?}", lit);
15971590
}
15981591
}
@@ -1602,46 +1595,64 @@ impl MacArgs {
16021595
/// Proc macros see these tokens, for example.
16031596
pub fn inner_tokens(&self) -> TokenStream {
16041597
match self {
1605-
MacArgs::Empty => TokenStream::default(),
1606-
MacArgs::Delimited(.., tokens) => tokens.clone(),
1607-
MacArgs::Eq(_, MacArgsEq::Ast(expr)) => TokenStream::from_ast(expr),
1608-
MacArgs::Eq(_, MacArgsEq::Hir(lit)) => {
1598+
AttrArgs::Empty => TokenStream::default(),
1599+
AttrArgs::Delimited(args) => args.tokens.clone(),
1600+
AttrArgs::Eq(_, AttrArgsEq::Ast(expr)) => TokenStream::from_ast(expr),
1601+
AttrArgs::Eq(_, AttrArgsEq::Hir(lit)) => {
16091602
unreachable!("in literal form when getting inner tokens: {:?}", lit)
16101603
}
16111604
}
16121605
}
1613-
1614-
/// Whether a macro with these arguments needs a semicolon
1615-
/// when used as a standalone item or statement.
1616-
pub fn need_semicolon(&self) -> bool {
1617-
!matches!(self, MacArgs::Delimited(_, MacDelimiter::Brace, _))
1618-
}
16191606
}
16201607

1621-
impl<CTX> HashStable<CTX> for MacArgs
1608+
impl<CTX> HashStable<CTX> for AttrArgs
16221609
where
16231610
CTX: crate::HashStableContext,
16241611
{
16251612
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
16261613
mem::discriminant(self).hash_stable(ctx, hasher);
16271614
match self {
1628-
MacArgs::Empty => {}
1629-
MacArgs::Delimited(dspan, delim, tokens) => {
1630-
dspan.hash_stable(ctx, hasher);
1631-
delim.hash_stable(ctx, hasher);
1632-
tokens.hash_stable(ctx, hasher);
1633-
}
1634-
MacArgs::Eq(_eq_span, MacArgsEq::Ast(expr)) => {
1615+
AttrArgs::Empty => {}
1616+
AttrArgs::Delimited(args) => args.hash_stable(ctx, hasher),
1617+
AttrArgs::Eq(_eq_span, AttrArgsEq::Ast(expr)) => {
16351618
unreachable!("hash_stable {:?}", expr);
16361619
}
1637-
MacArgs::Eq(eq_span, MacArgsEq::Hir(lit)) => {
1620+
AttrArgs::Eq(eq_span, AttrArgsEq::Hir(lit)) => {
16381621
eq_span.hash_stable(ctx, hasher);
16391622
lit.hash_stable(ctx, hasher);
16401623
}
16411624
}
16421625
}
16431626
}
16441627

1628+
/// Delimited arguments, as used in `#[attr()/[]/{}]` or `mac!()/[]/{}`.
1629+
#[derive(Clone, Encodable, Decodable, Debug)]
1630+
pub struct DelimArgs {
1631+
pub dspan: DelimSpan,
1632+
pub delim: MacDelimiter,
1633+
pub tokens: TokenStream,
1634+
}
1635+
1636+
impl DelimArgs {
1637+
/// Whether a macro with these arguments needs a semicolon
1638+
/// when used as a standalone item or statement.
1639+
pub fn need_semicolon(&self) -> bool {
1640+
!matches!(self, DelimArgs { delim: MacDelimiter::Brace, .. })
1641+
}
1642+
}
1643+
1644+
impl<CTX> HashStable<CTX> for DelimArgs
1645+
where
1646+
CTX: crate::HashStableContext,
1647+
{
1648+
fn hash_stable(&self, ctx: &mut CTX, hasher: &mut StableHasher) {
1649+
let DelimArgs { dspan, delim, tokens } = self;
1650+
dspan.hash_stable(ctx, hasher);
1651+
delim.hash_stable(ctx, hasher);
1652+
tokens.hash_stable(ctx, hasher);
1653+
}
1654+
}
1655+
16451656
#[derive(Copy, Clone, PartialEq, Eq, Encodable, Decodable, Debug, HashStable_Generic)]
16461657
pub enum MacDelimiter {
16471658
Parenthesis,
@@ -1671,7 +1682,7 @@ impl MacDelimiter {
16711682
/// Represents a macro definition.
16721683
#[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic)]
16731684
pub struct MacroDef {
1674-
pub body: P<MacArgs>,
1685+
pub body: P<DelimArgs>,
16751686
/// `true` if macro was defined with `macro_rules`.
16761687
pub macro_rules: bool,
16771688
}
@@ -2534,7 +2545,7 @@ impl<D: Decoder> Decodable<D> for AttrId {
25342545
#[derive(Clone, Encodable, Decodable, Debug, HashStable_Generic)]
25352546
pub struct AttrItem {
25362547
pub path: Path,
2537-
pub args: MacArgs,
2548+
pub args: AttrArgs,
25382549
pub tokens: Option<LazyAttrTokenStream>,
25392550
}
25402551

0 commit comments

Comments
 (0)
Please sign in to comment.