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,
44 /// Input to the analyzer is a set of files, where each file is identified by
45 /// `FileId` and contains source code. However, another source of source code in
46 /// Rust are macros: each macro can be thought of as producing a "temporary
47 /// file". To assign an id to such a file, we use the id of the macro call that
48 /// produced the file. So, a `HirFileId` is either a `FileId` (source code
49 /// written by user), or a `MacroCallId` (source code produced by macro).
51 /// What is a `MacroCallId`? Simplifying, it's a `HirFileId` of a file
52 /// containing the call plus the offset of the macro call in the file. Note that
53 /// this is a recursive definition! However, the size_of of `HirFileId` is
54 /// finite (because everything bottoms out at the real `FileId`) and small
55 /// (`MacroCallId` uses the location interning. You can check details here:
56 /// <https://en.wikipedia.org/wiki/String_interning>).
57 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
58 pub struct HirFileId(HirFileIdRepr);
60 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
66 impl From<FileId> for HirFileId {
67 fn from(id: FileId) -> Self {
68 HirFileId(HirFileIdRepr::FileId(id))
72 impl From<MacroFile> for HirFileId {
73 fn from(id: MacroFile) -> Self {
74 HirFileId(HirFileIdRepr::MacroFile(id))
79 /// For macro-expansion files, returns the file original source file the
80 /// expansion originated from.
81 pub fn original_file(self, db: &dyn db::AstDatabase) -> FileId {
83 HirFileIdRepr::FileId(file_id) => file_id,
84 HirFileIdRepr::MacroFile(macro_file) => {
85 let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id);
86 let file_id = match &loc.eager {
87 Some(EagerCallInfo { included_file: Some(file), .. }) => (*file).into(),
88 _ => loc.kind.file_id(),
90 file_id.original_file(db)
95 pub fn expansion_level(self, db: &dyn db::AstDatabase) -> u32 {
98 while let HirFileIdRepr::MacroFile(macro_file) = curr.0 {
99 let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id);
102 curr = loc.kind.file_id();
107 /// If this is a macro call, returns the syntax node of the call.
108 pub fn call_node(self, db: &dyn db::AstDatabase) -> Option<InFile<SyntaxNode>> {
110 HirFileIdRepr::FileId(_) => None,
111 HirFileIdRepr::MacroFile(macro_file) => {
112 let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id);
113 Some(loc.kind.to_node(db))
118 /// Return expansion information if it is a macro-expansion file
119 pub fn expansion_info(self, db: &dyn db::AstDatabase) -> Option<ExpansionInfo> {
121 HirFileIdRepr::FileId(_) => None,
122 HirFileIdRepr::MacroFile(macro_file) => {
123 let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id);
125 let arg_tt = loc.kind.arg(db)?;
127 let def = loc.def.ast_id().left().and_then(|id| {
128 let def_tt = match id.to_node(db) {
129 ast::Macro::MacroRules(mac) => mac.token_tree()?,
130 ast::Macro::MacroDef(mac) => mac.body()?,
132 Some(InFile::new(id.file_id, def_tt))
134 let attr_input_or_mac_def = def.or_else(|| match loc.kind {
135 MacroCallKind::Attr { ast_id, invoc_attr_index, .. } => {
139 .nth(invoc_attr_index as usize)?
141 Some(InFile::new(ast_id.file_id, tt))
146 let macro_def = db.macro_def(loc.def).ok()?;
147 let (parse, exp_map) = db.parse_macro_expansion(macro_file).value?;
148 let macro_arg = db.macro_arg(macro_file.macro_call_id)?;
151 expanded: InFile::new(self, parse.syntax_node()),
152 arg: InFile::new(loc.kind.file_id(), arg_tt),
153 attr_input_or_mac_def,
154 macro_arg_shift: mbe::Shift::new(¯o_arg.0),
163 /// Indicate it is macro file generated for builtin derive
164 pub fn is_builtin_derive(&self, db: &dyn db::AstDatabase) -> Option<InFile<ast::Item>> {
166 HirFileIdRepr::FileId(_) => None,
167 HirFileIdRepr::MacroFile(macro_file) => {
168 let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id);
169 let item = match loc.def.kind {
170 MacroDefKind::BuiltInDerive(..) => loc.kind.to_node(db),
173 Some(item.with_value(ast::Item::cast(item.value.clone())?))
178 pub fn is_custom_derive(&self, db: &dyn db::AstDatabase) -> bool {
180 HirFileIdRepr::FileId(_) => false,
181 HirFileIdRepr::MacroFile(macro_file) => {
182 let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id);
184 MacroDefKind::ProcMacro(_, ProcMacroKind::CustomDerive, _) => true,
191 /// Return whether this file is an include macro
192 pub fn is_include_macro(&self, db: &dyn db::AstDatabase) -> bool {
194 HirFileIdRepr::MacroFile(macro_file) => {
195 let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id);
196 matches!(loc.eager, Some(EagerCallInfo { included_file: Some(_), .. }))
202 /// Return whether this file is an include macro
203 pub fn is_attr_macro(&self, db: &dyn db::AstDatabase) -> bool {
205 HirFileIdRepr::MacroFile(macro_file) => {
206 let loc: MacroCallLoc = db.lookup_intern_macro(macro_file.macro_call_id);
207 matches!(loc.kind, MacroCallKind::Attr { .. })
213 pub fn is_macro(self) -> bool {
214 matches!(self.0, HirFileIdRepr::MacroFile(_))
218 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
219 pub struct MacroFile {
220 pub macro_call_id: MacroCallId,
223 /// `MacroCallId` identifies a particular macro invocation, like
224 /// `println!("Hello, {}", world)`.
225 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
226 pub struct MacroCallId(salsa::InternId);
227 impl_intern_key!(MacroCallId);
229 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
230 pub struct MacroDefId {
232 pub kind: MacroDefKind,
234 pub local_inner: bool,
238 pub fn as_lazy_macro(
240 db: &dyn db::AstDatabase,
244 db.intern_macro(MacroCallLoc { def: self, krate, eager: None, kind })
247 pub fn ast_id(&self) -> Either<AstId<ast::Macro>, AstId<ast::Fn>> {
248 let id = match &self.kind {
249 MacroDefKind::ProcMacro(.., id) => return Either::Right(*id),
250 MacroDefKind::Declarative(id)
251 | MacroDefKind::BuiltIn(_, id)
252 | MacroDefKind::BuiltInAttr(_, id)
253 | MacroDefKind::BuiltInDerive(_, id)
254 | MacroDefKind::BuiltInEager(_, id) => id,
259 pub fn is_proc_macro(&self) -> bool {
260 matches!(self.kind, MacroDefKind::ProcMacro(..))
264 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
265 pub enum MacroDefKind {
266 Declarative(AstId<ast::Macro>),
267 BuiltIn(BuiltinFnLikeExpander, AstId<ast::Macro>),
268 // FIXME: maybe just Builtin and rename BuiltinFnLikeExpander to BuiltinExpander
269 BuiltInAttr(BuiltinAttrExpander, AstId<ast::Macro>),
270 BuiltInDerive(BuiltinDeriveExpander, AstId<ast::Macro>),
271 BuiltInEager(EagerExpander, AstId<ast::Macro>),
272 ProcMacro(ProcMacroExpander, ProcMacroKind, AstId<ast::Fn>),
275 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
276 struct EagerCallInfo {
277 /// NOTE: This can be *either* the expansion result, *or* the argument to the eager macro!
278 arg_or_expansion: Arc<tt::Subtree>,
279 included_file: Option<FileId>,
282 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
283 pub struct MacroCallLoc {
285 pub(crate) krate: CrateId,
286 eager: Option<EagerCallInfo>,
287 pub kind: MacroCallKind,
290 #[derive(Debug, Clone, PartialEq, Eq, Hash)]
291 pub enum MacroCallKind {
293 ast_id: AstId<ast::MacroCall>,
297 ast_id: AstId<ast::Item>,
299 /// Syntactical index of the invoking `#[derive]` attribute.
301 /// Outer attributes are counted first, then inner attributes. This does not support
302 /// out-of-line modules, which may have attributes spread across 2 files!
303 derive_attr_index: u32,
306 ast_id: AstId<ast::Item>,
308 attr_args: (tt::Subtree, mbe::TokenMap),
309 /// Syntactical index of the invoking `#[attribute]`.
311 /// Outer attributes are counted first, then inner attributes. This does not support
312 /// out-of-line modules, which may have attributes spread across 2 files!
313 invoc_attr_index: u32,
317 // FIXME: attribute indices do not account for `cfg_attr`, which means that we'll strip the whole
318 // `cfg_attr` instead of just one of the attributes it expands to
321 /// Returns the file containing the macro invocation.
322 fn file_id(&self) -> HirFileId {
324 MacroCallKind::FnLike { ast_id, .. } => ast_id.file_id,
325 MacroCallKind::Derive { ast_id, .. } | MacroCallKind::Attr { ast_id, .. } => {
331 pub fn to_node(&self, db: &dyn db::AstDatabase) -> InFile<SyntaxNode> {
333 MacroCallKind::FnLike { ast_id, .. } => {
334 ast_id.with_value(ast_id.to_node(db).syntax().clone())
336 MacroCallKind::Derive { ast_id, .. } | MacroCallKind::Attr { ast_id, .. } => {
337 ast_id.with_value(ast_id.to_node(db).syntax().clone())
342 fn arg(&self, db: &dyn db::AstDatabase) -> Option<SyntaxNode> {
344 MacroCallKind::FnLike { ast_id, .. } => {
345 Some(ast_id.to_node(db).token_tree()?.syntax().clone())
347 MacroCallKind::Derive { ast_id, .. } | MacroCallKind::Attr { ast_id, .. } => {
348 Some(ast_id.to_node(db).syntax().clone())
353 fn expand_to(&self) -> ExpandTo {
355 MacroCallKind::FnLike { expand_to, .. } => *expand_to,
356 MacroCallKind::Derive { .. } => ExpandTo::Items,
357 MacroCallKind::Attr { .. } => ExpandTo::Items, // is this always correct?
363 pub fn as_file(self) -> HirFileId {
364 MacroFile { macro_call_id: self }.into()
368 /// ExpansionInfo mainly describes how to map text range between src and expanded macro
369 #[derive(Debug, Clone, PartialEq, Eq)]
370 pub struct ExpansionInfo {
371 expanded: InFile<SyntaxNode>,
372 arg: InFile<SyntaxNode>,
373 /// The `macro_rules!` arguments or attribute input.
374 attr_input_or_mac_def: Option<InFile<ast::TokenTree>>,
376 macro_def: Arc<TokenExpander>,
377 macro_arg: Arc<(tt::Subtree, mbe::TokenMap)>,
378 macro_arg_shift: mbe::Shift,
379 exp_map: Arc<mbe::TokenMap>,
385 pub fn call_node(&self) -> Option<InFile<SyntaxNode>> {
386 Some(self.arg.with_value(self.arg.value.parent()?))
389 pub fn map_token_down(
391 db: &dyn db::AstDatabase,
392 item: Option<ast::Item>,
393 token: InFile<&SyntaxToken>,
394 ) -> Option<impl Iterator<Item = InFile<SyntaxToken>> + '_> {
395 assert_eq!(token.file_id, self.arg.file_id);
396 let token_id = if let Some(item) = item {
397 // check if we are mapping down in an attribute input
398 let call_id = match self.expanded.file_id.0 {
399 HirFileIdRepr::FileId(_) => return None,
400 HirFileIdRepr::MacroFile(macro_file) => macro_file.macro_call_id,
402 let loc = db.lookup_intern_macro(call_id);
404 let token_range = token.value.text_range();
406 MacroCallKind::Attr { attr_args, invoc_attr_index, .. } => {
407 let attr = item.attrs().nth(*invoc_attr_index as usize)?;
408 match attr.token_tree() {
410 if token_tree.syntax().text_range().contains_range(token_range) =>
412 let attr_input_start =
413 token_tree.left_delimiter_token()?.text_range().start();
414 let range = token.value.text_range().checked_sub(attr_input_start)?;
416 self.macro_arg_shift.shift(attr_args.1.token_by_range(range)?);
428 let token_id = match token_id {
429 Some(token_id) => token_id,
432 token.value.text_range().checked_sub(self.arg.value.text_range().start())?;
433 let token_id = self.macro_arg.1.token_by_range(range)?;
434 self.macro_def.map_id_down(token_id)
440 .ranges_by_token(token_id, token.value.kind())
441 .flat_map(move |range| self.expanded.value.covering_element(range).into_token());
443 Some(tokens.map(move |token| self.expanded.with_value(token)))
448 db: &dyn db::AstDatabase,
449 token: InFile<&SyntaxToken>,
450 ) -> Option<(InFile<SyntaxToken>, Origin)> {
451 let token_id = self.exp_map.token_by_range(token.value.text_range())?;
452 let (mut token_id, origin) = self.macro_def.map_id_up(token_id);
454 let call_id = match self.expanded.file_id.0 {
455 HirFileIdRepr::FileId(_) => return None,
456 HirFileIdRepr::MacroFile(macro_file) => macro_file.macro_call_id,
458 let loc = db.lookup_intern_macro(call_id);
460 let (token_map, tt) = match &loc.kind {
461 MacroCallKind::Attr { attr_args, .. } => match self.macro_arg_shift.unshift(token_id) {
463 token_id = unshifted;
464 (&attr_args.1, self.attr_input_or_mac_def.clone()?.syntax().cloned())
466 None => (&self.macro_arg.1, self.arg.clone()),
469 mbe::Origin::Call => (&self.macro_arg.1, self.arg.clone()),
470 mbe::Origin::Def => match (&*self.macro_def, &self.attr_input_or_mac_def) {
471 (TokenExpander::DeclarativeMacro { def_site_token_map, .. }, Some(tt)) => {
472 (def_site_token_map, tt.syntax().cloned())
474 _ => panic!("`Origin::Def` used with non-`macro_rules!` macro"),
479 let range = token_map.first_range_by_token(token_id, token.value.kind())?;
481 tt.value.covering_element(range + tt.value.text_range().start()).into_token()?;
482 Some((tt.with_value(token), origin))
486 /// `AstId` points to an AST node in any file.
488 /// It is stable across reparses, and can be used as salsa key/value.
489 // FIXME: isn't this just a `Source<FileAstId<N>>` ?
490 pub type AstId<N> = InFile<FileAstId<N>>;
492 impl<N: AstNode> AstId<N> {
493 pub fn to_node(&self, db: &dyn db::AstDatabase) -> N {
494 let root = db.parse_or_expand(self.file_id).unwrap();
495 db.ast_id_map(self.file_id).get(self.value).to_node(&root)
499 /// `InFile<T>` stores a value of `T` inside a particular file/syntax tree.
501 /// Typical usages are:
503 /// * `InFile<SyntaxNode>` -- syntax node in a file
504 /// * `InFile<ast::FnDef>` -- ast node in a file
505 /// * `InFile<TextSize>` -- offset in a file
506 #[derive(Debug, PartialEq, Eq, Clone, Copy, Hash)]
507 pub struct InFile<T> {
508 pub file_id: HirFileId,
513 pub fn new(file_id: HirFileId, value: T) -> InFile<T> {
514 InFile { file_id, value }
517 // Similarly, naming here is stupid...
518 pub fn with_value<U>(&self, value: U) -> InFile<U> {
519 InFile::new(self.file_id, value)
522 pub fn map<F: FnOnce(T) -> U, U>(self, f: F) -> InFile<U> {
523 InFile::new(self.file_id, f(self.value))
525 pub fn as_ref(&self) -> InFile<&T> {
526 self.with_value(&self.value)
528 pub fn file_syntax(&self, db: &dyn db::AstDatabase) -> SyntaxNode {
529 db.parse_or_expand(self.file_id).expect("source created from invalid file")
533 impl<T: Clone> InFile<&T> {
534 pub fn cloned(&self) -> InFile<T> {
535 self.with_value(self.value.clone())
539 impl<T> InFile<Option<T>> {
540 pub fn transpose(self) -> Option<InFile<T>> {
541 let value = self.value?;
542 Some(InFile::new(self.file_id, value))
546 impl InFile<SyntaxNode> {
547 pub fn ancestors_with_macros(
549 db: &dyn db::AstDatabase,
550 ) -> impl Iterator<Item = InFile<SyntaxNode>> + Clone + '_ {
551 iter::successors(Some(self), move |node| match node.value.parent() {
552 Some(parent) => Some(node.with_value(parent)),
554 let parent_node = node.file_id.call_node(db)?;
560 /// Skips the attributed item that caused the macro invocation we are climbing up
561 pub fn ancestors_with_macros_skip_attr_item(
563 db: &dyn db::AstDatabase,
564 ) -> impl Iterator<Item = InFile<SyntaxNode>> + '_ {
565 iter::successors(Some(self), move |node| match node.value.parent() {
566 Some(parent) => Some(node.with_value(parent)),
568 let parent_node = node.file_id.call_node(db)?;
569 if node.file_id.is_attr_macro(db) {
570 // macro call was an attributed item, skip it
571 // FIXME: does this fail if this is a direct expansion of another macro?
572 parent_node.map(|node| node.parent()).transpose()
581 impl<'a> InFile<&'a SyntaxNode> {
582 /// Falls back to the macro call range if the node cannot be mapped up fully.
583 pub fn original_file_range(self, db: &dyn db::AstDatabase) -> FileRange {
584 if let Some(res) = self.original_file_range_opt(db) {
588 // Fall back to whole macro call.
589 let mut node = self.cloned();
590 while let Some(call_node) = node.file_id.call_node(db) {
594 let orig_file = node.file_id.original_file(db);
595 assert_eq!(node.file_id, orig_file.into());
597 FileRange { file_id: orig_file, range: node.value.text_range() }
600 /// Attempts to map the syntax node back up its macro calls.
601 pub fn original_file_range_opt(self, db: &dyn db::AstDatabase) -> Option<FileRange> {
602 match original_range_opt(db, self) {
604 let original_file = range.file_id.original_file(db);
605 if range.file_id != original_file.into() {
606 tracing::error!("Failed mapping up more for {:?}", range);
608 Some(FileRange { file_id: original_file, range: range.value })
610 _ if !self.file_id.is_macro() => Some(FileRange {
611 file_id: self.file_id.original_file(db),
612 range: self.value.text_range(),
619 fn original_range_opt(
620 db: &dyn db::AstDatabase,
621 node: InFile<&SyntaxNode>,
622 ) -> Option<InFile<TextRange>> {
623 let expansion = node.file_id.expansion_info(db)?;
625 // the input node has only one token ?
626 let single = skip_trivia_token(node.value.first_token()?, Direction::Next)?
627 == skip_trivia_token(node.value.last_token()?, Direction::Prev)?;
629 node.value.descendants().find_map(|it| {
630 let first = skip_trivia_token(it.first_token()?, Direction::Next)?;
631 let first = ascend_call_token(db, &expansion, node.with_value(first))?;
633 let last = skip_trivia_token(it.last_token()?, Direction::Prev)?;
634 let last = ascend_call_token(db, &expansion, node.with_value(last))?;
636 if (!single && first == last) || (first.file_id != last.file_id) {
640 Some(first.with_value(first.value.text_range().cover(last.value.text_range())))
644 fn ascend_call_token(
645 db: &dyn db::AstDatabase,
646 expansion: &ExpansionInfo,
647 token: InFile<SyntaxToken>,
648 ) -> Option<InFile<SyntaxToken>> {
649 let (mapped, origin) = expansion.map_token_up(db, token.as_ref())?;
650 if origin != Origin::Call {
653 if let Some(info) = mapped.file_id.expansion_info(db) {
654 return ascend_call_token(db, &info, mapped);
659 impl InFile<SyntaxToken> {
660 pub fn ancestors_with_macros(
662 db: &dyn db::AstDatabase,
663 ) -> impl Iterator<Item = InFile<SyntaxNode>> + '_ {
664 self.value.parent().into_iter().flat_map({
665 let file_id = self.file_id;
666 move |parent| InFile::new(file_id, parent).ancestors_with_macros(db)
671 impl<N: AstNode> InFile<N> {
672 pub fn descendants<T: AstNode>(self) -> impl Iterator<Item = InFile<T>> {
673 self.value.syntax().descendants().filter_map(T::cast).map(move |n| self.with_value(n))
676 pub fn syntax(&self) -> InFile<&SyntaxNode> {
677 self.with_value(self.value.syntax())
680 pub fn nodes_with_attributes<'db>(
682 db: &'db dyn db::AstDatabase,
683 ) -> impl Iterator<Item = InFile<N>> + 'db
687 iter::successors(Some(self), move |node| {
688 let InFile { file_id, value } = node.file_id.call_node(db)?;
689 N::cast(value).map(|n| InFile::new(file_id, n))
693 pub fn node_with_attributes(self, db: &dyn db::AstDatabase) -> InFile<N> {
694 self.nodes_with_attributes(db).last().unwrap()
698 /// In Rust, macros expand token trees to token trees. When we want to turn a
699 /// token tree into an AST node, we need to figure out what kind of AST node we
700 /// want: something like `foo` can be a type, an expression, or a pattern.
702 /// Naively, one would think that "what this expands to" is a property of a
703 /// particular macro: macro `m1` returns an item, while macro `m2` returns an
704 /// expression, etc. That's not the case -- macros are polymorphic in the
705 /// result, and can expand to any type of the AST node.
707 /// What defines the actual AST node is the syntactic context of the macro
708 /// invocation. As a contrived example, in `let T![*] = T![*];` the first `T`
709 /// expands to a pattern, while the second one expands to an expression.
711 /// `ExpandTo` captures this bit of information about a particular macro call
713 #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
723 pub fn from_call_site(call: &ast::MacroCall) -> ExpandTo {
724 use syntax::SyntaxKind::*;
726 let syn = call.syntax();
728 let parent = match syn.parent() {
730 None => return ExpandTo::Statements,
733 match parent.kind() {
734 MACRO_ITEMS | SOURCE_FILE | ITEM_LIST => ExpandTo::Items,
735 MACRO_STMTS | EXPR_STMT | STMT_LIST => ExpandTo::Statements,
736 MACRO_PAT => ExpandTo::Pattern,
737 MACRO_TYPE => ExpandTo::Type,
739 ARG_LIST | TRY_EXPR | TUPLE_EXPR | PAREN_EXPR | ARRAY_EXPR | FOR_EXPR | PATH_EXPR
740 | CLOSURE_EXPR | CONDITION | BREAK_EXPR | RETURN_EXPR | MATCH_EXPR | MATCH_ARM
741 | MATCH_GUARD | RECORD_EXPR_FIELD | CALL_EXPR | INDEX_EXPR | METHOD_CALL_EXPR
742 | FIELD_EXPR | AWAIT_EXPR | CAST_EXPR | REF_EXPR | PREFIX_EXPR | RANGE_EXPR
743 | BIN_EXPR => ExpandTo::Expr,
745 // FIXME: Handle LHS Pattern
750 // Unknown , Just guess it is `Items`