about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLukas Wirth <lukastw97@gmail.com>2023-04-16 16:11:59 +0200
committerLukas Wirth <lukastw97@gmail.com>2023-04-16 16:11:59 +0200
commit71b50f9f09d21e33e87c565617c1043284db80c1 (patch)
tree53c8daa93bdae03f4123577d577dcc01db140e19
parent6ae8d49e1554cbf99387ed83079277f5f854d187 (diff)
downloadrust-71b50f9f09d21e33e87c565617c1043284db80c1.tar.gz
rust-71b50f9f09d21e33e87c565617c1043284db80c1.zip
Record eager expansion errors in EagerCallInfo
-rw-r--r--crates/hir-expand/src/db.rs3
-rw-r--r--crates/hir-expand/src/eager.rs10
-rw-r--r--crates/hir-expand/src/lib.rs11
-rw-r--r--crates/mbe/src/lib.rs2
4 files changed, 14 insertions, 12 deletions
diff --git a/crates/hir-expand/src/db.rs b/crates/hir-expand/src/db.rs
index d7aff6b02f4..e8fba15601b 100644
--- a/crates/hir-expand/src/db.rs
+++ b/crates/hir-expand/src/db.rs
@@ -451,8 +451,7 @@ fn macro_expand(
     if let Some(eager) = &loc.eager {
         return ExpandResult {
             value: Some(eager.arg_or_expansion.clone()),
-            // FIXME: There could be errors here!
-            err: None,
+            err: eager.error.clone(),
         };
     }
 
diff --git a/crates/hir-expand/src/eager.rs b/crates/hir-expand/src/eager.rs
index 74adced8c68..7d00b682a93 100644
--- a/crates/hir-expand/src/eager.rs
+++ b/crates/hir-expand/src/eager.rs
@@ -60,10 +60,11 @@ pub fn expand_eager_macro(
     let arg_id = db.intern_macro_call(MacroCallLoc {
         def,
         krate,
-        eager: Some(EagerCallInfo {
+        eager: Some(Box::new(EagerCallInfo {
             arg_or_expansion: Arc::new(parsed_args.clone()),
             included_file: None,
-        }),
+            error: None,
+        })),
         kind: MacroCallKind::FnLike { ast_id: call_id, expand_to: ExpandTo::Expr },
     });
 
@@ -88,10 +89,11 @@ pub fn expand_eager_macro(
     let loc = MacroCallLoc {
         def,
         krate,
-        eager: Some(EagerCallInfo {
+        eager: Some(Box::new(EagerCallInfo {
             arg_or_expansion: Arc::new(res.value.subtree),
             included_file: res.value.included_file,
-        }),
+            error: err.clone(),
+        })),
         kind: MacroCallKind::FnLike { ast_id: call_id, expand_to },
     };
 
diff --git a/crates/hir-expand/src/lib.rs b/crates/hir-expand/src/lib.rs
index d26fdbf7d61..9685320cf5d 100644
--- a/crates/hir-expand/src/lib.rs
+++ b/crates/hir-expand/src/lib.rs
@@ -52,7 +52,7 @@ use crate::{
 
 pub type ExpandResult<T> = ValueResult<T, ExpandError>;
 
-#[derive(Debug, PartialEq, Eq, Clone)]
+#[derive(Debug, PartialEq, Eq, Clone, Hash)]
 pub enum ExpandError {
     UnresolvedProcMacro(CrateId),
     Mbe(mbe::ExpandError),
@@ -114,7 +114,7 @@ impl_intern_key!(MacroCallId);
 pub struct MacroCallLoc {
     pub def: MacroDefId,
     pub(crate) krate: CrateId,
-    eager: Option<EagerCallInfo>,
+    eager: Option<Box<EagerCallInfo>>,
     pub kind: MacroCallKind,
 }
 
@@ -141,6 +141,7 @@ struct EagerCallInfo {
     /// NOTE: This can be *either* the expansion result, *or* the argument to the eager macro!
     arg_or_expansion: Arc<tt::Subtree>,
     included_file: Option<(FileId, TokenMap)>,
+    error: Option<ExpandError>,
 }
 
 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -206,8 +207,8 @@ impl HirFileId {
                 HirFileIdRepr::FileId(id) => break id,
                 HirFileIdRepr::MacroFile(MacroFile { macro_call_id }) => {
                     let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_call_id);
-                    file_id = match loc.eager {
-                        Some(EagerCallInfo { included_file: Some((file, _)), .. }) => file.into(),
+                    file_id = match loc.eager.as_deref() {
+                        Some(&EagerCallInfo { included_file: Some((file, _)), .. }) => file.into(),
                         _ => loc.kind.file_id(),
                     };
                 }
@@ -320,7 +321,7 @@ impl HirFileId {
         match self.macro_file() {
             Some(macro_file) => {
                 let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
-                matches!(loc.eager, Some(EagerCallInfo { included_file: Some(..), .. }))
+                matches!(loc.eager.as_deref(), Some(EagerCallInfo { included_file: Some(..), .. }))
             }
             _ => false,
         }
diff --git a/crates/mbe/src/lib.rs b/crates/mbe/src/lib.rs
index ac107a0d6d6..23ec3235d2d 100644
--- a/crates/mbe/src/lib.rs
+++ b/crates/mbe/src/lib.rs
@@ -69,7 +69,7 @@ impl fmt::Display for ParseError {
     }
 }
 
-#[derive(Debug, PartialEq, Eq, Clone)]
+#[derive(Debug, PartialEq, Eq, Clone, Hash)]
 pub enum ExpandError {
     BindingError(Box<Box<str>>),
     LeftoverTokens,