Skip to content

Commit 9ad04b9

Browse files
committed
Add warning for a parameter list with an attribute but no parameters
1 parent dbc7924 commit 9ad04b9

File tree

3 files changed

+28
-10
lines changed

3 files changed

+28
-10
lines changed

src/libsyntax/parse/parser.rs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5545,13 +5545,25 @@ impl<'a> Parser<'a> {
55455545
params.push(self.parse_ty_param(attrs)?);
55465546
} else {
55475547
// Check for trailing attributes and stop parsing.
5548-
if !attrs.is_empty() && !params.is_empty() {
5549-
self.struct_span_err(
5550-
attrs[0].span,
5551-
&format!("trailing attribute after generic parameter"),
5552-
)
5553-
.span_label(attrs[0].span, "attributes must go before parameters")
5554-
.emit();
5548+
if !attrs.is_empty() {
5549+
if !params.is_empty() {
5550+
self.struct_span_err(
5551+
attrs[0].span,
5552+
&format!("trailing attribute after generic parameter"),
5553+
)
5554+
.span_label(attrs[0].span, "attributes must go before parameters")
5555+
.emit();
5556+
} else {
5557+
self.struct_span_err(
5558+
attrs[0].span,
5559+
&format!("attribute without generic parameters"),
5560+
)
5561+
.span_label(
5562+
attrs[0].span,
5563+
"attributes are only permitted when preceding parameters",
5564+
)
5565+
.emit();
5566+
}
55555567
}
55565568
break
55575569
}
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
// run-pass
2-
3-
fn foo<#[attr]>() {} // ok
1+
fn foo<#[attr]>() {} //~ ERROR attribute without generic parameters
42

53
fn main() {}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: attribute without generic parameters
2+
--> $DIR/attribute-with-no-generics-in-parameter-list.rs:1:8
3+
|
4+
LL | fn foo<#[attr]>() {} //~ ERROR attribute without generic parameters
5+
| ^^^^^^^ attributes are only permitted when preceding parameters
6+
7+
error: aborting due to previous error
8+

0 commit comments

Comments
 (0)