Skip to content

Commit ba93a4f

Browse files
authored
Rollup merge of #146849 - joshtriplett:macro-reduce-legacy-bang, r=petrochenkov
Reduce some uses of `LegacyBang` - **Switch `dummy_bang` from `LegacyBang` to `Bang`** - **mbe: Switch dummy extension used for errors from `LegacyBang` to `Bang`**
2 parents 35f443d + a1646bf commit ba93a4f

File tree

3 files changed

+19
-22
lines changed

3 files changed

+19
-22
lines changed

compiler/rustc_expand/src/base.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -324,16 +324,16 @@ pub trait BangProcMacro {
324324

325325
impl<F> BangProcMacro for F
326326
where
327-
F: Fn(TokenStream) -> TokenStream,
327+
F: Fn(&mut ExtCtxt<'_>, Span, TokenStream) -> Result<TokenStream, ErrorGuaranteed>,
328328
{
329329
fn expand<'cx>(
330330
&self,
331-
_ecx: &'cx mut ExtCtxt<'_>,
332-
_span: Span,
331+
ecx: &'cx mut ExtCtxt<'_>,
332+
span: Span,
333333
ts: TokenStream,
334334
) -> Result<TokenStream, ErrorGuaranteed> {
335335
// FIXME setup implicit context in TLS before calling self.
336-
Ok(self(ts))
336+
self(ecx, span, ts)
337337
}
338338
}
339339

@@ -999,17 +999,14 @@ impl SyntaxExtension {
999999

10001000
/// A dummy bang macro `foo!()`.
10011001
pub fn dummy_bang(edition: Edition) -> SyntaxExtension {
1002-
fn expander<'cx>(
1003-
cx: &'cx mut ExtCtxt<'_>,
1002+
fn expand(
1003+
ecx: &mut ExtCtxt<'_>,
10041004
span: Span,
1005-
_: TokenStream,
1006-
) -> MacroExpanderResult<'cx> {
1007-
ExpandResult::Ready(DummyResult::any(
1008-
span,
1009-
cx.dcx().span_delayed_bug(span, "expanded a dummy bang macro"),
1010-
))
1005+
_ts: TokenStream,
1006+
) -> Result<TokenStream, ErrorGuaranteed> {
1007+
Err(ecx.dcx().span_delayed_bug(span, "expanded a dummy bang macro"))
10111008
}
1012-
SyntaxExtension::default(SyntaxExtensionKind::LegacyBang(Arc::new(expander)), edition)
1009+
SyntaxExtension::default(SyntaxExtensionKind::Bang(Arc::new(expand)), edition)
10131010
}
10141011

10151012
/// A dummy derive macro `#[derive(Foo)]`.

compiler/rustc_expand/src/expand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -971,7 +971,7 @@ impl<'a, 'b> MacroExpander<'a, 'b> {
971971
});
972972
}
973973
},
974-
SyntaxExtensionKind::LegacyBang(..) => {
974+
SyntaxExtensionKind::Bang(..) => {
975975
let msg = "expanded a dummy glob delegation";
976976
let guar = self.cx.dcx().span_delayed_bug(span, msg);
977977
return ExpandResult::Ready(fragment_kind.dummy(span, guar));

compiler/rustc_expand/src/mbe/macro_rules.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ use super::diagnostics::{FailedMacro, failed_to_match_macro};
3333
use super::macro_parser::{NamedMatches, NamedParseResult};
3434
use super::{SequenceRepetition, diagnostics};
3535
use crate::base::{
36-
AttrProcMacro, DummyResult, ExpandResult, ExtCtxt, MacResult, MacroExpanderResult,
37-
SyntaxExtension, SyntaxExtensionKind, TTMacroExpander,
36+
AttrProcMacro, BangProcMacro, DummyResult, ExpandResult, ExtCtxt, MacResult,
37+
MacroExpanderResult, SyntaxExtension, SyntaxExtensionKind, TTMacroExpander,
3838
};
3939
use crate::errors;
4040
use crate::expand::{AstFragment, AstFragmentKind, ensure_complete_parse, parse_ast_fragment};
@@ -267,16 +267,16 @@ impl AttrProcMacro for MacroRulesMacroExpander {
267267
}
268268
}
269269

270-
struct DummyExpander(ErrorGuaranteed);
270+
struct DummyBang(ErrorGuaranteed);
271271

272-
impl TTMacroExpander for DummyExpander {
272+
impl BangProcMacro for DummyBang {
273273
fn expand<'cx>(
274274
&self,
275275
_: &'cx mut ExtCtxt<'_>,
276-
span: Span,
276+
_: Span,
277277
_: TokenStream,
278-
) -> ExpandResult<Box<dyn MacResult + 'cx>, ()> {
279-
ExpandResult::Ready(DummyResult::any(span, self.0))
278+
) -> Result<TokenStream, ErrorGuaranteed> {
279+
Err(self.0)
280280
}
281281
}
282282

@@ -664,7 +664,7 @@ pub fn compile_declarative_macro(
664664
SyntaxExtension::new(sess, kind, span, Vec::new(), edition, ident.name, attrs, is_local)
665665
};
666666
let dummy_syn_ext =
667-
|guar| (mk_syn_ext(SyntaxExtensionKind::LegacyBang(Arc::new(DummyExpander(guar)))), 0);
667+
|guar| (mk_syn_ext(SyntaxExtensionKind::Bang(Arc::new(DummyBang(guar)))), 0);
668668

669669
let macro_rules = macro_def.macro_rules;
670670
let exp_sep = if macro_rules { exp!(Semi) } else { exp!(Comma) };

0 commit comments

Comments
 (0)