Skip to content

Commit 7d38b0f

Browse files
committed
expand: address review comments
1 parent 83313e4 commit 7d38b0f

9 files changed

+64
-64
lines changed

src/librustc_expand/mbe/macro_rules.rs

+11-18
Original file line numberDiff line numberDiff line change
@@ -181,17 +181,12 @@ impl TTMacroExpander for MacroRulesMacroExpander {
181181
}
182182
}
183183

184-
struct MacroRulesDummyExpander;
185-
186-
impl TTMacroExpander for MacroRulesDummyExpander {
187-
fn expand<'cx>(
188-
&self,
189-
_: &'cx mut ExtCtxt<'_>,
190-
sp: Span,
191-
_: TokenStream,
192-
) -> Box<dyn MacResult + 'cx> {
193-
DummyResult::any(sp)
194-
}
184+
fn macro_rules_dummy_expander<'cx>(
185+
_: &'cx mut ExtCtxt<'_>,
186+
span: Span,
187+
_: TokenStream,
188+
) -> Box<dyn MacResult + 'cx> {
189+
DummyResult::any(span)
195190
}
196191

197192
fn trace_macros_note(cx_expansions: &mut FxHashMap<Span, Vec<String>>, sp: Span, message: String) {
@@ -450,14 +445,14 @@ pub fn compile_declarative_macro(
450445
let s = parse_failure_msg(&token);
451446
let sp = token.span.substitute_dummy(def.span);
452447
sess.span_diagnostic.struct_span_err(sp, &s).span_label(sp, msg).emit();
453-
return mk_syn_ext(Box::new(MacroRulesDummyExpander));
448+
return mk_syn_ext(Box::new(macro_rules_dummy_expander));
454449
}
455450
Error(sp, msg) => {
456451
sess.span_diagnostic.struct_span_err(sp.substitute_dummy(def.span), &msg).emit();
457-
return mk_syn_ext(Box::new(MacroRulesDummyExpander));
452+
return mk_syn_ext(Box::new(macro_rules_dummy_expander));
458453
}
459454
ErrorReported => {
460-
return mk_syn_ext(Box::new(MacroRulesDummyExpander));
455+
return mk_syn_ext(Box::new(macro_rules_dummy_expander));
461456
}
462457
};
463458

@@ -520,16 +515,14 @@ pub fn compile_declarative_macro(
520515
None => {}
521516
}
522517

523-
let expander: Box<_> = Box::new(MacroRulesMacroExpander {
518+
mk_syn_ext(Box::new(MacroRulesMacroExpander {
524519
name: def.ident,
525520
span: def.span,
526521
transparency,
527522
lhses,
528523
rhses,
529524
valid,
530-
});
531-
532-
mk_syn_ext(expander)
525+
}))
533526
}
534527

