Auto merge of #88680 - ehuss:more-attr-validation, r=petrochenkov
Validate builtin attributes for macro args. This adds some validation for `path`, `crate_type`, and `recursion_limit` attributes so that they will now return an error if you attempt to pass a macro into them (such as `#[path = foo!()]`). Previously, the attribute would be completely ignored. These attributes are special because their values need to be known before/during expansion. cc #87681
This commit is contained in:
commit
f6e6ddc09d
21 changed files with 211 additions and 76 deletions
|
|
@ -30,13 +30,13 @@ error: malformed `register_attr` attribute input
|
|||
--> $DIR/register-attr-tool-fail.rs:4:1
|
||||
|
|
||||
LL | #![register_attr]
|
||||
| ^^^^^^^^^^^^^^^^^ help: must be of the form: `#[register_attr(attr1, attr2, ...)]`
|
||||
| ^^^^^^^^^^^^^^^^^ help: must be of the form: `#![register_attr(attr1, attr2, ...)]`
|
||||
|
||||
error: malformed `register_tool` attribute input
|
||||
--> $DIR/register-attr-tool-fail.rs:5:1
|
||||
|
|
||||
LL | #![register_tool]
|
||||
| ^^^^^^^^^^^^^^^^^ help: must be of the form: `#[register_tool(tool1, tool2, ...)]`
|
||||
| ^^^^^^^^^^^^^^^^^ help: must be of the form: `#![register_tool(tool1, tool2, ...)]`
|
||||
|
||||
error: aborting due to 6 previous errors
|
||||
|
||||
|
|
|
|||
|
|
@ -20,13 +20,13 @@ error: malformed `feature` attribute input
|
|||
--> $DIR/gated-bad-feature.rs:5:1
|
||||
|
|
||||
LL | #![feature]
|
||||
| ^^^^^^^^^^^ help: must be of the form: `#[feature(name1, name1, ...)]`
|
||||
| ^^^^^^^^^^^ help: must be of the form: `#![feature(name1, name1, ...)]`
|
||||
|
||||
error: malformed `feature` attribute input
|
||||
--> $DIR/gated-bad-feature.rs:6:1
|
||||
|
|
||||
LL | #![feature = "foo"]
|
||||
| ^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[feature(name1, name1, ...)]`
|
||||
| ^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#![feature(name1, name1, ...)]`
|
||||
|
||||
error: aborting due to 5 previous errors
|
||||
|
||||
|
|
|
|||
7
src/test/ui/invalid/invalid-crate-type-macro.rs
Normal file
7
src/test/ui/invalid/invalid-crate-type-macro.rs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#![crate_type = foo!()] //~ ERROR malformed `crate_type` attribute
|
||||
|
||||
macro_rules! foo {
|
||||
() => {"rlib"};
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
8
src/test/ui/invalid/invalid-crate-type-macro.stderr
Normal file
8
src/test/ui/invalid/invalid-crate-type-macro.stderr
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
error: malformed `crate_type` attribute input
|
||||
--> $DIR/invalid-crate-type-macro.rs:1:1
|
||||
|
|
||||
LL | #![crate_type = foo!()]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#![crate_type = "bin|lib|..."]`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
@ -2,7 +2,7 @@ error: malformed `crate_type` attribute input
|
|||
--> $DIR/invalid_crate_type_syntax.rs:2:1
|
||||
|
|
||||
LL | #![crate_type(lib)]
|
||||
| ^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#[crate_type = "bin|lib|..."]`
|
||||
| ^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#![crate_type = "bin|lib|..."]`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ error: malformed `deny` attribute input
|
|||
--> $DIR/lint-malformed.rs:1:1
|
||||
|
|
||||
LL | #![deny = "foo"]
|
||||
| ^^^^^^^^^^^^^^^^ help: must be of the form: `#[deny(lint1, lint2, ..., /*opt*/ reason = "...")]`
|
||||
| ^^^^^^^^^^^^^^^^ help: must be of the form: `#![deny(lint1, lint2, ..., /*opt*/ reason = "...")]`
|
||||
|
||||
error[E0452]: malformed lint attribute input
|
||||
--> $DIR/lint-malformed.rs:2:10
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ error: malformed `plugin` attribute input
|
|||
--> $DIR/malformed-plugin-1.rs:2:1
|
||||
|
|
||||
LL | #![plugin]
|
||||
| ^^^^^^^^^^ help: must be of the form: `#[plugin(name)]`
|
||||
| ^^^^^^^^^^ help: must be of the form: `#![plugin(name)]`
|
||||
|
||||
warning: use of deprecated attribute `plugin`: compiler plugins are deprecated. See https://github.com/rust-lang/rust/pull/64675
|
||||
--> $DIR/malformed-plugin-1.rs:2:1
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ error: malformed `plugin` attribute input
|
|||
--> $DIR/malformed-plugin-2.rs:2:1
|
||||
|
|
||||
LL | #![plugin="bleh"]
|
||||
| ^^^^^^^^^^^^^^^^^ help: must be of the form: `#[plugin(name)]`
|
||||
| ^^^^^^^^^^^^^^^^^ help: must be of the form: `#![plugin(name)]`
|
||||
|
||||
warning: use of deprecated attribute `plugin`: compiler plugins are deprecated. See https://github.com/rust-lang/rust/pull/64675
|
||||
--> $DIR/malformed-plugin-2.rs:2:1
|
||||
|
|
|
|||
4
src/test/ui/modules/path-invalid-form.rs
Normal file
4
src/test/ui/modules/path-invalid-form.rs
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
#[path = 123] //~ ERROR malformed `path` attribute
|
||||
mod foo;
|
||||
|
||||
fn main() {}
|
||||
8
src/test/ui/modules/path-invalid-form.stderr
Normal file
8
src/test/ui/modules/path-invalid-form.stderr
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
error: malformed `path` attribute input
|
||||
--> $DIR/path-invalid-form.rs:1:1
|
||||
|
|
||||
LL | #[path = 123]
|
||||
| ^^^^^^^^^^^^^ help: must be of the form: `#[path = "file"]`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
8
src/test/ui/modules/path-macro.rs
Normal file
8
src/test/ui/modules/path-macro.rs
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
macro_rules! foo {
|
||||
() => {"bar.rs"};
|
||||
}
|
||||
|
||||
#[path = foo!()] //~ ERROR malformed `path` attribute
|
||||
mod abc;
|
||||
|
||||
fn main() {}
|
||||
8
src/test/ui/modules/path-macro.stderr
Normal file
8
src/test/ui/modules/path-macro.stderr
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
error: malformed `path` attribute input
|
||||
--> $DIR/path-macro.rs:5:1
|
||||
|
|
||||
LL | #[path = foo!()]
|
||||
| ^^^^^^^^^^^^^^^^ help: must be of the form: `#[path = "file"]`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
@ -2,7 +2,7 @@ error: malformed `crate_type` attribute input
|
|||
--> $DIR/no_crate_type.rs:2:1
|
||||
|
|
||||
LL | #![crate_type]
|
||||
| ^^^^^^^^^^^^^^ help: must be of the form: `#[crate_type = "bin|lib|..."]`
|
||||
| ^^^^^^^^^^^^^^ help: must be of the form: `#![crate_type = "bin|lib|..."]`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
|
|
|
|||
3
src/test/ui/recursion_limit/invalid_digit_type.rs
Normal file
3
src/test/ui/recursion_limit/invalid_digit_type.rs
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
#![recursion_limit = 123] //~ ERROR malformed `recursion_limit` attribute
|
||||
|
||||
fn main() {}
|
||||
8
src/test/ui/recursion_limit/invalid_digit_type.stderr
Normal file
8
src/test/ui/recursion_limit/invalid_digit_type.stderr
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
error: malformed `recursion_limit` attribute input
|
||||
--> $DIR/invalid_digit_type.rs:1:1
|
||||
|
|
||||
LL | #![recursion_limit = 123]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#![recursion_limit = "N"]`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
7
src/test/ui/recursion_limit/invalid_macro.rs
Normal file
7
src/test/ui/recursion_limit/invalid_macro.rs
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
#![recursion_limit = foo!()] //~ ERROR malformed `recursion_limit` attribute
|
||||
|
||||
macro_rules! foo {
|
||||
() => {"128"};
|
||||
}
|
||||
|
||||
fn main() {}
|
||||
8
src/test/ui/recursion_limit/invalid_macro.stderr
Normal file
8
src/test/ui/recursion_limit/invalid_macro.stderr
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
error: malformed `recursion_limit` attribute input
|
||||
--> $DIR/invalid_macro.rs:1:1
|
||||
|
|
||||
LL | #![recursion_limit = foo!()]
|
||||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: must be of the form: `#![recursion_limit = "N"]`
|
||||
|
||||
error: aborting due to previous error
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue