Upgrade no-panic to 0.1.21 am: 1f1a6173ee am: b6cc1be463 am: 798e45b1ea

Original change: https://android-review.googlesource.com/c/platform/external/rust/crates/no-panic/+/2470804

Change-Id: I8da0283cfeb7f4232fd8db6e088c161b59a04ab0
Signed-off-by: Automerger Merge Worker <[email protected]>
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 @@
 on:
   push:
   pull_request:
+  workflow_dispatch:
   schedule: [cron: "40 1 * * *"]
 
 permissions:
@@ -30,6 +31,12 @@
       - 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 @@
     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 @@
     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 <[email protected]>"]
 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 <[email protected]>"]
 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 @@
   }
   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_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 @@
     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 @@
 
     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 @@
 
         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! {