expand: Do not ICE when a legacy AST-based macro attribute produces and empty expression
This commit is contained in:
parent
97717a5618
commit
cd22425990
@ -735,7 +735,14 @@ fn expand_invoc(
|
||||
});
|
||||
}
|
||||
};
|
||||
fragment_kind.expect_from_annotatables(items)
|
||||
if fragment_kind == AstFragmentKind::Expr && items.is_empty() {
|
||||
let msg =
|
||||
"removing an expression is not supported in this position";
|
||||
self.cx.span_err(span, msg);
|
||||
fragment_kind.dummy(span)
|
||||
} else {
|
||||
fragment_kind.expect_from_annotatables(items)
|
||||
}
|
||||
}
|
||||
Err(mut err) => {
|
||||
err.emit();
|
||||
|
11
src/test/ui/macros/attr-empty-expr.rs
Normal file
11
src/test/ui/macros/attr-empty-expr.rs
Normal file
@ -0,0 +1,11 @@
|
||||
// AST-based macro attributes expanding to an empty expression produce an error and not ICE.
|
||||
|
||||
#![feature(custom_test_frameworks)]
|
||||
#![feature(stmt_expr_attributes)]
|
||||
#![feature(test)]
|
||||
|
||||
fn main() {
|
||||
let _ = #[test] 0; //~ ERROR removing an expression is not supported in this position
|
||||
let _ = #[bench] 1; //~ ERROR removing an expression is not supported in this position
|
||||
let _ = #[test_case] 2; //~ ERROR removing an expression is not supported in this position
|
||||
}
|
20
src/test/ui/macros/attr-empty-expr.stderr
Normal file
20
src/test/ui/macros/attr-empty-expr.stderr
Normal file
@ -0,0 +1,20 @@
|
||||
error: removing an expression is not supported in this position
|
||||
--> $DIR/attr-empty-expr.rs:8:13
|
||||
|
|
||||
LL | let _ = #[test] 0;
|
||||
| ^^^^^^^
|
||||
|
||||
error: removing an expression is not supported in this position
|
||||
--> $DIR/attr-empty-expr.rs:9:13
|
||||
|
|
||||
LL | let _ = #[bench] 1;
|
||||
| ^^^^^^^^
|
||||
|
||||
error: removing an expression is not supported in this position
|
||||
--> $DIR/attr-empty-expr.rs:10:13
|
||||
|
|
||||
LL | let _ = #[test_case] 2;
|
||||
| ^^^^^^^^^^^^
|
||||
|
||||
error: aborting due to 3 previous errors
|
||||
|
Loading…
Reference in New Issue
Block a user