about summary refs log tree commit diff
path: root/compiler/rustc_builtin_macros/src/derive.rs
diff options
context:
space:
mode:
authorLukas Markeffsky <@>2023-06-19 14:08:38 +0000
committerLukas Markeffsky <@>2023-06-19 21:34:59 +0200
commitd50875e24af7671aad9b627fb8c6c4a49fa04e7d (patch)
treebf73fb2dbe96808f7eb78564743f4356ac1d5346 /compiler/rustc_builtin_macros/src/derive.rs
parent689511047a75a30825e367d4fd45c74604d0b15e (diff)
downloadrust-d50875e24af7671aad9b627fb8c6c4a49fa04e7d.tar.gz
rust-d50875e24af7671aad9b627fb8c6c4a49fa04e7d.zip
use `ErrorGuaranteed` instead of booleans
Diffstat (limited to 'compiler/rustc_builtin_macros/src/derive.rs')
-rw-r--r--compiler/rustc_builtin_macros/src/derive.rs14
1 files changed, 9 insertions, 5 deletions
diff --git a/compiler/rustc_builtin_macros/src/derive.rs b/compiler/rustc_builtin_macros/src/derive.rs
index fe4483104ee..140853db695 100644
--- a/compiler/rustc_builtin_macros/src/derive.rs
+++ b/compiler/rustc_builtin_macros/src/derive.rs
@@ -8,7 +8,7 @@ use rustc_feature::AttributeTemplate;
 use rustc_parse::validate_attr;
 use rustc_session::Session;
 use rustc_span::symbol::{sym, Ident};
-use rustc_span::Span;
+use rustc_span::{ErrorGuaranteed, Span};
 
 pub(crate) struct Expander(pub bool);
 
@@ -22,7 +22,7 @@ impl MultiItemModifier for Expander {
         _: bool,
     ) -> ExpandResult<Vec<Annotatable>, Annotatable> {
         let sess = ecx.sess;
-        if report_bad_target(sess, &item, span) {
+        if report_bad_target(sess, &item, span).is_err() {
             // We don't want to pass inappropriate targets to derive macros to avoid
             // follow up errors, all other errors below are recoverable.
             return ExpandResult::Ready(vec![item]);
@@ -103,7 +103,11 @@ fn dummy_annotatable() -> Annotatable {
     })
 }
 
-fn report_bad_target(sess: &Session, item: &Annotatable, span: Span) -> bool {
+fn report_bad_target(
+    sess: &Session,
+    item: &Annotatable,
+    span: Span,
+) -> Result<(), ErrorGuaranteed> {
     let item_kind = match item {
         Annotatable::Item(item) => Some(&item.kind),
         Annotatable::Stmt(stmt) => match &stmt.kind {
@@ -116,9 +120,9 @@ fn report_bad_target(sess: &Session, item: &Annotatable, span: Span) -> bool {
     let bad_target =
         !matches!(item_kind, Some(ItemKind::Struct(..) | ItemKind::Enum(..) | ItemKind::Union(..)));
     if bad_target {
-        sess.emit_err(errors::BadDeriveTarget { span, item: item.span() });
+        return Err(sess.emit_err(errors::BadDeriveTarget { span, item: item.span() }));
     }
-    bad_target
+    Ok(())
 }
 
 fn report_unexpected_meta_item_lit(sess: &Session, lit: &ast::MetaItemLit) {