about summary refs log tree commit diff
path: root/compiler/rustc_macros/src/diagnostics/utils.rs
diff options
context:
space:
mode:
authorclubby789 <jamie@hill-daniel.co.uk>2023-02-27 12:54:11 +0000
committerclubby789 <jamie@hill-daniel.co.uk>2023-02-27 12:54:11 +0000
commitef434f04e9629132f59d3f90fac0d4cc797166e8 (patch)
tree4db93097a3c4bb1e890d4fb764cf8c79888ed787 /compiler/rustc_macros/src/diagnostics/utils.rs
parent49b9cc5139dd4d11ef78dc08c1f9170de5b1ca39 (diff)
downloadrust-ef434f04e9629132f59d3f90fac0d4cc797166e8.tar.gz
rust-ef434f04e9629132f59d3f90fac0d4cc797166e8.zip
Allow using `bool` for optional diagnostics
Diffstat (limited to 'compiler/rustc_macros/src/diagnostics/utils.rs')
-rw-r--r--compiler/rustc_macros/src/diagnostics/utils.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/compiler/rustc_macros/src/diagnostics/utils.rs b/compiler/rustc_macros/src/diagnostics/utils.rs
index 27b8f676f3f..65bb154d7f3 100644
--- a/compiler/rustc_macros/src/diagnostics/utils.rs
+++ b/compiler/rustc_macros/src/diagnostics/utils.rs
@@ -50,6 +50,11 @@ pub(crate) fn type_is_unit(ty: &Type) -> bool {
     if let Type::Tuple(TypeTuple { elems, .. }) = ty { elems.is_empty() } else { false }
 }
 
+/// Checks whether the type `ty` is `bool`.
+pub(crate) fn type_is_bool(ty: &Type) -> bool {
+    type_matches_path(ty, &["bool"])
+}
+
 /// Reports a type error for field with `attr`.
 pub(crate) fn report_type_error(
     attr: &Attribute,
@@ -192,6 +197,11 @@ impl<'ty> FieldInnerTy<'ty> {
                     #inner
                 }
             },
+            FieldInnerTy::Plain(t) if type_is_bool(t) => quote! {
+                if #binding {
+                    #inner
+                }
+            },
             FieldInnerTy::Plain(..) => quote! { #inner },
         }
     }