-
Notifications
You must be signed in to change notification settings - Fork 447
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restrict which
cfg
attributes can be used (#2313)
* Allow only whitelisted `cfg` attributes * Add tests * Update changelog * Add unit tests * Panic at unreachable code * Adjust for testing constructor instead
- Loading branch information
Showing
19 changed files
with
479 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
crates/ink/tests/ui/contract/fail/cfg-forbidden-usage-01.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#[ink::contract] | ||
mod contract { | ||
#[ink(storage)] | ||
pub struct Contract {} | ||
|
||
impl Contract { | ||
#[ink(constructor)] | ||
pub fn constructor() -> Self { | ||
Self {} | ||
} | ||
|
||
#[ink(message)] | ||
pub fn message1(&self) {} | ||
|
||
#[ink(message)] | ||
#[cfg(any(test, target_family = "wasm"))] | ||
pub fn message2(&self) {} | ||
} | ||
} | ||
|
||
fn main() {} |
12 changes: 12 additions & 0 deletions
12
crates/ink/tests/ui/contract/fail/cfg-forbidden-usage-01.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
error: This `cfg` attribute is not allowed. | ||
|
||
Allowed in `#[cfg(…)]`: | ||
- `test` | ||
- `feature` (without `std`) | ||
- `any` | ||
- `not` | ||
- `all` | ||
--> tests/ui/contract/fail/cfg-forbidden-usage-01.rs:16:25 | ||
| | ||
16 | #[cfg(any(test, target_family = "wasm"))] | ||
| ^^^^^^^^^^^^^ |
21 changes: 21 additions & 0 deletions
21
crates/ink/tests/ui/contract/fail/cfg-forbidden-usage-02.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#[ink::contract] | ||
mod contract { | ||
#[ink(storage)] | ||
pub struct Contract {} | ||
|
||
impl Contract { | ||
#[ink(constructor)] | ||
pub fn constructor() -> Self { | ||
Self {} | ||
} | ||
|
||
#[ink(message)] | ||
pub fn message1(&self) {} | ||
|
||
#[ink(message)] | ||
#[cfg(not(feature = "std"))] | ||
pub fn message2(&self) {} | ||
} | ||
} | ||
|
||
fn main() {} |
12 changes: 12 additions & 0 deletions
12
crates/ink/tests/ui/contract/fail/cfg-forbidden-usage-02.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
error: The feature `std` is not allowed in `cfg`. | ||
|
||
Allowed in `#[cfg(…)]`: | ||
- `test` | ||
- `feature` (without `std`) | ||
- `any` | ||
- `not` | ||
- `all` | ||
--> tests/ui/contract/fail/cfg-forbidden-usage-02.rs:16:19 | ||
| | ||
16 | #[cfg(not(feature = "std"))] | ||
| ^^^^^^^ |
21 changes: 21 additions & 0 deletions
21
crates/ink/tests/ui/contract/fail/cfg-forbidden-usage-03.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#[ink::contract] | ||
mod contract { | ||
#[ink(storage)] | ||
pub struct Contract {} | ||
|
||
impl Contract { | ||
#[ink(constructor)] | ||
pub fn constructor() -> Self { | ||
Self {} | ||
} | ||
|
||
#[ink(message)] | ||
pub fn message1(&self) {} | ||
|
||
#[ink(message)] | ||
#[cfg(any(not(feature = "std")))] | ||
pub fn message2(&self) {} | ||
} | ||
} | ||
|
||
fn main() {} |
12 changes: 12 additions & 0 deletions
12
crates/ink/tests/ui/contract/fail/cfg-forbidden-usage-03.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
error: The feature `std` is not allowed in `cfg`. | ||
|
||
Allowed in `#[cfg(…)]`: | ||
- `test` | ||
- `feature` (without `std`) | ||
- `any` | ||
- `not` | ||
- `all` | ||
--> tests/ui/contract/fail/cfg-forbidden-usage-03.rs:16:23 | ||
| | ||
16 | #[cfg(any(not(feature = "std")))] | ||
| ^^^^^^^ |
Oops, something went wrong.