Skip to content

Commit 0f7d817

Browse files
committed
Auto merge of rust-lang#104696 - matthiaskrgr:rollup-gi1pdb0, r=matthiaskrgr
Rollup of 11 pull requests Successful merges: - rust-lang#103396 (Pin::new_unchecked: discuss pinning closure captures) - rust-lang#104416 (Fix using `include_bytes` in pattern position) - rust-lang#104557 (Add a test case for async dyn* traits) - rust-lang#104559 (Split `MacArgs` in two.) - rust-lang#104597 (Probe + better error messsage for `need_migrate_deref_output_trait_object`) - rust-lang#104656 (Move tests) - rust-lang#104657 (Do not check transmute if has non region infer) - rust-lang#104663 (rustdoc: factor out common button CSS) - rust-lang#104666 (Migrate alias search result to CSS variables) - rust-lang#104674 (Make negative_impl and negative_impl_exists take the right types) - rust-lang#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

+1-5
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

+57-46
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

compiler/rustc_ast/src/attr/mod.rs

+28-26
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
//! Functions dealing with attributes and meta items.
22
33
use crate::ast;
4-
use crate::ast::{AttrId, AttrItem, AttrKind, AttrStyle, Attribute};
5-
use crate::ast::{Lit, LitKind};
6-
use crate::ast::{MacArgs, MacArgsEq, MacDelimiter, MetaItem, MetaItemKind, NestedMetaItem};
4+
use crate::ast::{AttrArgs, AttrArgsEq, AttrId, AttrItem, AttrKind, AttrStyle, Attribute};
5+
use crate::ast::{DelimArgs, Lit, LitKind};
6+
use crate::ast::{MacDelimiter, MetaItem, MetaItemKind, NestedMetaItem};
77
use crate::ast::{Path, PathSegment};
88
use crate::ptr::P;
99
use crate::token::{self, CommentKind, Delimiter, Token};
@@ -158,7 +158,7 @@ impl Attribute {
158158

159159
pub fn is_word(&self) -> bool {
160160
if let AttrKind::Normal(normal) = &self.kind {
161-
matches!(normal.item.args, MacArgs::Empty)
161+
matches!(normal.item.args, AttrArgs::Empty)
162162
} else {
163163
false
164164
}
@@ -223,13 +223,13 @@ impl AttrItem {
223223
pub fn meta(&self, span: Span) -> Option<MetaItem> {
224224
Some(MetaItem {
225225
path: self.path.clone(),
226-
kind: MetaItemKind::from_mac_args(&self.args)?,
226+
kind: MetaItemKind::from_attr_args(&self.args)?,
227227
span,
228228
})
229229
}
230230

231231
pub fn meta_kind(&self) -> Option<MetaItemKind> {
232-
MetaItemKind::from_mac_args(&self.args)
232+
MetaItemKind::from_attr_args(&self.args)
233233
}
234234
}
235235

@@ -390,7 +390,7 @@ pub fn mk_attr(
390390
g: &AttrIdGenerator,
391391
style: AttrStyle,
392392
path: Path,
393-
args: MacArgs,
393+
args: AttrArgs,
394394
span: Span,
395395
) -> Attribute {
396396
mk_attr_from_item(g, AttrItem { path, args, tokens: None }, None, style, span)
@@ -413,12 +413,12 @@ pub fn mk_attr_from_item(
413413

414414
/// Returns an inner attribute with the given value and span.
415415
pub fn mk_attr_inner(g: &AttrIdGenerator, item: MetaItem) -> Attribute {
416-
mk_attr(g, AttrStyle::Inner, item.path, item.kind.mac_args(item.span), item.span)
416+
mk_attr(g, AttrStyle::Inner, item.path, item.kind.attr_args(item.span), item.span)
417417
}
418418

419419
/// Returns an outer attribute with the given value and span.
420420
pub fn mk_attr_outer(g: &AttrIdGenerator, item: MetaItem) -> Attribute {
421-
mk_attr(g, AttrStyle::Outer, item.path, item.kind.mac_args(item.span), item.span)
421+
mk_attr(g, AttrStyle::Outer, item.path, item.kind.attr_args(item.span), item.span)
422422
}
423423

424424
pub fn mk_doc_comment(
@@ -524,9 +524,9 @@ impl MetaItemKind {
524524
}
525525
}
526526

527-
pub fn mac_args(&self, span: Span) -> MacArgs {
527+
pub fn attr_args(&self, span: Span) -> AttrArgs {
528528
match self {
529-
MetaItemKind::Word => MacArgs::Empty,
529+
MetaItemKind::Word => AttrArgs::Empty,
530530
MetaItemKind::NameValue(lit) => {
531531
let expr = P(ast::Expr {
532532
id: ast::DUMMY_NODE_ID,
@@ -535,7 +535,7 @@ impl MetaItemKind {
535535
attrs: ast::AttrVec::new(),
536536
tokens: None,
537537
});
538-
MacArgs::Eq(span, MacArgsEq::Ast(expr))
538+
AttrArgs::Eq(span, AttrArgsEq::Ast(expr))
539539
}
540540
MetaItemKind::List(list) => {
541541
let mut tts = Vec::new();
@@ -545,11 +545,11 @@ impl MetaItemKind {
545545
}
546546
tts.extend(item.token_trees())
547547
}
548-
MacArgs::Delimited(
549-
DelimSpan::from_single(span),
550-
MacDelimiter::Parenthesis,
551-
TokenStream::new(tts),
552-
)
548+
AttrArgs::Delimited(DelimArgs {
549+
dspan: DelimSpan::from_single(span),
550+
delim: MacDelimiter::Parenthesis,
551+
tokens: TokenStream::new(tts),
552+
})
553553
}
554554
}
555555
}
@@ -608,20 +608,22 @@ impl MetaItemKind {
608608
}
609609
}
610610

611-
fn from_mac_args(args: &MacArgs) -> Option<MetaItemKind> {
611+
fn from_attr_args(args: &AttrArgs) -> Option<MetaItemKind> {
612612
match args {
613-
MacArgs::Empty => Some(MetaItemKind::Word),
614-
MacArgs::Delimited(_, MacDelimiter::Parenthesis, tokens) => {
615-
MetaItemKind::list_from_tokens(tokens.clone())
616-
}
617-
MacArgs::Delimited(..) => None,
618-
MacArgs::Eq(_, MacArgsEq::Ast(expr)) => match expr.kind {
613+
AttrArgs::Empty => Some(MetaItemKind::Word),
614+
AttrArgs::Delimited(DelimArgs {
615+
dspan: _,
616+
delim: MacDelimiter::Parenthesis,
617+
tokens,
618+
}) => MetaItemKind::list_from_tokens(tokens.clone()),
619+
AttrArgs::Delimited(..) => None,
620+
AttrArgs::Eq(_, AttrArgsEq::Ast(expr)) => match expr.kind {
619621
ast::ExprKind::Lit(token_lit) => Some(MetaItemKind::NameValue(
620-
Lit::from_token_lit(token_lit, expr.span).expect("token_lit in from_mac_args"),
622+
Lit::from_token_lit(token_lit, expr.span).expect("token_lit in from_attr_args"),
621623
)),
622624
_ => None,
623625
},
624-
MacArgs::Eq(_, MacArgsEq::Hir(lit)) => Some(MetaItemKind::NameValue(lit.clone())),
626+
AttrArgs::Eq(_, AttrArgsEq::Hir(lit)) => Some(MetaItemKind::NameValue(lit.clone())),
625627
}
626628
}
627629

compiler/rustc_ast/src/mut_visit.rs

+16-12
Original file line numberDiff line numberDiff line change
@@ -367,23 +367,27 @@ pub fn visit_fn_sig<T: MutVisitor>(FnSig { header, decl, span }: &mut FnSig, vis
367367
}
368368

369369
// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
370-
pub fn visit_mac_args<T: MutVisitor>(args: &mut MacArgs, vis: &mut T) {
370+
pub fn visit_attr_args<T: MutVisitor>(args: &mut AttrArgs, vis: &mut T) {
371371
match args {
372-
MacArgs::Empty => {}
373-
MacArgs::Delimited(dspan, _delim, tokens) => {
374-
visit_delim_span(dspan, vis);
375-
visit_tts(tokens, vis);
376-
}
377-
MacArgs::Eq(eq_span, MacArgsEq::Ast(expr)) => {
372+
AttrArgs::Empty => {}
373+
AttrArgs::Delimited(args) => visit_delim_args(args, vis),
374+
AttrArgs::Eq(eq_span, AttrArgsEq::Ast(expr)) => {
378375
vis.visit_span(eq_span);
379376
vis.visit_expr(expr);
380377
}
381-
MacArgs::Eq(_, MacArgsEq::Hir(lit)) => {
378+
AttrArgs::Eq(_, AttrArgsEq::Hir(lit)) => {
382379
unreachable!("in literal form when visiting mac args eq: {:?}", lit)
383380
}
384381
}
385382
}
386383

384+
// No `noop_` prefix because there isn't a corresponding method in `MutVisitor`.
385+
pub fn visit_delim_args<T: MutVisitor>(args: &mut DelimArgs, vis: &mut T) {
386+
let DelimArgs { dspan, delim: _, tokens } = args;
387+
visit_delim_span(dspan, vis);
388+
visit_tts(tokens, vis);
389+
}
390+
387391
pub fn visit_delim_span<T: MutVisitor>(dspan: &mut DelimSpan, vis: &mut T) {
388392
vis.visit_span(&mut dspan.open);
389393
vis.visit_span(&mut dspan.close);
@@ -601,7 +605,7 @@ pub fn noop_visit_attribute<T: MutVisitor>(attr: &mut Attribute, vis: &mut T) {
601605
let NormalAttr { item: AttrItem { path, args, tokens }, tokens: attr_tokens } =
602606
&mut **normal;
603607
vis.visit_path(path);
604-
visit_mac_args(args, vis);
608+
visit_attr_args(args, vis);
605609
visit_lazy_tts(tokens, vis);
606610
visit_lazy_tts(attr_tokens, vis);
607611
}
@@ -613,12 +617,12 @@ pub fn noop_visit_attribute<T: MutVisitor>(attr: &mut Attribute, vis: &mut T) {
613617
pub fn noop_visit_mac<T: MutVisitor>(mac: &mut MacCall, vis: &mut T) {
614618
let MacCall { path, args, prior_type_ascription: _ } = mac;
615619
vis.visit_path(path);
616-
visit_mac_args(args, vis);
620+
visit_delim_args(args, vis);
617621
}
618622

619623
pub fn noop_visit_macro_def<T: MutVisitor>(macro_def: &mut MacroDef, vis: &mut T) {
620624
let MacroDef { body, macro_rules: _ } = macro_def;
621-
visit_mac_args(body, vis);
625+
visit_delim_args(body, vis);
622626
}
623627

624628
pub fn noop_visit_meta_list_item<T: MutVisitor>(li: &mut NestedMetaItem, vis: &mut T) {
@@ -792,7 +796,7 @@ pub fn visit_nonterminal<T: MutVisitor>(nt: &mut token::Nonterminal, vis: &mut T
792796
token::NtMeta(item) => {
793797
let AttrItem { path, args, tokens } = item.deref_mut();
794798
vis.visit_path(path);
795-
visit_mac_args(args, vis);
799+
visit_attr_args(args, vis);
796800
visit_lazy_tts(tokens, vis);
797801
}
798802
token::NtPath(path) => vis.visit_path(path),

0 commit comments

Comments
 (0)