diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-12-20 02:21:54 +0000 |
---|---|---|
committer | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2022-12-20 02:21:54 +0000 |
commit | 1152c86c920ae204a3e29250ce4512222ad269c1 (patch) | |
tree | 6337afdd89f0a3711f9a5ef20262c344230733e0 | |
parent | 94c0a6d75c96a39f50fc801f7787575dede48031 (diff) | |
parent | 9c422423a815342e55e7e9e2cca9d1d2077651f6 (diff) | |
download | no-panic-1152c86c920ae204a3e29250ce4512222ad269c1.tar.gz |
Snap for 9420774 from 9c422423a815342e55e7e9e2cca9d1d2077651f6 to udc-release
Change-Id: Iebebd0ff83ed7fddbfd9d0679503b64212aebbc5
-rw-r--r-- | .cargo_vcs_info.json | 7 | ||||
-rw-r--r-- | .clippy.toml | 1 | ||||
-rw-r--r-- | .github/workflows/ci.yml | 30 | ||||
-rw-r--r-- | Android.bp | 2 | ||||
-rw-r--r-- | Cargo.toml | 22 | ||||
-rw-r--r-- | Cargo.toml.orig | 10 | ||||
-rw-r--r-- | METADATA | 12 | ||||
-rw-r--r-- | README.md | 2 | ||||
-rw-r--r-- | src/lib.rs | 32 | ||||
-rw-r--r-- | tests/test.rs | 21 | ||||
-rw-r--r-- | tests/ui/trait-fn.rs | 12 | ||||
-rw-r--r-- | tests/ui/trait-fn.stderr | 5 |
12 files changed, 123 insertions, 33 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index a244221..b9117b2 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,5 +1,6 @@ { "git": { - "sha1": "bd3461a31006e0c46f76970db07d4054c12e9928" - } -} + "sha1": "dc6b36f0894f320b5e5c287131b0cb715f669aa5" + }, + "path_in_vcs": "" +}
\ No newline at end of file diff --git a/.clippy.toml b/.clippy.toml new file mode 100644 index 0000000..3d30690 --- /dev/null +++ b/.clippy.toml @@ -0,0 +1 @@ +msrv = "1.31.0" diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 921c271..ad357aa 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -5,6 +5,12 @@ on: pull_request: schedule: [cron: "40 1 * * *"] +permissions: + contents: read + +env: + RUSTFLAGS: -Dwarnings + jobs: test: name: Rust ${{matrix.rust}} @@ -12,9 +18,9 @@ jobs: strategy: fail-fast: false matrix: - rust: [nightly, beta, stable, 1.32.0] + rust: [nightly, beta, stable, 1.56.0] steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@master with: toolchain: ${{matrix.rust}} @@ -24,6 +30,24 @@ jobs: name: Rust 1.31.0 runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 - uses: dtolnay/rust-toolchain@1.31.0 - run: cargo build + + clippy: + name: Clippy + runs-on: ubuntu-latest + if: github.event_name != 'pull_request' + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/rust-toolchain@clippy + - run: cargo clippy --tests -- -Dclippy::all -Dclippy::pedantic + + outdated: + name: Outdated + runs-on: ubuntu-latest + if: github.event_name != 'pull_request' + steps: + - uses: actions/checkout@v3 + - uses: dtolnay/install@cargo-outdated + - run: cargo outdated --exit-code 1 @@ -41,7 +41,7 @@ rust_proc_macro { name: "libno_panic", crate_name: "no_panic", cargo_env_compat: true, - cargo_pkg_version: "0.1.15", + cargo_pkg_version: "0.1.16", srcs: ["src/lib.rs"], edition: "2018", rustlibs: [ @@ -3,28 +3,30 @@ # When uploading crates to the registry Cargo will automatically # "normalize" Cargo.toml files for maximal compatibility # with all versions of Cargo and also rewrite `path` dependencies -# to registry (e.g., crates.io) dependencies +# to registry (e.g., crates.io) dependencies. # -# If you believe there's an error in this file please file an -# issue against the rust-lang/cargo repository. If you're -# editing this file be aware that the upstream Cargo.toml -# will likely look very different (and much more reasonable) +# If you are reading this file be aware that the original Cargo.toml +# will likely look very different (and much more reasonable). +# See Cargo.toml.orig for the original contents. [package] edition = "2018" +rust-version = "1.31" name = "no-panic" -version = "0.1.15" +version = "0.1.16" authors = ["David Tolnay <dtolnay@gmail.com>"] description = "Attribute macro to require that the compiler prove a function can't ever panic." documentation = "https://docs.rs/no-panic" readme = "README.md" license = "MIT OR Apache-2.0" repository = "https://github.com/dtolnay/no-panic" + [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] [lib] proc-macro = true + [dependencies.proc-macro2] version = "1.0" @@ -34,5 +36,13 @@ version = "1.0" [dependencies.syn] version = "1.0" features = ["full"] + +[dev-dependencies.rustversion] +version = "1.0.9" + [dev-dependencies.tempfile] version = "3.0" + +[dev-dependencies.trybuild] +version = "1.0.69" +features = ["diff"] diff --git a/Cargo.toml.orig b/Cargo.toml.orig index f32a7f2..ab773e7 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,13 +1,13 @@ [package] name = "no-panic" -version = "0.1.15" +version = "0.1.16" authors = ["David Tolnay <dtolnay@gmail.com>"] +description = "Attribute macro to require that the compiler prove a function can't ever panic." +documentation = "https://docs.rs/no-panic" edition = "2018" license = "MIT OR Apache-2.0" -description = "Attribute macro to require that the compiler prove a function can't ever panic." repository = "https://github.com/dtolnay/no-panic" -documentation = "https://docs.rs/no-panic" -readme = "README.md" +rust-version = "1.31" [lib] proc-macro = true @@ -18,7 +18,9 @@ quote = "1.0" syn = { version = "1.0", features = ["full"] } [dev-dependencies] +rustversion = "1.0.9" tempfile = "3.0" +trybuild = { version = "1.0.69", features = ["diff"] } [package.metadata.docs.rs] targets = ["x86_64-unknown-linux-gnu"] @@ -1,3 +1,7 @@ +# This project was upgraded with external_updater. +# Usage: tools/external_updater/updater.sh update rust/crates/no-panic +# For more info, check https://cs.android.com/android/platform/superproject/+/master:tools/external_updater/README.md + name: "no-panic" description: "Attribute macro to require that the compiler prove a function can\'t ever panic." third_party { @@ -7,13 +11,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/no-panic/no-panic-0.1.15.crate" + value: "https://static.crates.io/crates/no-panic/no-panic-0.1.16.crate" } - version: "0.1.15" + version: "0.1.16" license_type: NOTICE last_upgrade_date { - year: 2020 + year: 2022 month: 12 - day: 29 + day: 13 } } @@ -3,7 +3,7 @@ [<img alt="github" src="https://img.shields.io/badge/github-dtolnay/no--panic-8da0cb?style=for-the-badge&labelColor=555555&logo=github" height="20">](https://github.com/dtolnay/no-panic) [<img alt="crates.io" src="https://img.shields.io/crates/v/no-panic.svg?style=for-the-badge&color=fc8d62&logo=rust" height="20">](https://crates.io/crates/no-panic) -[<img alt="docs.rs" src="https://img.shields.io/badge/docs.rs-no--panic-66c2a5?style=for-the-badge&labelColor=555555&logoColor=white&logo=data:image/svg+xml;base64,PHN2ZyByb2xlPSJpbWciIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmlld0JveD0iMCAwIDUxMiA1MTIiPjxwYXRoIGZpbGw9IiNmNWY1ZjUiIGQ9Ik00ODguNiAyNTAuMkwzOTIgMjE0VjEwNS41YzAtMTUtOS4zLTI4LjQtMjMuNC0zMy43bC0xMDAtMzcuNWMtOC4xLTMuMS0xNy4xLTMuMS0yNS4zIDBsLTEwMCAzNy41Yy0xNC4xIDUuMy0yMy40IDE4LjctMjMuNCAzMy43VjIxNGwtOTYuNiAzNi4yQzkuMyAyNTUuNSAwIDI2OC45IDAgMjgzLjlWMzk0YzAgMTMuNiA3LjcgMjYuMSAxOS45IDMyLjJsMTAwIDUwYzEwLjEgNS4xIDIyLjEgNS4xIDMyLjIgMGwxMDMuOS01MiAxMDMuOSA1MmMxMC4xIDUuMSAyMi4xIDUuMSAzMi4yIDBsMTAwLTUwYzEyLjItNi4xIDE5LjktMTguNiAxOS45LTMyLjJWMjgzLjljMC0xNS05LjMtMjguNC0yMy40LTMzLjd6TTM1OCAyMTQuOGwtODUgMzEuOXYtNjguMmw4NS0zN3Y3My4zek0xNTQgMTA0LjFsMTAyLTM4LjIgMTAyIDM4LjJ2LjZsLTEwMiA0MS40LTEwMi00MS40di0uNnptODQgMjkxLjFsLTg1IDQyLjV2LTc5LjFsODUtMzguOHY3NS40em0wLTExMmwtMTAyIDQxLjQtMTAyLTQxLjR2LS42bDEwMi0zOC4yIDEwMiAzOC4ydi42em0yNDAgMTEybC04NSA0Mi41di03OS4xbDg1LTM4Ljh2NzUuNHptMC0xMTJsLTEwMiA0MS40LTEwMi00MS40di0uNmwxMDItMzguMiAxMDIgMzguMnYuNnoiPjwvcGF0aD48L3N2Zz4K" height="20">](https://docs.rs/no-panic) +[<img alt="docs.rs" src="https://img.shields.io/badge/docs.rs-no--panic-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs" height="20">](https://docs.rs/no-panic) [<img alt="build status" src="https://img.shields.io/github/workflow/status/dtolnay/no-panic/CI/master?style=for-the-badge" height="20">](https://github.com/dtolnay/no-panic/actions?query=branch%3Amaster) A Rust attribute macro to require that the compiler prove a function can't ever @@ -2,7 +2,7 @@ //! //! [github]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo=github //! [crates-io]: https://img.shields.io/badge/crates.io-fc8d62?style=for-the-badge&labelColor=555555&logo=rust -//! [docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logoColor=white&logo=data:image/svg+xml;base64,PHN2ZyByb2xlPSJpbWciIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgdmlld0JveD0iMCAwIDUxMiA1MTIiPjxwYXRoIGZpbGw9IiNmNWY1ZjUiIGQ9Ik00ODguNiAyNTAuMkwzOTIgMjE0VjEwNS41YzAtMTUtOS4zLTI4LjQtMjMuNC0zMy43bC0xMDAtMzcuNWMtOC4xLTMuMS0xNy4xLTMuMS0yNS4zIDBsLTEwMCAzNy41Yy0xNC4xIDUuMy0yMy40IDE4LjctMjMuNCAzMy43VjIxNGwtOTYuNiAzNi4yQzkuMyAyNTUuNSAwIDI2OC45IDAgMjgzLjlWMzk0YzAgMTMuNiA3LjcgMjYuMSAxOS45IDMyLjJsMTAwIDUwYzEwLjEgNS4xIDIyLjEgNS4xIDMyLjIgMGwxMDMuOS01MiAxMDMuOSA1MmMxMC4xIDUuMSAyMi4xIDUuMSAzMi4yIDBsMTAwLTUwYzEyLjItNi4xIDE5LjktMTguNiAxOS45LTMyLjJWMjgzLjljMC0xNS05LjMtMjguNC0yMy40LTMzLjd6TTM1OCAyMTQuOGwtODUgMzEuOXYtNjguMmw4NS0zN3Y3My4zek0xNTQgMTA0LjFsMTAyLTM4LjIgMTAyIDM4LjJ2LjZsLTEwMiA0MS40LTEwMi00MS40di0uNnptODQgMjkxLjFsLTg1IDQyLjV2LTc5LjFsODUtMzguOHY3NS40em0wLTExMmwtMTAyIDQxLjQtMTAyLTQxLjR2LS42bDEwMi0zOC4yIDEwMiAzOC4ydi42em0yNDAgMTEybC04NSA0Mi41di03OS4xbDg1LTM4Ljh2NzUuNHptMC0xMTJsLTEwMiA0MS40LTEwMi00MS40di0uNmwxMDItMzguMiAxMDIgMzguMnYuNnoiPjwvcGF0aD48L3N2Zz4K +//! [docs-rs]: https://img.shields.io/badge/docs.rs-66c2a5?style=for-the-badge&labelColor=555555&logo=docs.rs //! //! <br> //! @@ -119,19 +119,37 @@ //! [Kixunil]: https://github.com/Kixunil //! [`dont_panic`]: https://github.com/Kixunil/dont_panic +#![allow(clippy::doc_markdown, clippy::missing_panics_doc)] + extern crate proc_macro; use proc_macro::TokenStream; -use proc_macro2::Span; +use proc_macro2::{Span, TokenStream as TokenStream2}; use quote::quote; -use syn::{parse_macro_input, parse_quote, Attribute, FnArg, Ident, ItemFn, PatType, ReturnType}; +use syn::parse::{Nothing, Result}; +use syn::{parse_quote, Attribute, FnArg, Ident, ItemFn, PatType, ReturnType}; #[proc_macro_attribute] -pub fn no_panic(args: TokenStream, function: TokenStream) -> TokenStream { - assert!(args.is_empty()); +pub fn no_panic(args: TokenStream, input: TokenStream) -> TokenStream { + let args = TokenStream2::from(args); + let input = TokenStream2::from(input); + let expanded = match parse(args, input.clone()) { + Ok(function) => expand_no_panic(function), + Err(parse_error) => { + let compile_error = parse_error.to_compile_error(); + quote!(#compile_error #input) + } + }; + TokenStream::from(expanded) +} - let mut function = parse_macro_input!(function as ItemFn); +fn parse(args: TokenStream2, input: TokenStream2) -> Result<ItemFn> { + let function: ItemFn = syn::parse2(input)?; + let _: Nothing = syn::parse2::<Nothing>(args)?; + Ok(function) +} +fn expand_no_panic(mut function: ItemFn) -> TokenStream2 { let mut move_self = None; let mut arg_pat = Vec::new(); let mut arg_val = Vec::new(); @@ -200,5 +218,5 @@ pub fn no_panic(args: TokenStream, function: TokenStream) -> TokenStream { __result })); - TokenStream::from(quote!(#function)) + quote!(#function) } diff --git a/tests/test.rs b/tests/test.rs index a7da4d4..b14d92b 100644 --- a/tests/test.rs +++ b/tests/test.rs @@ -1,6 +1,13 @@ #[macro_use] mod compiletest; +#[rustversion::attr(not(nightly), ignore)] +#[test] +fn ui() { + let t = trybuild::TestCases::new(); + t.compile_fail("tests/ui/*.rs"); +} + assert_no_panic! { mod test_readme { #[no_panic] @@ -119,21 +126,27 @@ assert_no_panic! { } } - mod test_self_in_vec { + mod test_self_in_macro { struct S { data: usize, } + macro_rules! id { + ($expr:expr) => { + $expr + }; + } + impl S { #[no_panic] - fn get_mut(&mut self) -> Vec<usize> { - vec![self.data] + fn get_mut(&mut self) -> usize { + id![self.data] } } fn main() { let mut s = S { data: 0 }; - println!("{}", s.get_mut()[0]); + println!("{}", s.get_mut()); } } diff --git a/tests/ui/trait-fn.rs b/tests/ui/trait-fn.rs new file mode 100644 index 0000000..d2c650f --- /dev/null +++ b/tests/ui/trait-fn.rs @@ -0,0 +1,12 @@ +use no_panic::no_panic; + +trait Trait { + #[no_panic] + fn f(); +} + +impl Trait for i32 { + fn f() {} +} + +fn main() {} diff --git a/tests/ui/trait-fn.stderr b/tests/ui/trait-fn.stderr new file mode 100644 index 0000000..b4215c8 --- /dev/null +++ b/tests/ui/trait-fn.stderr @@ -0,0 +1,5 @@ +error: expected curly braces + --> tests/ui/trait-fn.rs:5:11 + | +5 | fn f(); + | ^ |