226edf64fa
Attribute values must be literals. The error you get when that doesn't hold is pretty bad, e.g.: ``` unexpected expression: 1 + 1 ``` You also get the same error if the attribute value is a literal, but an invalid literal, e.g.: ``` unexpected expression: "foo"suffix ``` This commit does two things. - Changes the error message to "attribute value must be a literal", which gives a better idea of what the problem is and how to fix it. It also no longer prints the invalid expression, because the carets below highlight it anyway. - Separates the "not a literal" case from the "invalid literal" case. Which means invalid literals now get the specific error at the literal level, rather than at the attribute level.
46 lines
1.6 KiB
Rust
46 lines
1.6 KiB
Rust
#![feature(rustc_attrs)]
|
|
|
|
extern
|
|
"C"suffix //~ ERROR suffixes on string literals are invalid
|
|
fn foo() {}
|
|
|
|
extern
|
|
"C"suffix //~ ERROR suffixes on string literals are invalid
|
|
{}
|
|
|
|
fn main() {
|
|
""suffix; //~ ERROR suffixes on string literals are invalid
|
|
b""suffix; //~ ERROR suffixes on byte string literals are invalid
|
|
r#""#suffix; //~ ERROR suffixes on string literals are invalid
|
|
br#""#suffix; //~ ERROR suffixes on byte string literals are invalid
|
|
'a'suffix; //~ ERROR suffixes on char literals are invalid
|
|
b'a'suffix; //~ ERROR suffixes on byte literals are invalid
|
|
|
|
1234u1024; //~ ERROR invalid width `1024` for integer literal
|
|
1234i1024; //~ ERROR invalid width `1024` for integer literal
|
|
1234f1024; //~ ERROR invalid width `1024` for float literal
|
|
1234.5f1024; //~ ERROR invalid width `1024` for float literal
|
|
|
|
1234suffix; //~ ERROR invalid suffix `suffix` for number literal
|
|
0b101suffix; //~ ERROR invalid suffix `suffix` for number literal
|
|
1.0suffix; //~ ERROR invalid suffix `suffix` for float literal
|
|
1.0e10suffix; //~ ERROR invalid suffix `suffix` for float literal
|
|
}
|
|
|
|
#[rustc_dummy = "string"suffix]
|
|
//~^ ERROR suffixes on string literals are invalid
|
|
fn f() {}
|
|
|
|
#[must_use = "string"suffix]
|
|
//~^ ERROR suffixes on string literals are invalid
|
|
//~| ERROR malformed `must_use` attribute input
|
|
fn g() {}
|
|
|
|
#[link(name = "string"suffix)]
|
|
//~^ ERROR suffixes on string literals are invalid
|
|
extern "C" {}
|
|
|
|
#[rustc_layout_scalar_valid_range_start(0suffix)]
|
|
//~^ ERROR invalid suffix `suffix` for number literal
|
|
struct S;
|