aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Vander Stoep <jeffv@google.com>2023-03-07 04:20:24 +0000
committerAutomerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>2023-03-07 04:20:24 +0000
commita6a35bb62f9568faf38a058bfeb4f919cf1599db (patch)
treea930d3b84f8285e6210b2edf59de7382f0cf76d7
parent1575776e467d34f62f073df15ac360e7b34e79dc (diff)
parent6aed02773ec17fe5dcd3606f52451356e1f93b79 (diff)
downloadno-panic-a6a35bb62f9568faf38a058bfeb4f919cf1599db.tar.gz
Upgrade no-panic to 0.1.21 am: 1f1a6173ee am: b6cc1be463 am: 798e45b1ea am: 6aed02773e
Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/no-panic/+/2470804 Change-Id: Id4096c8a01f129578b9715001b6c980909a23c41 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
-rw-r--r--.cargo_vcs_info.json2
-rw-r--r--.github/workflows/ci.yml9
-rw-r--r--Android.bp2
-rw-r--r--Cargo.toml2
-rw-r--r--Cargo.toml.orig2
-rw-r--r--METADATA8
-rw-r--r--src/lib.rs60
-rw-r--r--tests/test.rs52
8 files changed, 126 insertions, 11 deletions
diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json
index 3ae0a43..341a73b 100644
--- a/.cargo_vcs_info.json
+++ b/.cargo_vcs_info.json
@@ -1,6 +1,6 @@
{
"git": {
- "sha1": "67d07dbfd0a40f088de60cf0347f67fc373a2a44"
+ "sha1": "b5c6d7e1df7e423a9543ee9317f63339660743a6"
},
"path_in_vcs": ""
} \ No newline at end of file
diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml
index 2f7af61..650b0e7 100644
--- a/.github/workflows/ci.yml
+++ b/.github/workflows/ci.yml
@@ -3,6 +3,7 @@ name: CI
on:
push:
pull_request:
+ workflow_dispatch:
schedule: [cron: "40 1 * * *"]
permissions:
@@ -30,6 +31,12 @@ jobs:
- uses: dtolnay/rust-toolchain@master
with:
toolchain: ${{matrix.rust}}
+ - name: Enable deny(non_exhaustive_omitted_patterns)
+ run: echo RUSTFLAGS=$(RUSTFLAGS)\ --cfg=exhaustive >> $GITHUB_ENV
+ if: matrix.rust == 'nightly'
+ - name: Enable type layout randomization
+ run: echo RUSTFLAGS=${RUSTFLAGS}\ -Zrandomize-layout >> $GITHUB_ENV
+ if: matrix.rust == 'nightly'
- run: cargo test
xplat:
@@ -49,6 +56,8 @@ jobs:
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@nightly
+ - name: Enable type layout randomization
+ run: echo RUSTFLAGS=${RUSTFLAGS}\ -Zrandomize-layout >> $GITHUB_ENV
- run: cargo test
msrv:
diff --git a/Android.bp b/Android.bp
index b066818..ff229de 100644
--- a/Android.bp
+++ b/Android.bp
@@ -41,7 +41,7 @@ rust_proc_macro {
name: "libno_panic",
crate_name: "no_panic",
cargo_env_compat: true,
- cargo_pkg_version: "0.1.19",
+ cargo_pkg_version: "0.1.21",
srcs: ["src/lib.rs"],
edition: "2018",
rustlibs: [
diff --git a/Cargo.toml b/Cargo.toml
index 97bace1..a183443 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -13,7 +13,7 @@
edition = "2018"
rust-version = "1.31"
name = "no-panic"
-version = "0.1.19"
+version = "0.1.21"
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"
diff --git a/Cargo.toml.orig b/Cargo.toml.orig
index 3a7a13f..98bf79c 100644
--- a/Cargo.toml.orig
+++ b/Cargo.toml.orig
@@ -1,6 +1,6 @@
[package]
name = "no-panic"
-version = "0.1.19"
+version = "0.1.21"
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"
diff --git a/METADATA b/METADATA
index bcb0241..18ed219 100644
--- a/METADATA
+++ b/METADATA
@@ -11,13 +11,13 @@ third_party {
}
url {
type: ARCHIVE
- value: "https://static.crates.io/crates/no-panic/no-panic-0.1.19.crate"
+ value: "https://static.crates.io/crates/no-panic/no-panic-0.1.21.crate"
}
- version: "0.1.19"
+ version: "0.1.21"
license_type: NOTICE
last_upgrade_date {
year: 2023
- month: 2
- day: 16
+ month: 3
+ day: 6
}
}
diff --git a/src/lib.rs b/src/lib.rs
index f1f6861..d0be8b4 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -119,7 +119,13 @@
//! [Kixunil]: https://github.com/Kixunil
//! [`dont_panic`]: https://github.com/Kixunil/dont_panic
-#![allow(clippy::doc_markdown, clippy::missing_panics_doc)]
+#![doc(html_root_url = "https://docs.rs/no-panic/0.1.21")]
+#![allow(
+ clippy::doc_markdown,
+ clippy::match_same_arms,
+ clippy::missing_panics_doc
+)]
+#![cfg_attr(all(test, exhaustive), feature(non_exhaustive_omitted_patterns_lint))]
extern crate proc_macro;
@@ -127,7 +133,10 @@ use proc_macro::TokenStream;
use proc_macro2::{Span, TokenStream as TokenStream2};
use quote::quote;
use syn::parse::{Error, Nothing, Result};
-use syn::{parse_quote, Attribute, FnArg, Ident, ItemFn, Pat, PatType, ReturnType};
+use syn::{
+ parse_quote, Attribute, FnArg, GenericArgument, Ident, ItemFn, Pat, PatType, Path,
+ PathArguments, ReturnType, Token, Type, TypeInfer, TypeParamBound,
+};
#[proc_macro_attribute]
pub fn no_panic(args: TokenStream, input: TokenStream) -> TokenStream {
@@ -155,6 +164,47 @@ fn parse(args: TokenStream2, input: TokenStream2) -> Result<ItemFn> {
Ok(function)
}
+// Convert `Path<impl Trait>` to `Path<_>`
+fn make_impl_trait_wild(ret: &mut Type) {
+ match ret {
+ Type::ImplTrait(impl_trait) => {
+ *ret = Type::Infer(TypeInfer {
+ underscore_token: Token![_](impl_trait.impl_token.span),
+ });
+ }
+ Type::Array(ret) => make_impl_trait_wild(&mut ret.elem),
+ Type::Group(ret) => make_impl_trait_wild(&mut ret.elem),
+ Type::Paren(ret) => make_impl_trait_wild(&mut ret.elem),
+ Type::Path(ret) => make_impl_trait_wild_in_path(&mut ret.path),
+ Type::Ptr(ret) => make_impl_trait_wild(&mut ret.elem),
+ Type::Reference(ret) => make_impl_trait_wild(&mut ret.elem),
+ Type::Slice(ret) => make_impl_trait_wild(&mut ret.elem),
+ Type::TraitObject(ret) => {
+ for bound in &mut ret.bounds {
+ if let TypeParamBound::Trait(bound) = bound {
+ make_impl_trait_wild_in_path(&mut bound.path);
+ }
+ }
+ }
+ Type::Tuple(ret) => ret.elems.iter_mut().for_each(make_impl_trait_wild),
+ Type::BareFn(_) | Type::Infer(_) | Type::Macro(_) | Type::Never(_) | Type::Verbatim(_) => {}
+ #[cfg_attr(all(test, exhaustive), deny(non_exhaustive_omitted_patterns))]
+ _ => {}
+ }
+}
+
+fn make_impl_trait_wild_in_path(path: &mut Path) {
+ for segment in &mut path.segments {
+ if let PathArguments::AngleBracketed(bracketed) = &mut segment.arguments {
+ for arg in &mut bracketed.args {
+ if let GenericArgument::Type(arg) = arg {
+ make_impl_trait_wild(arg);
+ }
+ }
+ }
+ }
+}
+
fn expand_no_panic(mut function: ItemFn) -> TokenStream2 {
let mut move_self = None;
let mut arg_pat = Vec::new();
@@ -197,7 +247,11 @@ fn expand_no_panic(mut function: ItemFn) -> TokenStream2 {
let ret = match &function.sig.output {
ReturnType::Default => quote!(-> ()),
- output @ ReturnType::Type(..) => quote!(#output),
+ ReturnType::Type(arrow, output) => {
+ let mut output = output.clone();
+ make_impl_trait_wild(&mut output);
+ quote!(#arrow #output)
+ }
};
let stmts = function.block.stmts;
let message = format!(
diff --git a/tests/test.rs b/tests/test.rs
index f6505ba..c65a08c 100644
--- a/tests/test.rs
+++ b/tests/test.rs
@@ -193,6 +193,58 @@ assert_no_panic! {
fn main() {}
}
+
+ mod test_deref_coercion {
+ #[no_panic]
+ pub fn f(s: &str) -> &str {
+ &s
+ }
+
+ fn main() {}
+ }
+
+ mod test_return_impl_trait {
+ use std::io;
+
+ #[no_panic]
+ pub fn f() -> io::Result<impl io::Write> {
+ Ok(Vec::new())
+ }
+
+ fn main() {}
+ }
+
+ mod test_conditional_return {
+ #[no_panic]
+ pub fn f(i: i32) {
+ if i < 0 {
+ return;
+ }
+ }
+
+ fn main() {
+ println!("{:?}", f(-1));
+ }
+ }
+
+ mod test_conditional_return_macro {
+ macro_rules! return_if_negative {
+ ($e:expr) => {
+ if $e < 0 {
+ return;
+ }
+ }
+ }
+
+ #[no_panic]
+ pub fn f(i: i32) {
+ return_if_negative!(i);
+ }
+
+ fn main() {
+ println!("{:?}", f(-1));
+ }
+ }
}
assert_link_error! {