diff options
author | Brandon <[email protected]> | 2021-03-17 06:31:14 +0000 |
---|---|---|
committer | Brandon <[email protected]> | 2021-03-17 06:31:14 +0000 |
commit | a79b5673e8f5d1f8d569bc7c984a293a972a7bb0 (patch) | |
tree | 61eb44cada0b64cd0fbf137bb2cc5f2600755330 | |
parent | 0103f5df8fff2ccdbfb03adfe432b69c7840cf42 (diff) |
Follow established ErrorEmitted pattern
-rw-r--r-- | crates/hir_def/src/body.rs | 7 | ||||
-rw-r--r-- | crates/hir_def/src/lib.rs | 22 | ||||
-rw-r--r-- | crates/hir_expand/src/eager.rs | 2 |
3 files changed, 14 insertions, 17 deletions
diff --git a/crates/hir_def/src/body.rs b/crates/hir_def/src/body.rs index d2dcd6727..1080d9c2c 100644 --- a/crates/hir_def/src/body.rs +++ b/crates/hir_def/src/body.rs | |||
@@ -121,11 +121,8 @@ impl Expander { | |||
121 | err.get_or_insert(e); | 121 | err.get_or_insert(e); |
122 | })?; | 122 | })?; |
123 | let call_id = match call_id { | 123 | let call_id = match call_id { |
124 | Some(it) => it, | 124 | Ok(it) => it, |
125 | None => { | 125 | Err(_) => { |
126 | if err.is_none() { | ||
127 | log::warn!("no error despite `as_call_id_with_errors` returning `None`"); | ||
128 | } | ||
129 | return Ok(ExpandResult { value: None, err }); | 126 | return Ok(ExpandResult { value: None, err }); |
130 | } | 127 | } |
131 | }; | 128 | }; |
diff --git a/crates/hir_def/src/lib.rs b/crates/hir_def/src/lib.rs index 4b5cdd7a1..6758411a0 100644 --- a/crates/hir_def/src/lib.rs +++ b/crates/hir_def/src/lib.rs | |||
@@ -58,7 +58,7 @@ use std::{ | |||
58 | use base_db::{impl_intern_key, salsa, CrateId}; | 58 | use base_db::{impl_intern_key, salsa, CrateId}; |
59 | use hir_expand::{ | 59 | use hir_expand::{ |
60 | ast_id_map::FileAstId, | 60 | ast_id_map::FileAstId, |
61 | eager::{expand_eager_macro, ErrorEmitted}, | 61 | eager::{expand_eager_macro, ErrorEmitted, ErrorSink}, |
62 | hygiene::Hygiene, | 62 | hygiene::Hygiene, |
63 | AstId, HirFileId, InFile, MacroCallId, MacroCallKind, MacroDefId, MacroDefKind, | 63 | AstId, HirFileId, InFile, MacroCallId, MacroCallKind, MacroDefId, MacroDefKind, |
64 | }; | 64 | }; |
@@ -583,7 +583,7 @@ pub trait AsMacroCall { | |||
583 | krate: CrateId, | 583 | krate: CrateId, |
584 | resolver: impl Fn(path::ModPath) -> Option<MacroDefId>, | 584 | resolver: impl Fn(path::ModPath) -> Option<MacroDefId>, |
585 | ) -> Option<MacroCallId> { | 585 | ) -> Option<MacroCallId> { |
586 | self.as_call_id_with_errors(db, krate, resolver, &mut |_| ()).ok()? | 586 | self.as_call_id_with_errors(db, krate, resolver, &mut |_| ()).ok()?.ok() |
587 | } | 587 | } |
588 | 588 | ||
589 | fn as_call_id_with_errors( | 589 | fn as_call_id_with_errors( |
@@ -592,7 +592,7 @@ pub trait AsMacroCall { | |||
592 | krate: CrateId, | 592 | krate: CrateId, |
593 | resolver: impl Fn(path::ModPath) -> Option<MacroDefId>, | 593 | resolver: impl Fn(path::ModPath) -> Option<MacroDefId>, |
594 | error_sink: &mut dyn FnMut(mbe::ExpandError), | 594 | error_sink: &mut dyn FnMut(mbe::ExpandError), |
595 | ) -> Result<Option<MacroCallId>, UnresolvedMacro>; | 595 | ) -> Result<Result<MacroCallId, ErrorEmitted>, UnresolvedMacro>; |
596 | } | 596 | } |
597 | 597 | ||
598 | impl AsMacroCall for InFile<&ast::MacroCall> { | 598 | impl AsMacroCall for InFile<&ast::MacroCall> { |
@@ -601,18 +601,19 @@ impl AsMacroCall for InFile<&ast::MacroCall> { | |||
601 | db: &dyn db::DefDatabase, | 601 | db: &dyn db::DefDatabase, |
602 | krate: CrateId, | 602 | krate: CrateId, |
603 | resolver: impl Fn(path::ModPath) -> Option<MacroDefId>, | 603 | resolver: impl Fn(path::ModPath) -> Option<MacroDefId>, |
604 | error_sink: &mut dyn FnMut(mbe::ExpandError), | 604 | mut error_sink: &mut dyn FnMut(mbe::ExpandError), |
605 | ) -> Result<Option<MacroCallId>, UnresolvedMacro> { | 605 | ) -> Result<Result<MacroCallId, ErrorEmitted>, UnresolvedMacro> { |
606 | let ast_id = AstId::new(self.file_id, db.ast_id_map(self.file_id).ast_id(self.value)); | 606 | let ast_id = AstId::new(self.file_id, db.ast_id_map(self.file_id).ast_id(self.value)); |
607 | let h = Hygiene::new(db.upcast(), self.file_id); | 607 | let h = Hygiene::new(db.upcast(), self.file_id); |
608 | let path = self.value.path().and_then(|path| path::ModPath::from_src(path, &h)); | 608 | let path = self.value.path().and_then(|path| path::ModPath::from_src(path, &h)); |
609 | 609 | ||
610 | let path = match path { | 610 | let path = match error_sink |
611 | None => { | 611 | .option(path, || mbe::ExpandError::Other("malformed macro invocation".into())) |
612 | error_sink(mbe::ExpandError::Other("malformed macro invocation".into())); | 612 | { |
613 | return Ok(None); | 613 | Ok(path) => path, |
614 | Err(error) => { | ||
615 | return Ok(Err(error)); | ||
614 | } | 616 | } |
615 | Some(path) => path, | ||
616 | }; | 617 | }; |
617 | 618 | ||
618 | macro_call_as_call_id( | 619 | macro_call_as_call_id( |
@@ -622,7 +623,6 @@ impl AsMacroCall for InFile<&ast::MacroCall> { | |||
622 | resolver, | 623 | resolver, |
623 | error_sink, | 624 | error_sink, |
624 | ) | 625 | ) |
625 | .map(Result::ok) | ||
626 | } | 626 | } |
627 | } | 627 | } |
628 | 628 | ||
diff --git a/crates/hir_expand/src/eager.rs b/crates/hir_expand/src/eager.rs index ae7b51a08..dc618a9ee 100644 --- a/crates/hir_expand/src/eager.rs +++ b/crates/hir_expand/src/eager.rs | |||
@@ -35,7 +35,7 @@ pub struct ErrorEmitted { | |||
35 | _private: (), | 35 | _private: (), |
36 | } | 36 | } |
37 | 37 | ||
38 | trait ErrorSink { | 38 | pub trait ErrorSink { |
39 | fn emit(&mut self, err: mbe::ExpandError); | 39 | fn emit(&mut self, err: mbe::ExpandError); |
40 | 40 | ||
41 | fn option<T>( | 41 | fn option<T>( |