Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 71b50f9

Browse files
committed
Record eager expansion errors in EagerCallInfo
1 parent 6ae8d49 commit 71b50f9

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

crates/hir-expand/src/db.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -451,8 +451,7 @@ fn macro_expand(
451451
if let Some(eager) = &loc.eager {
452452
return ExpandResult {
453453
value: Some(eager.arg_or_expansion.clone()),
454-
// FIXME: There could be errors here!
455-
err: None,
454+
err: eager.error.clone(),
456455
};
457456
}
458457

crates/hir-expand/src/eager.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ pub fn expand_eager_macro(
6060
let arg_id = db.intern_macro_call(MacroCallLoc {
6161
def,
6262
krate,
63-
eager: Some(EagerCallInfo {
63+
eager: Some(Box::new(EagerCallInfo {
6464
arg_or_expansion: Arc::new(parsed_args.clone()),
6565
included_file: None,
66-
}),
66+
error: None,
67+
})),
6768
kind: MacroCallKind::FnLike { ast_id: call_id, expand_to: ExpandTo::Expr },
6869
});
6970

@@ -88,10 +89,11 @@ pub fn expand_eager_macro(
8889
let loc = MacroCallLoc {
8990
def,
9091
krate,
91-
eager: Some(EagerCallInfo {
92+
eager: Some(Box::new(EagerCallInfo {
9293
arg_or_expansion: Arc::new(res.value.subtree),
9394
included_file: res.value.included_file,
94-
}),
95+
error: err.clone(),
96+
})),
9597
kind: MacroCallKind::FnLike { ast_id: call_id, expand_to },
9698
};
9799

crates/hir-expand/src/lib.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ use crate::{
5252

5353
pub type ExpandResult<T> = ValueResult<T, ExpandError>;
5454

55-
#[derive(Debug, PartialEq, Eq, Clone)]
55+
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
5656
pub enum ExpandError {
5757
UnresolvedProcMacro(CrateId),
5858
Mbe(mbe::ExpandError),
@@ -114,7 +114,7 @@ impl_intern_key!(MacroCallId);
114114
pub struct MacroCallLoc {
115115
pub def: MacroDefId,
116116
pub(crate) krate: CrateId,
117-
eager: Option<EagerCallInfo>,
117+
eager: Option<Box<EagerCallInfo>>,
118118
pub kind: MacroCallKind,
119119
}
120120

@@ -141,6 +141,7 @@ struct EagerCallInfo {
141141
/// NOTE: This can be *either* the expansion result, *or* the argument to the eager macro!
142142
arg_or_expansion: Arc<tt::Subtree>,
143143
included_file: Option<(FileId, TokenMap)>,
144+
error: Option<ExpandError>,
144145
}
145146

146147
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
@@ -206,8 +207,8 @@ impl HirFileId {
206207
HirFileIdRepr::FileId(id) => break id,
207208
HirFileIdRepr::MacroFile(MacroFile { macro_call_id }) => {
208209
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_call_id);
209-
file_id = match loc.eager {
210-
Some(EagerCallInfo { included_file: Some((file, _)), .. }) => file.into(),
210+
file_id = match loc.eager.as_deref() {
211+
Some(&EagerCallInfo { included_file: Some((file, _)), .. }) => file.into(),
211212
_ => loc.kind.file_id(),
212213
};
213214
}
@@ -320,7 +321,7 @@ impl HirFileId {
320321
match self.macro_file() {
321322
Some(macro_file) => {
322323
let loc: MacroCallLoc = db.lookup_intern_macro_call(macro_file.macro_call_id);
323-
matches!(loc.eager, Some(EagerCallInfo { included_file: Some(..), .. }))
324+
matches!(loc.eager.as_deref(), Some(EagerCallInfo { included_file: Some(..), .. }))
324325
}
325326
_ => false,
326327
}

crates/mbe/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ impl fmt::Display for ParseError {
6969
}
7070
}
7171

72-
#[derive(Debug, PartialEq, Eq, Clone)]
72+
#[derive(Debug, PartialEq, Eq, Clone, Hash)]
7373
pub enum ExpandError {
7474
BindingError(Box<Box<str>>),
7575
LeftoverTokens,

0 commit comments

Comments
 (0)