mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-03 07:04:49 +00:00
internal: remove accidental code re-use
FragmentKind played two roles: * entry point to the parser * syntactic category of a macro call These are different use-cases, and warrant different types. For example, macro can't expand to visibility, but we have such fragment today. This PR introduces `ExpandsTo` enum to separate this two use-cases. I suspect we might further split `FragmentKind` into `$x:specifier` enum specific to MBE, and a general parser entry point, but that's for another PR!
This commit is contained in:
parent
847d0faf92
commit
dbb702cfc1
18 changed files with 168 additions and 135 deletions
|
@ -554,17 +554,19 @@ fn option_env_expand(
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use crate::{
|
||||
name::AsName, test_db::TestDB, AstNode, EagerCallInfo, MacroCallId, MacroCallKind,
|
||||
MacroCallLoc,
|
||||
};
|
||||
use std::sync::Arc;
|
||||
|
||||
use base_db::{fixture::WithFixture, SourceDatabase};
|
||||
use expect_test::{expect, Expect};
|
||||
use parser::FragmentKind;
|
||||
use std::sync::Arc;
|
||||
use syntax::ast::NameOwner;
|
||||
|
||||
use crate::{
|
||||
name::AsName, test_db::TestDB, AstNode, EagerCallInfo, ExpandTo, MacroCallId,
|
||||
MacroCallKind, MacroCallLoc,
|
||||
};
|
||||
|
||||
use super::*;
|
||||
|
||||
fn expand_builtin_macro(ra_fixture: &str) -> String {
|
||||
let (db, file_id) = TestDB::with_single_file(ra_fixture);
|
||||
let parsed = db.parse(file_id);
|
||||
|
@ -599,7 +601,7 @@ mod tests {
|
|||
eager: None,
|
||||
kind: MacroCallKind::FnLike {
|
||||
ast_id: AstId::new(file_id.into(), ast_id_map.ast_id(¯o_call)),
|
||||
fragment: FragmentKind::Expr,
|
||||
expand_to: ExpandTo::Expr,
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -614,7 +616,6 @@ mod tests {
|
|||
local_inner: false,
|
||||
};
|
||||
|
||||
let fragment = crate::to_fragment_kind(¯o_call);
|
||||
let args = macro_call.token_tree().unwrap();
|
||||
let parsed_args = mbe::syntax_node_to_token_tree(args.syntax()).0;
|
||||
let call_id = AstId::new(file_id.into(), ast_id_map.ast_id(¯o_call));
|
||||
|
@ -626,10 +627,11 @@ mod tests {
|
|||
arg_or_expansion: Arc::new(parsed_args.clone()),
|
||||
included_file: None,
|
||||
}),
|
||||
kind: MacroCallKind::FnLike { ast_id: call_id, fragment: FragmentKind::Expr },
|
||||
kind: MacroCallKind::FnLike { ast_id: call_id, expand_to: ExpandTo::Expr },
|
||||
});
|
||||
|
||||
let expanded = expander.expand(&db, arg_id, &parsed_args).value.unwrap();
|
||||
let expand_to = crate::ExpandTo::from_call_site(¯o_call);
|
||||
let loc = MacroCallLoc {
|
||||
def,
|
||||
krate,
|
||||
|
@ -637,7 +639,7 @@ mod tests {
|
|||
arg_or_expansion: Arc::new(expanded.subtree),
|
||||
included_file: expanded.included_file,
|
||||
}),
|
||||
kind: MacroCallKind::FnLike { ast_id: call_id, fragment },
|
||||
kind: MacroCallKind::FnLike { ast_id: call_id, expand_to },
|
||||
};
|
||||
|
||||
let id: MacroCallId = db.intern_macro(loc);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue