Skip to content

Commit c89846c

Browse files
committed
Forbid #[test] attributes on non-optional expressions.
1 parent 66b9ade commit c89846c

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

src/libsyntax/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ impl<'a> CfgFolder for StripUnconfigured<'a> {
134134
}
135135

136136
fn visit_unremovable_expr(&mut self, expr: &ast::Expr) {
137-
if let Some(attr) = expr.attrs().iter().find(|a| is_cfg(a)) {
137+
if let Some(attr) = expr.attrs().iter().find(|a| is_cfg(a) || is_test_or_bench(a)) {
138138
let msg = "removing an expression is not supported in this position";
139139
self.diag.diag.span_err(attr.span, msg);
140140
}

src/test/compile-fail/cfg-non-opt-expr.rs

+2
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,6 @@ fn main() {
1717
//~^ ERROR removing an expression is not supported in this position
1818
let _ = [1, 2, 3][#[cfg(unset)] 1];
1919
//~^ ERROR removing an expression is not supported in this position
20+
let _ = #[test] ();
21+
//~^ ERROR removing an expression is not supported in this position
2022
}

0 commit comments

Comments
 (0)