From 93aeb16eb21709de38ba8484fa82ed4e05ae5665 Mon Sep 17 00:00:00 2001 From: Jonas Schievink Date: Fri, 19 Mar 2021 19:56:13 +0100 Subject: Return `Either` from `MacroDefId::ast_id` --- crates/hir_expand/src/hygiene.rs | 2 +- crates/hir_expand/src/lib.rs | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) (limited to 'crates/hir_expand/src') diff --git a/crates/hir_expand/src/hygiene.rs b/crates/hir_expand/src/hygiene.rs index 20cda1683..0e0f7214a 100644 --- a/crates/hir_expand/src/hygiene.rs +++ b/crates/hir_expand/src/hygiene.rs @@ -145,7 +145,7 @@ fn make_hygiene_info( ) -> Option { let arg_tt = loc.kind.arg(db)?; - let def_offset = loc.def.ast_id().and_then(|id| { + let def_offset = loc.def.ast_id().left().and_then(|id| { let def_tt = match id.to_node(db) { ast::Macro::MacroRules(mac) => mac.token_tree()?.syntax().text_range().start(), ast::Macro::MacroDef(_) => return None, diff --git a/crates/hir_expand/src/lib.rs b/crates/hir_expand/src/lib.rs index c958b0865..f49fd4fda 100644 --- a/crates/hir_expand/src/lib.rs +++ b/crates/hir_expand/src/lib.rs @@ -15,6 +15,7 @@ pub mod proc_macro; pub mod quote; pub mod eager; +use either::Either; pub use mbe::{ExpandError, ExpandResult}; use std::hash::Hash; @@ -143,7 +144,7 @@ impl HirFileId { let arg_tt = loc.kind.arg(db)?; - let def = loc.def.ast_id().and_then(|id| { + let def = loc.def.ast_id().left().and_then(|id| { let def_tt = match id.to_node(db) { ast::Macro::MacroRules(mac) => mac.token_tree()?, ast::Macro::MacroDef(_) => return None, @@ -239,15 +240,15 @@ impl MacroDefId { db.intern_macro(MacroCallLoc { def: self, krate, kind }) } - pub fn ast_id(&self) -> Option> { + pub fn ast_id(&self) -> Either, AstId> { let id = match &self.kind { MacroDefKind::Declarative(id) => id, MacroDefKind::BuiltIn(_, id) => id, MacroDefKind::BuiltInDerive(_, id) => id, MacroDefKind::BuiltInEager(_, id) => id, - MacroDefKind::ProcMacro(..) => return None, + MacroDefKind::ProcMacro(_, id) => return Either::Right(*id), }; - Some(*id) + Either::Left(*id) } } -- cgit v1.2.3