diff --git a/Cargo.lock b/Cargo.lock index 551d0ea..4610c7b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -27,12 +27,46 @@ version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801" +[[package]] +name = "equivalent" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "877a4ace8713b0bcf2a4e7eec82529c029f1d0619886d18145fea96c3ffe5c0f" + [[package]] name = "find-msvc-tools" version = "0.1.4" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "52051878f80a721bb68ebfbc930e07b65ba72f2da88968ea5c06fd6ca3d3a127" +[[package]] +name = "glob" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0cc23270f6e1808e30a928bdc84dea0b9b4136a8bc82338574f23baf47bbd280" + +[[package]] +name = "hashbrown" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" + +[[package]] +name = "indexmap" +version = "2.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d466e9454f08e4a911e14806c24e16fba1b4c121d1ea474396f396069cf949d9" +dependencies = [ + "equivalent", + "hashbrown", +] + +[[package]] +name = "itoa" +version = "1.0.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f42a60cbdf9a97f5d2305f08a87dc4e09308d1276d28c869c684d7777685682" + [[package]] name = "libc" version = "0.2.177" @@ -111,6 +145,28 @@ dependencies = [ "syn", ] +[[package]] +name = "serde_json" +version = "1.0.150" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e8014e44b4736ed0538adeecded0fce2a272f22dc9578a7eb6b2d9993c74cfb9" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_spanned" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6662b5879511e06e8999a8a235d848113e942c9124f211511b16466ee2995f26" +dependencies = [ + "serde_core", +] + [[package]] name = "shlex" version = "1.3.0" @@ -137,6 +193,7 @@ dependencies = [ "serde", "stacker", "stacksafe-macro", + "trybuild", ] [[package]] @@ -159,12 +216,90 @@ dependencies = [ "unicode-ident", ] +[[package]] +name = "target-triple" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "591ef38edfb78ca4771ee32cf494cb8771944bee237a9b91fc9c1424ac4b777b" + +[[package]] +name = "termcolor" +version = "1.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "06794f8f6c5c898b3275aebefa6b8a1cb24cd2c6c79397ab15774837a0bc5755" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "toml" +version = "1.1.2+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "81f3d15e84cbcd896376e6730314d59fb5a87f31e4b038454184435cd57defee" +dependencies = [ + "indexmap", + "serde_core", + "serde_spanned", + "toml_datetime", + "toml_parser", + "toml_writer", + "winnow", +] + +[[package]] +name = "toml_datetime" +version = "1.1.1+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3165f65f62e28e0115a00b2ebdd37eb6f3b641855f9d636d3cd4103767159ad7" +dependencies = [ + "serde_core", +] + +[[package]] +name = "toml_parser" +version = "1.1.2+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2abe9b86193656635d2411dc43050282ca48aa31c2451210f4202550afb7526" +dependencies = [ + "winnow", +] + +[[package]] +name = "toml_writer" +version = "1.1.1+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "756daf9b1013ebe47a8776667b466417e2d4c5679d441c26230efd9ef78692db" + +[[package]] +name = "trybuild" +version = "1.0.116" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47c635f0191bd3a2941013e5062667100969f8c4e9cd787c14f977265d73616e" +dependencies = [ + "glob", + "serde", + "serde_derive", + "serde_json", + "target-triple", + "termcolor", + "toml", +] + [[package]] name = "unicode-ident" version = "1.0.22" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9312f7c4f6ff9069b165498234ce8be658059c6728633667c526e27dc2cf1df5" +[[package]] +name = "winapi-util" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" +dependencies = [ + "windows-sys", +] + [[package]] name = "windows-link" version = "0.2.1" @@ -179,3 +314,15 @@ checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" dependencies = [ "windows-link", ] + +[[package]] +name = "winnow" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0592e1c9d151f854e6fd382574c3a0855250e1d9b2f99d9281c6e6391af352f1" + +[[package]] +name = "zmij" +version = "1.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8848ee67ecc8aedbaf3e4122217aff892639231befc6a1b58d29fff4c2cabaa" diff --git a/Cargo.toml b/Cargo.toml index 1987e28..74e5ce1 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -34,3 +34,4 @@ quote = { version = "1.0.45" } serde = { version = "1.0.228" } stacker = { version = "0.1.24" } syn = { version = "2.0.117" } +trybuild = { version = "1.0.116" } diff --git a/stacksafe/Cargo.toml b/stacksafe/Cargo.toml index 1ed968d..dccb4e9 100644 --- a/stacksafe/Cargo.toml +++ b/stacksafe/Cargo.toml @@ -39,3 +39,6 @@ serde = ["dep:serde"] serde = { workspace = true, optional = true } stacker = { workspace = true } stacksafe-macro = { workspace = true } + +[dev-dependencies] +trybuild = { workspace = true } diff --git a/stacksafe/tests/ui.rs b/stacksafe/tests/ui.rs new file mode 100644 index 0000000..699213a --- /dev/null +++ b/stacksafe/tests/ui.rs @@ -0,0 +1,19 @@ +// Copyright 2025 FastLabs Developers +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#[test] +fn ui() { + let t = trybuild::TestCases::new(); + t.compile_fail("tests/ui/*.rs"); +} diff --git a/stacksafe/tests/ui/async_function.rs b/stacksafe/tests/ui/async_function.rs new file mode 100644 index 0000000..a753fae --- /dev/null +++ b/stacksafe/tests/ui/async_function.rs @@ -0,0 +1,20 @@ +// Copyright 2025 FastLabs Developers +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use stacksafe::stacksafe; + +#[stacksafe] +async fn unsupported() {} + +fn main() {} diff --git a/stacksafe/tests/ui/async_function.stderr b/stacksafe/tests/ui/async_function.stderr new file mode 100644 index 0000000..94518a9 --- /dev/null +++ b/stacksafe/tests/ui/async_function.stderr @@ -0,0 +1,5 @@ +error: #[stacksafe] does not support async functions + --> tests/ui/async_function.rs:18:1 + | +18 | async fn unsupported() {} + | ^^^^^ diff --git a/stacksafe/tests/ui/non_function_item.rs b/stacksafe/tests/ui/non_function_item.rs new file mode 100644 index 0000000..9110940 --- /dev/null +++ b/stacksafe/tests/ui/non_function_item.rs @@ -0,0 +1,20 @@ +// Copyright 2025 FastLabs Developers +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use stacksafe::stacksafe; + +#[stacksafe] +struct NotAFunction; + +fn main() {} diff --git a/stacksafe/tests/ui/non_function_item.stderr b/stacksafe/tests/ui/non_function_item.stderr new file mode 100644 index 0000000..2d024fe --- /dev/null +++ b/stacksafe/tests/ui/non_function_item.stderr @@ -0,0 +1,7 @@ +error: #[stacksafe] can only be applied to functions + --> tests/ui/non_function_item.rs:17:1 + | +17 | #[stacksafe] + | ^^^^^^^^^^^^ + | + = note: this error originates in the attribute macro `stacksafe` (in Nightly builds, run with -Z macro-backtrace for more info) diff --git a/stacksafe/tests/ui/unknown_parameter.rs b/stacksafe/tests/ui/unknown_parameter.rs new file mode 100644 index 0000000..bdb26b3 --- /dev/null +++ b/stacksafe/tests/ui/unknown_parameter.rs @@ -0,0 +1,20 @@ +// Copyright 2025 FastLabs Developers +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +use stacksafe::stacksafe; + +#[stacksafe(unknown = true)] +fn unsupported() {} + +fn main() {} diff --git a/stacksafe/tests/ui/unknown_parameter.stderr b/stacksafe/tests/ui/unknown_parameter.stderr new file mode 100644 index 0000000..fd208ae --- /dev/null +++ b/stacksafe/tests/ui/unknown_parameter.stderr @@ -0,0 +1,5 @@ +error: unknown attribute parameter `unknown` + --> tests/ui/unknown_parameter.rs:17:13 + | +17 | #[stacksafe(unknown = true)] + | ^^^^^^^