From a79b5673e8f5d1f8d569bc7c984a293a972a7bb0 Mon Sep 17 00:00:00 2001 From: Brandon Date: Tue, 16 Mar 2021 23:31:14 -0700 Subject: Follow established ErrorEmitted pattern --- crates/hir_def/src/body.rs | 7 ++----- crates/hir_def/src/lib.rs | 22 +++++++++++----------- 2 files changed, 13 insertions(+), 16 deletions(-) (limited to 'crates/hir_def') 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 { err.get_or_insert(e); })?; let call_id = match call_id { - Some(it) => it, - None => { - if err.is_none() { - log::warn!("no error despite `as_call_id_with_errors` returning `None`"); - } + Ok(it) => it, + Err(_) => { return Ok(ExpandResult { value: None, err }); } }; 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::{ use base_db::{impl_intern_key, salsa, CrateId}; use hir_expand::{ ast_id_map::FileAstId, - eager::{expand_eager_macro, ErrorEmitted}, + eager::{expand_eager_macro, ErrorEmitted, ErrorSink}, hygiene::Hygiene, AstId, HirFileId, InFile, MacroCallId, MacroCallKind, MacroDefId, MacroDefKind, }; @@ -583,7 +583,7 @@ pub trait AsMacroCall { krate: CrateId, resolver: impl Fn(path::ModPath) -> Option, ) -> Option { - self.as_call_id_with_errors(db, krate, resolver, &mut |_| ()).ok()? + self.as_call_id_with_errors(db, krate, resolver, &mut |_| ()).ok()?.ok() } fn as_call_id_with_errors( @@ -592,7 +592,7 @@ pub trait AsMacroCall { krate: CrateId, resolver: impl Fn(path::ModPath) -> Option, error_sink: &mut dyn FnMut(mbe::ExpandError), - ) -> Result, UnresolvedMacro>; + ) -> Result, UnresolvedMacro>; } impl AsMacroCall for InFile<&ast::MacroCall> { @@ -601,18 +601,19 @@ impl AsMacroCall for InFile<&ast::MacroCall> { db: &dyn db::DefDatabase, krate: CrateId, resolver: impl Fn(path::ModPath) -> Option, - error_sink: &mut dyn FnMut(mbe::ExpandError), - ) -> Result, UnresolvedMacro> { + mut error_sink: &mut dyn FnMut(mbe::ExpandError), + ) -> Result, UnresolvedMacro> { let ast_id = AstId::new(self.file_id, db.ast_id_map(self.file_id).ast_id(self.value)); let h = Hygiene::new(db.upcast(), self.file_id); let path = self.value.path().and_then(|path| path::ModPath::from_src(path, &h)); - let path = match path { - None => { - error_sink(mbe::ExpandError::Other("malformed macro invocation".into())); - return Ok(None); + let path = match error_sink + .option(path, || mbe::ExpandError::Other("malformed macro invocation".into())) + { + Ok(path) => path, + Err(error) => { + return Ok(Err(error)); } - Some(path) => path, }; macro_call_as_call_id( @@ -622,7 +623,6 @@ impl AsMacroCall for InFile<&ast::MacroCall> { resolver, error_sink, ) - .map(Result::ok) } } -- cgit v1.2.3