1 //! `hir_expand` deals with macro expansion.
3 //! Specifically, it implements a concept of `MacroFile` -- a file whose syntax
4 //! tree originates not from the text of some `FileId`, but from some macro
11 pub mod builtin_attr_macro;
12 pub mod builtin_derive_macro;
13 pub mod builtin_fn_macro;
18 use base_db::ProcMacroKind;
21 pub use mbe::{ExpandError, ExpandResult};
23 use std::{hash::Hash, iter, sync::Arc};
25 use base_db::{impl_intern_key, salsa, CrateId, FileId, FileRange};
27 algo::skip_trivia_token,
28 ast::{self, AstNode, HasAttrs},
29 Direction, SyntaxNode, SyntaxToken, TextRange,
33 ast_id_map::FileAstId,
34 builtin_attr_macro::BuiltinAttrExpander,
35 builtin_derive_macro::BuiltinDeriveExpander,
36 builtin_fn_macro::{BuiltinFnLikeExpander, EagerExpander},
38 proc_macro::ProcMacroExpander,
41 /// Input to the analyzer is a set of files, where each file is identified by
42 /// `FileId` and contains source code. However, another source of source code in
43 /// Rust are macros: each macro can be thought of as producing a "temporary
44 /// file". To assign an id to such a file, we use the id of the macro call that
45 /// produced the file. So, a `HirFileId` is either a `FileId` (source code
46 /// written by user), or a `MacroCallId` (source code produced by macro).
48 /// What is a `MacroCallId`? Simplifying, it's a `HirFileId` of a file
49 /// containing the call plus the offset of the macro call in the file. Note that
50 /// this is a recursive definition! However, the size_of of `HirFileId` is
51 /// finite (because everything bottoms out at the real `FileId`) and small
52 /// (`MacroCallId` uses the location interning. You can check details here:
53 /// <https://en.wikipedia.org/wiki/String_interning>).
54 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
55 pub struct HirFileId(HirFileIdRepr);
57 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
62 impl From<FileId> for HirFileId {
63 fn from(id: FileId) -> Self {
64 HirFileId(HirFileIdRepr::FileId(id))
67 impl From<MacroFile> for HirFileId {
68 fn from(id: MacroFile) -> Self {
69 HirFileId(HirFileIdRepr::MacroFile(id))
73 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
74 pub struct MacroFile {
75 pub macro_call_id: MacroCallId,
78 /// `MacroCallId` identifies a particular macro invocation, like
79 /// `println!("Hello, {}", world)`.
80 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
81 pub struct MacroCallId(salsa::InternId);
82 impl_intern_key!(MacroCallId);
84 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
85 pub struct MacroCallLoc {
87 pub(crate) krate: CrateId,
88 eager: Option<EagerCallInfo>,
89 pub kind: MacroCallKind,
92 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
93 pub struct MacroDefId {
95 pub kind: MacroDefKind,
96 pub local_inner: bool,
99 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
100 pub enum MacroDefKind {
101 Declarative(AstId<ast::Macro>),
102 BuiltIn(BuiltinFnLikeExpander, AstId<ast::Macro>),
103 // FIXME: maybe just Builtin and rename BuiltinFnLikeExpander to BuiltinExpander
104 BuiltInAttr(BuiltinAttrExpander, AstId<ast::Macro>),
105 BuiltInDerive(BuiltinDeriveExpander, AstId<ast::Macro>),
106 BuiltInEager(EagerExpander, AstId<ast::Macro>),
107 ProcMacro(ProcMacroExpander, ProcMacroKind, AstId<ast::Fn>),
110 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
111 struct EagerCallInfo {
112 /// NOTE: This can be *either* the expansion result, *or* the argument to the eager macro!
113 arg_or_expansion: Arc<tt::Subtree>,
114 included_file: Option<FileId>,
117 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
118 pub enum MacroCallKind {
120 ast_id: AstId<ast::MacroCall>,
124 ast_id: AstId<ast::Item>,
126 /// Syntactical index of the invoking `#[derive]` attribute.
128 /// Outer attributes are counted first, then inner attributes. This does not support
129 /// out-of-line modules, which may have attributes spread across 2 files!
130 derive_attr_index: u32,
133 ast_id: AstId<ast::Item>,
135 attr_args: (tt::Subtree, mbe::TokenMap),
136 /// Syntactical index of the invoking `#[attribute]`.
138 /// Outer attributes are counted first, then inner attributes. This does not support
139 /// out-of-line modules, which may have attributes spread across 2 files!
140 invoc_attr_index: u32,
145 /// For macro-expansion files, returns the file original source file the
146 /// expansion originated from.
147 pub fn original_file(self, db: &dyn db::AstDatabase) -> FileId {
149 HirFileIdRepr::FileId(file_id) => file_id,
150 HirFileIdRepr::MacroFile(macro_file) => {
151 let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id);
152 let file_id = match &loc.eager {
153 Some(EagerCallInfo { included_file: Some(file), .. }) => (*file).into(),
154 _ => loc.kind.file_id(),
156 file_id.original_file(db)
161 pub fn expansion_level(self, db: &dyn db::AstDatabase) -> u32 {
164 while let HirFileIdRepr::MacroFile(macro_file) = curr.0 {
165 let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id);
168 curr = loc.kind.file_id();
173 /// If this is a macro call, returns the syntax node of the call.
174 pub fn call_node(self, db: &dyn db::AstDatabase) -> Option<InFile<SyntaxNode>> {
176 HirFileIdRepr::FileId(_) => None,
177 HirFileIdRepr::MacroFile(macro_file) => {
178 let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id);
179 Some(loc.kind.to_node(db))
184 /// Return expansion information if it is a macro-expansion file
185 pub fn expansion_info(self, db: &dyn db::AstDatabase) -> Option<ExpansionInfo> {
187 HirFileIdRepr::FileId(_) => None,
188 HirFileIdRepr::MacroFile(macro_file) => {
189 let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id);
191 let arg_tt = loc.kind.arg(db)?;
193 let def = loc.def.ast_id().left().and_then(|id| {
194 let def_tt = match id.to_node(db) {
195 ast::Macro::MacroRules(mac) => mac.token_tree()?,
196 ast::Macro::MacroDef(mac) => mac.body()?,
198 Some(InFile::new(id.file_id, def_tt))
200 let attr_input_or_mac_def = def.or_else(|| match loc.kind {
201 MacroCallKind::Attr { ast_id, invoc_attr_index, .. } => {
205 .nth(invoc_attr_index as usize)?
207 Some(InFile::new(ast_id.file_id, tt))
212 let macro_def = db.macro_def(loc.def).ok()?;
213 let (parse, exp_map) = db.parse_macro_expansion(macro_file).value?;
214 let macro_arg = db.macro_arg(macro_file.macro_call_id)?;
217 expanded: InFile::new(self, parse.syntax_node()),
218 arg: InFile::new(loc.kind.file_id(), arg_tt),
219 attr_input_or_mac_def,
220 macro_arg_shift: mbe::Shift::new(¯o_arg.0),
229 /// Indicate it is macro file generated for builtin derive
230 pub fn is_builtin_derive(&self, db: &dyn db::AstDatabase) -> Option<InFile<ast::Item>> {
232 HirFileIdRepr::FileId(_) => None,
233 HirFileIdRepr::MacroFile(macro_file) => {
234 let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id);
235 let item = match loc.def.kind {
236 MacroDefKind::BuiltInDerive(..) => loc.kind.to_node(db),
239 Some(item.with_value(ast::Item::cast(item.value.clone())?))
244 pub fn is_custom_derive(&self, db: &dyn db::AstDatabase) -> bool {
246 HirFileIdRepr::FileId(_) => false,
247 HirFileIdRepr::MacroFile(macro_file) => {
248 let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id);
250 MacroDefKind::ProcMacro(_, ProcMacroKind::CustomDerive, _) => true,
257 /// Return whether this file is an include macro
258 pub fn is_include_macro(&self, db: &dyn db::AstDatabase) -> bool {
260 HirFileIdRepr::MacroFile(macro_file) => {
261 let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id);
262 matches!(loc.eager, Some(EagerCallInfo { included_file: Some(_), .. }))
268 /// Return whether this file is an include macro
269 pub fn is_attr_macro(&self, db: &dyn db::AstDatabase) -> bool {
271 HirFileIdRepr::MacroFile(macro_file) => {
272 let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id);
273 matches!(loc.kind, MacroCallKind::Attr { .. })
279 pub fn is_macro(self) -> bool {
280 matches!(self.0, HirFileIdRepr::MacroFile(_))
285 pub fn as_lazy_macro(
287 db: &dyn db::AstDatabase,
291 db.intern_macro(MacroCallLoc { def: self, krate, eager: None, kind })
294 pub fn ast_id(&self) -> Either<AstId<ast::Macro>, AstId<ast::Fn>> {
295 let id = match &self.kind {
296 MacroDefKind::ProcMacro(.., id) => return Either::Right(*id),
297 MacroDefKind::Declarative(id)
298 | MacroDefKind::BuiltIn(_, id)
299 | MacroDefKind::BuiltInAttr(_, id)
300 | MacroDefKind::BuiltInDerive(_, id)
301 | MacroDefKind::BuiltInEager(_, id) => id,
306 pub fn is_proc_macro(&self) -> bool {
307 matches!(self.kind, MacroDefKind::ProcMacro(..))
311 // FIXME: attribute indices do not account for `cfg_attr`, which means that we'll strip the whole
312 // `cfg_attr` instead of just one of the attributes it expands to
315 /// Returns the file containing the macro invocation.
316 fn file_id(&self) -> HirFileId {
318 MacroCallKind::FnLike { ast_id, .. } => ast_id.file_id,
319 MacroCallKind::Derive { ast_id, .. } | MacroCallKind::Attr { ast_id, .. } => {
325 pub fn to_node(&self, db: &dyn db::AstDatabase) -> InFile<SyntaxNode> {
327 MacroCallKind::FnLike { ast_id, .. } => {
328 ast_id.with_value(ast_id.to_node(db).syntax().clone())
330 MacroCallKind::Derive { ast_id, .. } | MacroCallKind::Attr { ast_id, .. } => {
331 ast_id.with_value(ast_id.to_node(db).syntax().clone())
336 fn arg(&self, db: &dyn db::AstDatabase) -> Option<SyntaxNode> {
338 MacroCallKind::FnLike { ast_id, .. } => {
339 Some(ast_id.to_node(db).token_tree()?.syntax().clone())
341 MacroCallKind::Derive { ast_id, .. } | MacroCallKind::Attr { ast_id, .. } => {
342 Some(ast_id.to_node(db).syntax().clone())
347 fn expand_to(&self) -> ExpandTo {
349 MacroCallKind::FnLike { expand_to, .. } => *expand_to,
350 MacroCallKind::Derive { .. } => ExpandTo::Items,
351 MacroCallKind::Attr { .. } => ExpandTo::Items, // is this always correct?
357 pub fn as_file(self) -> HirFileId {
358 MacroFile { macro_call_id: self }.into()
362 /// ExpansionInfo mainly describes how to map text range between src and expanded macro
363 #[derive(Debug, Clone, PartialEq, Eq)]
364 pub struct ExpansionInfo {
365 expanded: InFile<SyntaxNode>,
366 arg: InFile<SyntaxNode>,
367 /// The `macro_rules!` arguments or attribute input.
368 attr_input_or_mac_def: Option<InFile<ast::TokenTree>>,
370 macro_def: Arc<TokenExpander>,
371 macro_arg: Arc<(tt::Subtree, mbe::TokenMap)>,
372 macro_arg_shift: mbe::Shift,
373 exp_map: Arc<mbe::TokenMap>,
379 pub fn call_node(&self) -> Option<InFile<SyntaxNode>> {
380 Some(self.arg.with_value(self.arg.value.parent()?))
383 pub fn map_token_down(
385 db: &dyn db::AstDatabase,
386 item: Option<ast::Item>,
387 token: InFile<&SyntaxToken>,
388 ) -> Option<impl Iterator<Item = InFile<SyntaxToken>> + '_> {
389 assert_eq!(token.file_id, self.arg.file_id);
390 let token_id = if let Some(item) = item {
391 // check if we are mapping down in an attribute input
392 let call_id = match self.expanded.file_id.0 {
393 HirFileIdRepr::FileId(_) => return None,
394 HirFileIdRepr::MacroFile(macro_file) => macro_file.macro_call_id,
396 let loc = db.lookup_intern_macro(call_id);
398 let token_range = token.value.text_range();
400 MacroCallKind::Attr { attr_args, invoc_attr_index, .. } => {
401 let attr = item.attrs().nth(*invoc_attr_index as usize)?;
402 match attr.token_tree() {
404 if token_tree.syntax().text_range().contains_range(token_range) =>
406 let attr_input_start =
407 token_tree.left_delimiter_token()?.text_range().start();
408 let range = token.value.text_range().checked_sub(attr_input_start)?;
410 self.macro_arg_shift.shift(attr_args.1.token_by_range(range)?);
422 let token_id = match token_id {
423 Some(token_id) => token_id,
426 token.value.text_range().checked_sub(self.arg.value.text_range().start())?;
427 let token_id = self.macro_arg.1.token_by_range(range)?;
428 self.macro_def.map_id_down(token_id)
434 .ranges_by_token(token_id, token.value.kind())
435 .flat_map(move |range| self.expanded.value.covering_element(range).into_token());
437 Some(tokens.map(move |token| self.expanded.with_value(token)))
442 db: &dyn db::AstDatabase,
443 token: InFile<&SyntaxToken>,
444 ) -> Option<(InFile<SyntaxToken>, Origin)> {
445 let token_id = self.exp_map.token_by_range(token.value.text_range())?;
446 let (mut token_id, origin) = self.macro_def.map_id_up(token_id);
448 let call_id = match self.expanded.file_id.0 {
449 HirFileIdRepr::FileId(_) => return None,
450 HirFileIdRepr::MacroFile(macro_file) => macro_file.macro_call_id,
452 let loc = db.lookup_intern_macro(call_id);
454 let (token_map, tt) = match &loc.kind {
455 MacroCallKind::Attr { attr_args, .. } => match self.macro_arg_shift.unshift(token_id) {
457 token_id = unshifted;
458 (&attr_args.1, self.attr_input_or_mac_def.clone()?.syntax().cloned())
460 None => (&self.macro_arg.1, self.arg.clone()),
463 mbe::Origin::Call => (&self.macro_arg.1, self.arg.clone()),
464 mbe::Origin::Def => match (&*self.macro_def, &self.attr_input_or_mac_def) {
465 (TokenExpander::DeclarativeMacro { def_site_token_map, .. }, Some(tt)) => {
466 (def_site_token_map, tt.syntax().cloned())
468 _ => panic!("`Origin::Def` used with non-`macro_rules!` macro"),
473 let range = token_map.first_range_by_token(token_id, token.value.kind())?;
475 tt.value.covering_element(range + tt.value.text_range().start()).into_token()?;
476 Some((tt.with_value(token), origin))
480 /// `AstId` points to an AST node in any file.
482 /// It is stable across reparses, and can be used as salsa key/value.
483 // FIXME: isn't this just a `Source<FileAstId<N>>` ?
484 pub type AstId<N> = InFile<FileAstId<N>>;
486 impl<N: AstNode> AstId<N> {
487 pub fn to_node(&self, db: &dyn db::AstDatabase) -> N {
488 let root = db.parse_or_expand(self.file_id).unwrap();
489 db.ast_id_map(self.file_id).get(self.value).to_node(&root)
493 /// `InFile<T>` stores a value of `T` inside a particular file/syntax tree.
495 /// Typical usages are:
497 /// * `InFile<SyntaxNode>` -- syntax node in a file
498 /// * `InFile<ast::FnDef>` -- ast node in a file
499 /// * `InFile<TextSize>` -- offset in a file
500 #[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
501 pub struct InFile<T> {
502 pub file_id: HirFileId,
507 pub fn new(file_id: HirFileId, value: T) -> InFile<T> {
508 InFile { file_id, value }
511 // Similarly, naming here is stupid...
512 pub fn with_value<U>(&self, value: U) -> InFile<U> {
513 InFile::new(self.file_id, value)
516 pub fn map<F: FnOnce(T) -> U, U>(self, f: F) -> InFile<U> {
517 InFile::new(self.file_id, f(self.value))
519 pub fn as_ref(&self) -> InFile<&T> {
520 self.with_value(&self.value)
522 pub fn file_syntax(&self, db: &dyn db::AstDatabase) -> SyntaxNode {
523 db.parse_or_expand(self.file_id).expect("source created from invalid file")
527 impl<T: Clone> InFile<&T> {
528 pub fn cloned(&self) -> InFile<T> {
529 self.with_value(self.value.clone())
533 impl<T> InFile<Option<T>> {
534 pub fn transpose(self) -> Option<InFile<T>> {
535 let value = self.value?;
536 Some(InFile::new(self.file_id, value))
540 impl InFile<SyntaxNode> {
541 pub fn ancestors_with_macros(
543 db: &dyn db::AstDatabase,
544 ) -> impl Iterator<Item = InFile<SyntaxNode>> + Clone + '_ {
545 iter::successors(Some(self), move |node| match node.value.parent() {
546 Some(parent) => Some(node.with_value(parent)),
548 let parent_node = node.file_id.call_node(db)?;
554 /// Skips the attributed item that caused the macro invocation we are climbing up
555 pub fn ancestors_with_macros_skip_attr_item(
557 db: &dyn db::AstDatabase,
558 ) -> impl Iterator<Item = InFile<SyntaxNode>> + '_ {
559 iter::successors(Some(self), move |node| match node.value.parent() {
560 Some(parent) => Some(node.with_value(parent)),
562 let parent_node = node.file_id.call_node(db)?;
563 if node.file_id.is_attr_macro(db) {
564 // macro call was an attributed item, skip it
565 // FIXME: does this fail if this is a direct expansion of another macro?
566 parent_node.map(|node| node.parent()).transpose()
575 impl<'a> InFile<&'a SyntaxNode> {
576 /// Falls back to the macro call range if the node cannot be mapped up fully.
577 pub fn original_file_range(self, db: &dyn db::AstDatabase) -> FileRange {
578 if let Some(res) = self.original_file_range_opt(db) {
582 // Fall back to whole macro call.
583 let mut node = self.cloned();
584 while let Some(call_node) = node.file_id.call_node(db) {
588 let orig_file = node.file_id.original_file(db);
589 assert_eq!(node.file_id, orig_file.into());
591 FileRange { file_id: orig_file, range: node.value.text_range() }
594 /// Attempts to map the syntax node back up its macro calls.
595 pub fn original_file_range_opt(self, db: &dyn db::AstDatabase) -> Option<FileRange> {
596 match original_range_opt(db, self) {
598 let original_file = range.file_id.original_file(db);
599 if range.file_id != original_file.into() {
600 tracing::error!("Failed mapping up more for {:?}", range);
602 Some(FileRange { file_id: original_file, range: range.value })
604 _ if !self.file_id.is_macro() => Some(FileRange {
605 file_id: self.file_id.original_file(db),
606 range: self.value.text_range(),
613 fn original_range_opt(
614 db: &dyn db::AstDatabase,
615 node: InFile<&SyntaxNode>,
616 ) -> Option<InFile<TextRange>> {
617 let expansion = node.file_id.expansion_info(db)?;
619 // the input node has only one token ?
620 let single = skip_trivia_token(node.value.first_token()?, Direction::Next)?
621 == skip_trivia_token(node.value.last_token()?, Direction::Prev)?;
623 node.value.descendants().find_map(|it| {
624 let first = skip_trivia_token(it.first_token()?, Direction::Next)?;
625 let first = ascend_call_token(db, &expansion, node.with_value(first))?;
627 let last = skip_trivia_token(it.last_token()?, Direction::Prev)?;
628 let last = ascend_call_token(db, &expansion, node.with_value(last))?;
630 if (!single && first == last) || (first.file_id != last.file_id) {
634 Some(first.with_value(first.value.text_range().cover(last.value.text_range())))
638 fn ascend_call_token(
639 db: &dyn db::AstDatabase,
640 expansion: &ExpansionInfo,
641 token: InFile<SyntaxToken>,
642 ) -> Option<InFile<SyntaxToken>> {
643 let (mapped, origin) = expansion.map_token_up(db, token.as_ref())?;
644 if origin != Origin::Call {
647 if let Some(info) = mapped.file_id.expansion_info(db) {
648 return ascend_call_token(db, &info, mapped);
653 impl InFile<SyntaxToken> {
654 pub fn ancestors_with_macros(
656 db: &dyn db::AstDatabase,
657 ) -> impl Iterator<Item = InFile<SyntaxNode>> + '_ {
658 self.value.parent().into_iter().flat_map({
659 let file_id = self.file_id;
660 move |parent| InFile::new(file_id, parent).ancestors_with_macros(db)
665 impl<N: AstNode> InFile<N> {
666 pub fn descendants<T: AstNode>(self) -> impl Iterator<Item = InFile<T>> {
667 self.value.syntax().descendants().filter_map(T::cast).map(move |n| self.with_value(n))
670 pub fn syntax(&self) -> InFile<&SyntaxNode> {
671 self.with_value(self.value.syntax())
674 pub fn nodes_with_attributes<'db>(
676 db: &'db dyn db::AstDatabase,
677 ) -> impl Iterator<Item = InFile<N>> + 'db
681 iter::successors(Some(self), move |node| {
682 let InFile { file_id, value } = node.file_id.call_node(db)?;
683 N::cast(value).map(|n| InFile::new(file_id, n))
687 pub fn node_with_attributes(self, db: &dyn db::AstDatabase) -> InFile<N> {
688 self.nodes_with_attributes(db).last().unwrap()
692 /// In Rust, macros expand token trees to token trees. When we want to turn a
693 /// token tree into an AST node, we need to figure out what kind of AST node we
694 /// want: something like `foo` can be a type, an expression, or a pattern.
696 /// Naively, one would think that "what this expands to" is a property of a
697 /// particular macro: macro `m1` returns an item, while macro `m2` returns an
698 /// expression, etc. That's not the case -- macros are polymorphic in the
699 /// result, and can expand to any type of the AST node.
701 /// What defines the actual AST node is the syntactic context of the macro
702 /// invocation. As a contrived example, in `let T![*] = T![*];` the first `T`
703 /// expands to a pattern, while the second one expands to an expression.
705 /// `ExpandTo` captures this bit of information about a particular macro call
707 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
717 pub fn from_call_site(call: &ast::MacroCall) -> ExpandTo {
718 use syntax::SyntaxKind::*;
720 let syn = call.syntax();
722 let parent = match syn.parent() {
724 None => return ExpandTo::Statements,
727 match parent.kind() {
728 MACRO_ITEMS | SOURCE_FILE | ITEM_LIST => ExpandTo::Items,
729 MACRO_STMTS | EXPR_STMT | STMT_LIST => ExpandTo::Statements,
730 MACRO_PAT => ExpandTo::Pattern,
731 MACRO_TYPE => ExpandTo::Type,
733 ARG_LIST | TRY_EXPR | TUPLE_EXPR | PAREN_EXPR | ARRAY_EXPR | FOR_EXPR | PATH_EXPR
734 | CLOSURE_EXPR | CONDITION | BREAK_EXPR | RETURN_EXPR | MATCH_EXPR | MATCH_ARM
735 | MATCH_GUARD | RECORD_EXPR_FIELD | CALL_EXPR | INDEX_EXPR | METHOD_CALL_EXPR
736 | FIELD_EXPR | AWAIT_EXPR | CAST_EXPR | REF_EXPR | PREFIX_EXPR | RANGE_EXPR
737 | BIN_EXPR => ExpandTo::Expr,
739 // FIXME: Handle LHS Pattern
744 // Unknown , Just guess it is `Items`