535528
fn check_lhs_nt_follows(

src/test/ui/editions/edition-keywords-2018-2015-parsing.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// edition:2018
22
// aux-build:edition-kw-macro-2015.rs
33

4+
#![feature(async_closure)]
5+
46
fn main() {}
57

68
#[macro_use]
@@ -19,8 +21,10 @@ pub fn check_async() {
1921
r#async = consumes_async_raw!(async); //~ ERROR no rules expected the token `async`
2022
r#async = consumes_async_raw!(r#async); // OK
2123

22-
if passes_ident!(async) == 1 {} //~ ERROR async closures are unstable
24+
if passes_ident!(async) == 1 {}
2325
if passes_ident!(r#async) == 1 {} // OK
2426
module::async(); //~ ERROR expected identifier, found keyword `async`
2527
module::r#async(); // OK
28+
29+
let _recovery_witness: () = 0; //~ ERROR mismatched types
2630
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: expected identifier, found keyword `async`
2-
--> $DIR/edition-keywords-2018-2015-parsing.rs:14:13
2+
--> $DIR/edition-keywords-2018-2015-parsing.rs:16:13
33
|
44
LL | let mut async = 1;
55
| ^^^^^ expected identifier, found keyword
@@ -10,7 +10,7 @@ LL | let mut r#async = 1;
1010
| ^^^^^^^
1111

1212
error: expected identifier, found keyword `async`
13-
--> $DIR/edition-keywords-2018-2015-parsing.rs:24:13
13+
--> $DIR/edition-keywords-2018-2015-parsing.rs:26:13
1414
|
1515
LL | module::async();
1616
| ^^^^^ expected identifier, found keyword
@@ -21,13 +21,13 @@ LL | module::r#async();
2121
| ^^^^^^^
2222

2323
error: no rules expected the token `r#async`
24-
--> $DIR/edition-keywords-2018-2015-parsing.rs:18:31
24+
--> $DIR/edition-keywords-2018-2015-parsing.rs:20:31
2525
|
2626
LL | r#async = consumes_async!(r#async);
2727
| ^^^^^^^ no rules expected this token in macro call
2828

2929
error: no rules expected the token `async`
30-
--> $DIR/edition-keywords-2018-2015-parsing.rs:19:35
30+
--> $DIR/edition-keywords-2018-2015-parsing.rs:21:35
3131
|
3232
LL | r#async = consumes_async_raw!(async);
3333
| ^^^^^ no rules expected this token in macro call
@@ -38,20 +38,19 @@ error: macro expansion ends with an incomplete expression: expected one of `move
3838
LL | ($i: ident) => ($i)
3939
| ^ expected one of `move`, `|`, or `||`
4040
|
41-
::: $DIR/edition-keywords-2018-2015-parsing.rs:22:8
41+
::: $DIR/edition-keywords-2018-2015-parsing.rs:24:8
4242
|
4343
LL | if passes_ident!(async) == 1 {}
4444
| -------------------- in this macro invocation
4545

46-
error[E0658]: async closures are unstable
47-
--> $DIR/edition-keywords-2018-2015-parsing.rs:22:22
46+
error[E0308]: mismatched types
47+
--> $DIR/edition-keywords-2018-2015-parsing.rs:29:33
4848
|
49-
LL | if passes_ident!(async) == 1 {}
50-
| ^^^^^
51-
|
52-
= note: see issue #62290 <https://github.com/rust-lang/rust/issues/62290> for more information
53-
= help: add `#![feature(async_closure)]` to the crate attributes to enable
49+
LL | let _recovery_witness: () = 0;
50+
| -- ^ expected `()`, found integer
51+
| |
52+
| expected due to this
5453

5554
error: aborting due to 6 previous errors
5655

57-
For more information about this error, try `rustc --explain E0658`.
56+
For more information about this error, try `rustc --explain E0308`.

src/test/ui/editions/edition-keywords-2018-2018-parsing.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
// edition:2018
22
// aux-build:edition-kw-macro-2018.rs
33

4+
#![feature(async_closure)]
5+
46
fn main() {}
57

68
#[macro_use]
@@ -19,8 +21,10 @@ pub fn check_async() {
1921
r#async = consumes_async_raw!(async); //~ ERROR no rules expected the token `async`
2022
r#async = consumes_async_raw!(r#async); // OK
2123

22-
if passes_ident!(async) == 1 {} //~ ERROR async closures are unstable
24+
if passes_ident!(async) == 1 {}
2325
if passes_ident!(r#async) == 1 {} // OK
2426
module::async(); //~ ERROR expected identifier, found keyword `async`
2527
module::r#async(); // OK
28+
29+
let _recovery_witness: () = 0; //~ ERROR mismatched types
2630
}
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: expected identifier, found keyword `async`
2-
--> $DIR/edition-keywords-2018-2018-parsing.rs:14:13
2+
--> $DIR/edition-keywords-2018-2018-parsing.rs:16:13
33
|
44
LL | let mut async = 1;
55
| ^^^^^ expected identifier, found keyword
@@ -10,7 +10,7 @@ LL | let mut r#async = 1;
1010
| ^^^^^^^
1111

1212
error: expected identifier, found keyword `async`
13-
--> $DIR/edition-keywords-2018-2018-parsing.rs:24:13
13+
--> $DIR/edition-keywords-2018-2018-parsing.rs:26:13
1414
|
1515
LL | module::async();
1616
| ^^^^^ expected identifier, found keyword
@@ -21,13 +21,13 @@ LL | module::r#async();
2121
| ^^^^^^^
2222

2323
error: no rules expected the token `r#async`
24-
--> $DIR/edition-keywords-2018-2018-parsing.rs:18:31
24+
--> $DIR/edition-keywords-2018-2018-parsing.rs:20:31
2525
|
2626
LL | r#async = consumes_async!(r#async);
2727
| ^^^^^^^ no rules expected this token in macro call
2828

2929
error: no rules expected the token `async`
30-
--> $DIR/edition-keywords-2018-2018-parsing.rs:19:35
30+
--> $DIR/edition-keywords-2018-2018-parsing.rs:21:35
3131
|
3232
LL | r#async = consumes_async_raw!(async);
3333
| ^^^^^ no rules expected this token in macro call
@@ -38,20 +38,19 @@ error: macro expansion ends with an incomplete expression: expected one of `move
3838
LL | ($i: ident) => ($i)
3939
| ^ expected one of `move`, `|`, or `||`
4040
|
41-
::: $DIR/edition-keywords-2018-2018-parsing.rs:22:8
41+
::: $DIR/edition-keywords-2018-2018-parsing.rs:24:8
4242
|
4343
LL | if passes_ident!(async) == 1 {}
4444
| -------------------- in this macro invocation
4545

46-
error[E0658]: async closures are unstable
47-
--> $DIR/edition-keywords-2018-2018-parsing.rs:22:22
46+
error[E0308]: mismatched types
47+
--> $DIR/edition-keywords-2018-2018-parsing.rs:29:33
4848
|
49-
LL | if passes_ident!(async) == 1 {}
50-
| ^^^^^
51-
|
52-
= note: see issue #62290 <https://github.com/rust-lang/rust/issues/62290> for more information
53-
= help: add `#![feature(async_closure)]` to the crate attributes to enable
49+
LL | let _recovery_witness: () = 0;
50+
| -- ^ expected `()`, found integer
51+
| |
52+
| expected due to this
5453

5554
error: aborting due to 6 previous errors
5655

57-
For more information about this error, try `rustc --explain E0658`.
56+
For more information about this error, try `rustc --explain E0308`.
+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
fn main() {}
2-
31
macro_rules! foo {
42
{ $+ } => { //~ ERROR expected identifier, found `+`
53
//~^ ERROR missing fragment specifier
@@ -8,3 +6,5 @@ macro_rules! foo {
86
}
97

108
foo!();
9+
10+
fn main() {}

src/test/ui/parser/macro/issue-33569.stderr

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
error: expected identifier, found `+`
2-
--> $DIR/issue-33569.rs:4:8
2+
--> $DIR/issue-33569.rs:2:8
33
|
44
LL | { $+ } => {
55
| ^
66

77
error: expected one of: `*`, `+`, or `?`
8-
--> $DIR/issue-33569.rs:6:13
8+
--> $DIR/issue-33569.rs:4:13
99
|
1010
LL | $(x)(y)
1111
| ^^^
1212

1313
error: missing fragment specifier
14-
--> $DIR/issue-33569.rs:4:8
14+
--> $DIR/issue-33569.rs:2:8
1515
|
1616
LL | { $+ } => {
1717
| ^
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
// aux-build:invalid-punct-ident.rs
22

3-
// We use `main` not found below as a witness for error recovery in proc macro expansion.
4-
5-
#[macro_use] //~ ERROR `main` function not found
3+
#[macro_use]
64
extern crate invalid_punct_ident;
75

86
lexer_failure!();
97
//~^ ERROR proc macro panicked
108
//~| ERROR unexpected closing delimiter: `)`
9+
10+
fn main() {
11+
let _recovery_witness: () = 0; //~ ERROR mismatched types
12+
}
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
11
error: unexpected closing delimiter: `)`
2-
--> $DIR/invalid-punct-ident-4.rs:8:1
2+
--> $DIR/invalid-punct-ident-4.rs:6:1
33
|
44
LL | lexer_failure!();
55
| ^^^^^^^^^^^^^^^^^ unexpected closing delimiter
66
|
77
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
88

99
error: proc macro panicked
10-
--> $DIR/invalid-punct-ident-4.rs:8:1
10+
--> $DIR/invalid-punct-ident-4.rs:6:1
1111
|
1212
LL | lexer_failure!();
1313
| ^^^^^^^^^^^^^^^^^
1414

15-
error[E0601]: `main` function not found in crate `invalid_punct_ident_4`
16-
--> $DIR/invalid-punct-ident-4.rs:5:1
15+
error[E0308]: mismatched types
16+
--> $DIR/invalid-punct-ident-4.rs:11:33
1717
|
18-
LL | / #[macro_use]
19-
LL | | extern crate invalid_punct_ident;
20-
LL | |
21-
LL | | lexer_failure!();
22-
| |_________________^ consider adding a `main` function to `$DIR/invalid-punct-ident-4.rs`
18+
LL | let _recovery_witness: () = 0;
19+
| -- ^ expected `()`, found integer
20+
| |
21+
| expected due to this
2322

2423
error: aborting due to 3 previous errors
2524

26-
For more information about this error, try `rustc --explain E0601`.
25+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)