mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-19 08:40:24 +00:00
Rename hygiene vars and fields to span_map
This commit is contained in:
parent
6208960c48
commit
ab8f12e169
13 changed files with 85 additions and 83 deletions
|
@ -415,35 +415,32 @@ impl AttrsWithOwner {
|
||||||
AttrDefId::StaticId(it) => attrs_from_item_tree_assoc(db, it),
|
AttrDefId::StaticId(it) => attrs_from_item_tree_assoc(db, it),
|
||||||
AttrDefId::FunctionId(it) => attrs_from_item_tree_assoc(db, it),
|
AttrDefId::FunctionId(it) => attrs_from_item_tree_assoc(db, it),
|
||||||
AttrDefId::TypeAliasId(it) => attrs_from_item_tree_assoc(db, it),
|
AttrDefId::TypeAliasId(it) => attrs_from_item_tree_assoc(db, it),
|
||||||
AttrDefId::GenericParamId(it) => {
|
AttrDefId::GenericParamId(it) => match it {
|
||||||
// FIXME: we could probably just make these relative to the params?
|
GenericParamId::ConstParamId(it) => {
|
||||||
match it {
|
let src = it.parent().child_source(db);
|
||||||
GenericParamId::ConstParamId(it) => {
|
RawAttrs::from_attrs_owner(
|
||||||
let src = it.parent().child_source(db);
|
db.upcast(),
|
||||||
RawAttrs::from_attrs_owner(
|
src.with_value(&src.value[it.local_id()]),
|
||||||
db.upcast(),
|
db.span_map(src.file_id).as_ref(),
|
||||||
src.with_value(&src.value[it.local_id()]),
|
)
|
||||||
db.span_map(src.file_id).as_ref(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
GenericParamId::TypeParamId(it) => {
|
|
||||||
let src = it.parent().child_source(db);
|
|
||||||
RawAttrs::from_attrs_owner(
|
|
||||||
db.upcast(),
|
|
||||||
src.with_value(&src.value[it.local_id()]),
|
|
||||||
db.span_map(src.file_id).as_ref(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
GenericParamId::LifetimeParamId(it) => {
|
|
||||||
let src = it.parent.child_source(db);
|
|
||||||
RawAttrs::from_attrs_owner(
|
|
||||||
db.upcast(),
|
|
||||||
src.with_value(&src.value[it.local_id]),
|
|
||||||
db.span_map(src.file_id).as_ref(),
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
GenericParamId::TypeParamId(it) => {
|
||||||
|
let src = it.parent().child_source(db);
|
||||||
|
RawAttrs::from_attrs_owner(
|
||||||
|
db.upcast(),
|
||||||
|
src.with_value(&src.value[it.local_id()]),
|
||||||
|
db.span_map(src.file_id).as_ref(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
GenericParamId::LifetimeParamId(it) => {
|
||||||
|
let src = it.parent.child_source(db);
|
||||||
|
RawAttrs::from_attrs_owner(
|
||||||
|
db.upcast(),
|
||||||
|
src.with_value(&src.value[it.local_id]),
|
||||||
|
db.span_map(src.file_id).as_ref(),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
},
|
||||||
AttrDefId::ExternBlockId(it) => attrs_from_item_tree_loc(db, it),
|
AttrDefId::ExternBlockId(it) => attrs_from_item_tree_loc(db, it),
|
||||||
AttrDefId::ExternCrateId(it) => attrs_from_item_tree_loc(db, it),
|
AttrDefId::ExternCrateId(it) => attrs_from_item_tree_loc(db, it),
|
||||||
AttrDefId::UseId(it) => attrs_from_item_tree_loc(db, it),
|
AttrDefId::UseId(it) => attrs_from_item_tree_loc(db, it),
|
||||||
|
|
|
@ -18,7 +18,7 @@ use crate::{
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Expander {
|
pub struct Expander {
|
||||||
cfg_options: CfgOptions,
|
cfg_options: CfgOptions,
|
||||||
hygiene: SpanMap,
|
span_map: SpanMap,
|
||||||
krate: CrateId,
|
krate: CrateId,
|
||||||
pub(crate) current_file_id: HirFileId,
|
pub(crate) current_file_id: HirFileId,
|
||||||
pub(crate) module: ModuleId,
|
pub(crate) module: ModuleId,
|
||||||
|
@ -41,7 +41,7 @@ impl Expander {
|
||||||
recursion_depth: 0,
|
recursion_depth: 0,
|
||||||
recursion_limit,
|
recursion_limit,
|
||||||
cfg_options: db.crate_graph()[module.krate].cfg_options.clone(),
|
cfg_options: db.crate_graph()[module.krate].cfg_options.clone(),
|
||||||
hygiene: db.span_map(current_file_id),
|
span_map: db.span_map(current_file_id),
|
||||||
krate: module.krate,
|
krate: module.krate,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -95,7 +95,7 @@ impl Expander {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn exit(&mut self, db: &dyn DefDatabase, mut mark: Mark) {
|
pub fn exit(&mut self, db: &dyn DefDatabase, mut mark: Mark) {
|
||||||
self.hygiene = db.span_map(mark.file_id);
|
self.span_map = db.span_map(mark.file_id);
|
||||||
self.current_file_id = mark.file_id;
|
self.current_file_id = mark.file_id;
|
||||||
if self.recursion_depth == u32::MAX {
|
if self.recursion_depth == u32::MAX {
|
||||||
// Recursion limit has been reached somewhere in the macro expansion tree. Reset the
|
// Recursion limit has been reached somewhere in the macro expansion tree. Reset the
|
||||||
|
@ -110,7 +110,7 @@ impl Expander {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ctx<'a>(&self, db: &'a dyn DefDatabase) -> LowerCtx<'a> {
|
pub fn ctx<'a>(&self, db: &'a dyn DefDatabase) -> LowerCtx<'a> {
|
||||||
LowerCtx::new(db, self.hygiene.clone(), self.current_file_id)
|
LowerCtx::new(db, self.span_map.clone(), self.current_file_id)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn to_source<T>(&self, value: T) -> InFile<T> {
|
pub(crate) fn to_source<T>(&self, value: T) -> InFile<T> {
|
||||||
|
@ -118,7 +118,7 @@ impl Expander {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn parse_attrs(&self, db: &dyn DefDatabase, owner: &dyn ast::HasAttrs) -> Attrs {
|
pub(crate) fn parse_attrs(&self, db: &dyn DefDatabase, owner: &dyn ast::HasAttrs) -> Attrs {
|
||||||
Attrs::filter(db, self.krate, RawAttrs::new(db.upcast(), owner, self.hygiene.as_ref()))
|
Attrs::filter(db, self.krate, RawAttrs::new(db.upcast(), owner, self.span_map.as_ref()))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn cfg_options(&self) -> &CfgOptions {
|
pub(crate) fn cfg_options(&self) -> &CfgOptions {
|
||||||
|
@ -130,7 +130,7 @@ impl Expander {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn parse_path(&mut self, db: &dyn DefDatabase, path: ast::Path) -> Option<Path> {
|
pub(crate) fn parse_path(&mut self, db: &dyn DefDatabase, path: ast::Path) -> Option<Path> {
|
||||||
let ctx = LowerCtx::new(db, self.hygiene.clone(), self.current_file_id);
|
let ctx = LowerCtx::new(db, self.span_map.clone(), self.current_file_id);
|
||||||
Path::from_src(path, &ctx)
|
Path::from_src(path, &ctx)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -174,7 +174,7 @@ impl Expander {
|
||||||
let parse = value.cast::<T>()?;
|
let parse = value.cast::<T>()?;
|
||||||
|
|
||||||
self.recursion_depth += 1;
|
self.recursion_depth += 1;
|
||||||
self.hygiene = db.span_map(file_id);
|
self.span_map = db.span_map(file_id);
|
||||||
let old_file_id = std::mem::replace(&mut self.current_file_id, file_id);
|
let old_file_id = std::mem::replace(&mut self.current_file_id, file_id);
|
||||||
let mark = Mark {
|
let mark = Mark {
|
||||||
file_id: old_file_id,
|
file_id: old_file_id,
|
||||||
|
|
|
@ -776,8 +776,8 @@ impl Use {
|
||||||
// Note: The AST unwraps are fine, since if they fail we should have never obtained `index`.
|
// Note: The AST unwraps are fine, since if they fail we should have never obtained `index`.
|
||||||
let ast = InFile::new(file_id, self.ast_id).to_node(db.upcast());
|
let ast = InFile::new(file_id, self.ast_id).to_node(db.upcast());
|
||||||
let ast_use_tree = ast.use_tree().expect("missing `use_tree`");
|
let ast_use_tree = ast.use_tree().expect("missing `use_tree`");
|
||||||
let hygiene = db.span_map(file_id);
|
let span_map = db.span_map(file_id);
|
||||||
let (_, source_map) = lower::lower_use_tree(db, hygiene.as_ref(), ast_use_tree)
|
let (_, source_map) = lower::lower_use_tree(db, span_map.as_ref(), ast_use_tree)
|
||||||
.expect("failed to lower use tree");
|
.expect("failed to lower use tree");
|
||||||
source_map[index].clone()
|
source_map[index].clone()
|
||||||
}
|
}
|
||||||
|
@ -791,8 +791,8 @@ impl Use {
|
||||||
// Note: The AST unwraps are fine, since if they fail we should have never obtained `index`.
|
// Note: The AST unwraps are fine, since if they fail we should have never obtained `index`.
|
||||||
let ast = InFile::new(file_id, self.ast_id).to_node(db.upcast());
|
let ast = InFile::new(file_id, self.ast_id).to_node(db.upcast());
|
||||||
let ast_use_tree = ast.use_tree().expect("missing `use_tree`");
|
let ast_use_tree = ast.use_tree().expect("missing `use_tree`");
|
||||||
let hygiene = db.span_map(file_id);
|
let span_map = db.span_map(file_id);
|
||||||
lower::lower_use_tree(db, hygiene.as_ref(), ast_use_tree)
|
lower::lower_use_tree(db, span_map.as_ref(), ast_use_tree)
|
||||||
.expect("failed to lower use tree")
|
.expect("failed to lower use tree")
|
||||||
.1
|
.1
|
||||||
}
|
}
|
||||||
|
|
|
@ -657,7 +657,8 @@ impl<'a> Ctx<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn lower_visibility(&mut self, item: &dyn ast::HasVisibility) -> RawVisibilityId {
|
fn lower_visibility(&mut self, item: &dyn ast::HasVisibility) -> RawVisibilityId {
|
||||||
let vis = RawVisibility::from_ast_with_hygiene(self.db, item.visibility(), self.span_map());
|
let vis =
|
||||||
|
RawVisibility::from_ast_with_span_map(self.db, item.visibility(), self.span_map());
|
||||||
self.data().vis.alloc(vis)
|
self.data().vis.alloc(vis)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -735,7 +736,7 @@ fn lower_abi(abi: ast::Abi) -> Interned<str> {
|
||||||
|
|
||||||
struct UseTreeLowering<'a> {
|
struct UseTreeLowering<'a> {
|
||||||
db: &'a dyn DefDatabase,
|
db: &'a dyn DefDatabase,
|
||||||
hygiene: SpanMapRef<'a>,
|
span_map: SpanMapRef<'a>,
|
||||||
mapping: Arena<ast::UseTree>,
|
mapping: Arena<ast::UseTree>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -748,7 +749,7 @@ impl UseTreeLowering<'_> {
|
||||||
// E.g. `use something::{inner}` (prefix is `None`, path is `something`)
|
// E.g. `use something::{inner}` (prefix is `None`, path is `something`)
|
||||||
// or `use something::{path::{inner::{innerer}}}` (prefix is `something::path`, path is `inner`)
|
// or `use something::{path::{inner::{innerer}}}` (prefix is `something::path`, path is `inner`)
|
||||||
Some(path) => {
|
Some(path) => {
|
||||||
match ModPath::from_src(self.db.upcast(), path, self.hygiene) {
|
match ModPath::from_src(self.db.upcast(), path, self.span_map) {
|
||||||
Some(it) => Some(it),
|
Some(it) => Some(it),
|
||||||
None => return None, // FIXME: report errors somewhere
|
None => return None, // FIXME: report errors somewhere
|
||||||
}
|
}
|
||||||
|
@ -767,7 +768,7 @@ impl UseTreeLowering<'_> {
|
||||||
} else {
|
} else {
|
||||||
let is_glob = tree.star_token().is_some();
|
let is_glob = tree.star_token().is_some();
|
||||||
let path = match tree.path() {
|
let path = match tree.path() {
|
||||||
Some(path) => Some(ModPath::from_src(self.db.upcast(), path, self.hygiene)?),
|
Some(path) => Some(ModPath::from_src(self.db.upcast(), path, self.span_map)?),
|
||||||
None => None,
|
None => None,
|
||||||
};
|
};
|
||||||
let alias = tree.rename().map(|a| {
|
let alias = tree.rename().map(|a| {
|
||||||
|
@ -803,10 +804,10 @@ impl UseTreeLowering<'_> {
|
||||||
|
|
||||||
pub(crate) fn lower_use_tree(
|
pub(crate) fn lower_use_tree(
|
||||||
db: &dyn DefDatabase,
|
db: &dyn DefDatabase,
|
||||||
hygiene: SpanMapRef<'_>,
|
span_map: SpanMapRef<'_>,
|
||||||
tree: ast::UseTree,
|
tree: ast::UseTree,
|
||||||
) -> Option<(UseTree, Arena<ast::UseTree>)> {
|
) -> Option<(UseTree, Arena<ast::UseTree>)> {
|
||||||
let mut lowering = UseTreeLowering { db, hygiene, mapping: Arena::new() };
|
let mut lowering = UseTreeLowering { db, span_map, mapping: Arena::new() };
|
||||||
let tree = lowering.lower_use_tree(tree)?;
|
let tree = lowering.lower_use_tree(tree)?;
|
||||||
Some((tree, lowering.mapping))
|
Some((tree, lowering.mapping))
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,26 +13,30 @@ use crate::{db::DefDatabase, path::Path};
|
||||||
|
|
||||||
pub struct LowerCtx<'a> {
|
pub struct LowerCtx<'a> {
|
||||||
pub db: &'a dyn DefDatabase,
|
pub db: &'a dyn DefDatabase,
|
||||||
hygiene: SpanMap,
|
span_map: SpanMap,
|
||||||
// FIXME: This optimization is probably pointless, ast id map should pretty much always exist anyways.
|
// FIXME: This optimization is probably pointless, ast id map should pretty much always exist anyways.
|
||||||
ast_id_map: Option<(HirFileId, OnceCell<Arc<AstIdMap>>)>,
|
ast_id_map: Option<(HirFileId, OnceCell<Arc<AstIdMap>>)>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> LowerCtx<'a> {
|
impl<'a> LowerCtx<'a> {
|
||||||
pub fn new(db: &'a dyn DefDatabase, hygiene: SpanMap, file_id: HirFileId) -> Self {
|
pub fn new(db: &'a dyn DefDatabase, span_map: SpanMap, file_id: HirFileId) -> Self {
|
||||||
LowerCtx { db, hygiene, ast_id_map: Some((file_id, OnceCell::new())) }
|
LowerCtx { db, span_map, ast_id_map: Some((file_id, OnceCell::new())) }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_file_id(db: &'a dyn DefDatabase, file_id: HirFileId) -> Self {
|
pub fn with_file_id(db: &'a dyn DefDatabase, file_id: HirFileId) -> Self {
|
||||||
LowerCtx { db, hygiene: db.span_map(file_id), ast_id_map: Some((file_id, OnceCell::new())) }
|
LowerCtx {
|
||||||
|
db,
|
||||||
|
span_map: db.span_map(file_id),
|
||||||
|
ast_id_map: Some((file_id, OnceCell::new())),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn with_hygiene(db: &'a dyn DefDatabase, hygiene: SpanMap) -> Self {
|
pub fn with_span_map(db: &'a dyn DefDatabase, span_map: SpanMap) -> Self {
|
||||||
LowerCtx { db, hygiene, ast_id_map: None }
|
LowerCtx { db, span_map, ast_id_map: None }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn span_map(&self) -> SpanMapRef<'_> {
|
pub(crate) fn span_map(&self) -> SpanMapRef<'_> {
|
||||||
self.hygiene.as_ref()
|
self.span_map.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn lower_path(&self, ast: ast::Path) -> Option<Path> {
|
pub(crate) fn lower_path(&self, ast: ast::Path) -> Option<Path> {
|
||||||
|
|
|
@ -26,7 +26,7 @@ pub(super) fn lower_path(mut path: ast::Path, ctx: &LowerCtx<'_>) -> Option<Path
|
||||||
let mut type_anchor = None;
|
let mut type_anchor = None;
|
||||||
let mut segments = Vec::new();
|
let mut segments = Vec::new();
|
||||||
let mut generic_args = Vec::new();
|
let mut generic_args = Vec::new();
|
||||||
let hygiene = ctx.span_map();
|
let span_map = ctx.span_map();
|
||||||
loop {
|
loop {
|
||||||
let segment = path.segment()?;
|
let segment = path.segment()?;
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ pub(super) fn lower_path(mut path: ast::Path, ctx: &LowerCtx<'_>) -> Option<Path
|
||||||
let name = if name_ref.text() == "$crate" {
|
let name = if name_ref.text() == "$crate" {
|
||||||
kind = resolve_crate_root(
|
kind = resolve_crate_root(
|
||||||
ctx.db.upcast(),
|
ctx.db.upcast(),
|
||||||
hygiene.span_for_range(name_ref.syntax().text_range()).ctx,
|
span_map.span_for_range(name_ref.syntax().text_range()).ctx,
|
||||||
)
|
)
|
||||||
.map(PathKind::DollarCrate)
|
.map(PathKind::DollarCrate)
|
||||||
.unwrap_or(PathKind::Crate);
|
.unwrap_or(PathKind::Crate);
|
||||||
|
@ -159,7 +159,7 @@ pub(super) fn lower_path(mut path: ast::Path, ctx: &LowerCtx<'_>) -> Option<Path
|
||||||
// We follow what it did anyway :)
|
// We follow what it did anyway :)
|
||||||
if segments.len() == 1 && kind == PathKind::Plain {
|
if segments.len() == 1 && kind == PathKind::Plain {
|
||||||
if let Some(_macro_call) = path.syntax().parent().and_then(ast::MacroCall::cast) {
|
if let Some(_macro_call) = path.syntax().parent().and_then(ast::MacroCall::cast) {
|
||||||
let syn_ctxt = hygiene.span_for_range(path.segment()?.syntax().text_range()).ctx;
|
let syn_ctxt = span_map.span_for_range(path.segment()?.syntax().text_range()).ctx;
|
||||||
if let Some(macro_call_id) = ctx.db.lookup_intern_syntax_context(syn_ctxt).outer_expn {
|
if let Some(macro_call_id) = ctx.db.lookup_intern_syntax_context(syn_ctxt).outer_expn {
|
||||||
if ctx.db.lookup_intern_macro_call(macro_call_id).def.local_inner {
|
if ctx.db.lookup_intern_macro_call(macro_call_id).def.local_inner {
|
||||||
kind = match resolve_crate_root(ctx.db.upcast(), syn_ctxt) {
|
kind = match resolve_crate_root(ctx.db.upcast(), syn_ctxt) {
|
||||||
|
|
|
@ -34,22 +34,22 @@ impl RawVisibility {
|
||||||
db: &dyn DefDatabase,
|
db: &dyn DefDatabase,
|
||||||
node: InFile<Option<ast::Visibility>>,
|
node: InFile<Option<ast::Visibility>>,
|
||||||
) -> RawVisibility {
|
) -> RawVisibility {
|
||||||
Self::from_ast_with_hygiene(db, node.value, db.span_map(node.file_id).as_ref())
|
Self::from_ast_with_span_map(db, node.value, db.span_map(node.file_id).as_ref())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn from_ast_with_hygiene(
|
pub(crate) fn from_ast_with_span_map(
|
||||||
db: &dyn DefDatabase,
|
db: &dyn DefDatabase,
|
||||||
node: Option<ast::Visibility>,
|
node: Option<ast::Visibility>,
|
||||||
hygiene: SpanMapRef<'_>,
|
span_map: SpanMapRef<'_>,
|
||||||
) -> RawVisibility {
|
) -> RawVisibility {
|
||||||
Self::from_ast_with_hygiene_and_default(db, node, RawVisibility::private(), hygiene)
|
Self::from_ast_with_span_map_and_default(db, node, RawVisibility::private(), span_map)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub(crate) fn from_ast_with_hygiene_and_default(
|
pub(crate) fn from_ast_with_span_map_and_default(
|
||||||
db: &dyn DefDatabase,
|
db: &dyn DefDatabase,
|
||||||
node: Option<ast::Visibility>,
|
node: Option<ast::Visibility>,
|
||||||
default: RawVisibility,
|
default: RawVisibility,
|
||||||
hygiene: SpanMapRef<'_>,
|
span_map: SpanMapRef<'_>,
|
||||||
) -> RawVisibility {
|
) -> RawVisibility {
|
||||||
let node = match node {
|
let node = match node {
|
||||||
None => return default,
|
None => return default,
|
||||||
|
@ -57,7 +57,7 @@ impl RawVisibility {
|
||||||
};
|
};
|
||||||
match node.kind() {
|
match node.kind() {
|
||||||
ast::VisibilityKind::In(path) => {
|
ast::VisibilityKind::In(path) => {
|
||||||
let path = ModPath::from_src(db.upcast(), path, hygiene);
|
let path = ModPath::from_src(db.upcast(), path, span_map);
|
||||||
let path = match path {
|
let path = match path {
|
||||||
None => return RawVisibility::private(),
|
None => return RawVisibility::private(),
|
||||||
Some(path) => path,
|
Some(path) => path,
|
||||||
|
|
|
@ -42,18 +42,18 @@ impl RawAttrs {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
db: &dyn ExpandDatabase,
|
db: &dyn ExpandDatabase,
|
||||||
owner: &dyn ast::HasAttrs,
|
owner: &dyn ast::HasAttrs,
|
||||||
hygiene: SpanMapRef<'_>,
|
span_map: SpanMapRef<'_>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
let entries = collect_attrs(owner)
|
let entries = collect_attrs(owner)
|
||||||
.filter_map(|(id, attr)| match attr {
|
.filter_map(|(id, attr)| match attr {
|
||||||
Either::Left(attr) => {
|
Either::Left(attr) => {
|
||||||
attr.meta().and_then(|meta| Attr::from_src(db, meta, hygiene, id))
|
attr.meta().and_then(|meta| Attr::from_src(db, meta, span_map, id))
|
||||||
}
|
}
|
||||||
Either::Right(comment) => comment.doc_comment().map(|doc| Attr {
|
Either::Right(comment) => comment.doc_comment().map(|doc| Attr {
|
||||||
id,
|
id,
|
||||||
input: Some(Interned::new(AttrInput::Literal(SmolStr::new(doc)))),
|
input: Some(Interned::new(AttrInput::Literal(SmolStr::new(doc)))),
|
||||||
path: Interned::new(ModPath::from(crate::name!(doc))),
|
path: Interned::new(ModPath::from(crate::name!(doc))),
|
||||||
ctxt: hygiene.span_for_range(comment.syntax().text_range()).ctx,
|
ctxt: span_map.span_for_range(comment.syntax().text_range()).ctx,
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
|
@ -66,9 +66,9 @@ impl RawAttrs {
|
||||||
pub fn from_attrs_owner(
|
pub fn from_attrs_owner(
|
||||||
db: &dyn ExpandDatabase,
|
db: &dyn ExpandDatabase,
|
||||||
owner: InFile<&dyn ast::HasAttrs>,
|
owner: InFile<&dyn ast::HasAttrs>,
|
||||||
hygiene: SpanMapRef<'_>,
|
span_map: SpanMapRef<'_>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self::new(db, owner.value, hygiene)
|
Self::new(db, owner.value, span_map)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn merge(&self, other: Self) -> Self {
|
pub fn merge(&self, other: Self) -> Self {
|
||||||
|
@ -216,10 +216,10 @@ impl Attr {
|
||||||
fn from_src(
|
fn from_src(
|
||||||
db: &dyn ExpandDatabase,
|
db: &dyn ExpandDatabase,
|
||||||
ast: ast::Meta,
|
ast: ast::Meta,
|
||||||
hygiene: SpanMapRef<'_>,
|
span_map: SpanMapRef<'_>,
|
||||||
id: AttrId,
|
id: AttrId,
|
||||||
) -> Option<Attr> {
|
) -> Option<Attr> {
|
||||||
let path = Interned::new(ModPath::from_src(db, ast.path()?, hygiene)?);
|
let path = Interned::new(ModPath::from_src(db, ast.path()?, span_map)?);
|
||||||
let input = if let Some(ast::Expr::Literal(lit)) = ast.expr() {
|
let input = if let Some(ast::Expr::Literal(lit)) = ast.expr() {
|
||||||
let value = match lit.kind() {
|
let value = match lit.kind() {
|
||||||
ast::LiteralKind::String(string) => string.value()?.into(),
|
ast::LiteralKind::String(string) => string.value()?.into(),
|
||||||
|
@ -227,12 +227,12 @@ impl Attr {
|
||||||
};
|
};
|
||||||
Some(Interned::new(AttrInput::Literal(value)))
|
Some(Interned::new(AttrInput::Literal(value)))
|
||||||
} else if let Some(tt) = ast.token_tree() {
|
} else if let Some(tt) = ast.token_tree() {
|
||||||
let tree = syntax_node_to_token_tree(tt.syntax(), hygiene);
|
let tree = syntax_node_to_token_tree(tt.syntax(), span_map);
|
||||||
Some(Interned::new(AttrInput::TokenTree(Box::new(tree))))
|
Some(Interned::new(AttrInput::TokenTree(Box::new(tree))))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
Some(Attr { id, path, input, ctxt: hygiene.span_for_range(ast.syntax().text_range()).ctx })
|
Some(Attr { id, path, input, ctxt: span_map.span_for_range(ast.syntax().text_range()).ctx })
|
||||||
}
|
}
|
||||||
|
|
||||||
fn from_tt(db: &dyn ExpandDatabase, tt: &tt::Subtree, id: AttrId) -> Option<Attr> {
|
fn from_tt(db: &dyn ExpandDatabase, tt: &tt::Subtree, id: AttrId) -> Option<Attr> {
|
||||||
|
|
|
@ -127,7 +127,7 @@ fn lazy_expand(
|
||||||
|
|
||||||
fn eager_macro_recur(
|
fn eager_macro_recur(
|
||||||
db: &dyn ExpandDatabase,
|
db: &dyn ExpandDatabase,
|
||||||
hygiene: &ExpansionSpanMap,
|
span_map: &ExpansionSpanMap,
|
||||||
curr: InFile<SyntaxNode>,
|
curr: InFile<SyntaxNode>,
|
||||||
krate: CrateId,
|
krate: CrateId,
|
||||||
call_site: SyntaxContextId,
|
call_site: SyntaxContextId,
|
||||||
|
@ -170,7 +170,7 @@ fn eager_macro_recur(
|
||||||
};
|
};
|
||||||
let def = match call
|
let def = match call
|
||||||
.path()
|
.path()
|
||||||
.and_then(|path| ModPath::from_src(db, path, SpanMapRef::ExpansionSpanMap(hygiene)))
|
.and_then(|path| ModPath::from_src(db, path, SpanMapRef::ExpansionSpanMap(span_map)))
|
||||||
{
|
{
|
||||||
Some(path) => match macro_resolver(path.clone()) {
|
Some(path) => match macro_resolver(path.clone()) {
|
||||||
Some(def) => def,
|
Some(def) => def,
|
||||||
|
|
|
@ -47,9 +47,9 @@ impl ModPath {
|
||||||
pub fn from_src(
|
pub fn from_src(
|
||||||
db: &dyn ExpandDatabase,
|
db: &dyn ExpandDatabase,
|
||||||
path: ast::Path,
|
path: ast::Path,
|
||||||
hygiene: SpanMapRef<'_>,
|
span_map: SpanMapRef<'_>,
|
||||||
) -> Option<ModPath> {
|
) -> Option<ModPath> {
|
||||||
convert_path(db, None, path, hygiene)
|
convert_path(db, None, path, span_map)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn from_segments(kind: PathKind, segments: impl IntoIterator<Item = Name>) -> ModPath {
|
pub fn from_segments(kind: PathKind, segments: impl IntoIterator<Item = Name>) -> ModPath {
|
||||||
|
@ -194,10 +194,10 @@ fn convert_path(
|
||||||
db: &dyn ExpandDatabase,
|
db: &dyn ExpandDatabase,
|
||||||
prefix: Option<ModPath>,
|
prefix: Option<ModPath>,
|
||||||
path: ast::Path,
|
path: ast::Path,
|
||||||
hygiene: SpanMapRef<'_>,
|
span_map: SpanMapRef<'_>,
|
||||||
) -> Option<ModPath> {
|
) -> Option<ModPath> {
|
||||||
let prefix = match path.qualifier() {
|
let prefix = match path.qualifier() {
|
||||||
Some(qual) => Some(convert_path(db, prefix, qual, hygiene)?),
|
Some(qual) => Some(convert_path(db, prefix, qual, span_map)?),
|
||||||
None => prefix,
|
None => prefix,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -211,7 +211,7 @@ fn convert_path(
|
||||||
ModPath::from_kind(
|
ModPath::from_kind(
|
||||||
resolve_crate_root(
|
resolve_crate_root(
|
||||||
db,
|
db,
|
||||||
hygiene.span_for_range(name_ref.syntax().text_range()).ctx,
|
span_map.span_for_range(name_ref.syntax().text_range()).ctx,
|
||||||
)
|
)
|
||||||
.map(PathKind::DollarCrate)
|
.map(PathKind::DollarCrate)
|
||||||
.unwrap_or(PathKind::Crate),
|
.unwrap_or(PathKind::Crate),
|
||||||
|
@ -265,7 +265,7 @@ fn convert_path(
|
||||||
// We follow what it did anyway :)
|
// We follow what it did anyway :)
|
||||||
if mod_path.segments.len() == 1 && mod_path.kind == PathKind::Plain {
|
if mod_path.segments.len() == 1 && mod_path.kind == PathKind::Plain {
|
||||||
if let Some(_macro_call) = path.syntax().parent().and_then(ast::MacroCall::cast) {
|
if let Some(_macro_call) = path.syntax().parent().and_then(ast::MacroCall::cast) {
|
||||||
let syn_ctx = hygiene.span_for_range(segment.syntax().text_range()).ctx;
|
let syn_ctx = span_map.span_for_range(segment.syntax().text_range()).ctx;
|
||||||
if let Some(macro_call_id) = db.lookup_intern_syntax_context(syn_ctx).outer_expn {
|
if let Some(macro_call_id) = db.lookup_intern_syntax_context(syn_ctx).outer_expn {
|
||||||
if db.lookup_intern_macro_call(macro_call_id).def.local_inner {
|
if db.lookup_intern_macro_call(macro_call_id).def.local_inner {
|
||||||
mod_path.kind = match resolve_crate_root(db, syn_ctx) {
|
mod_path.kind = match resolve_crate_root(db, syn_ctx) {
|
||||||
|
|
|
@ -1732,7 +1732,7 @@ impl HirDisplay for TypeRef {
|
||||||
f.write_joined(bounds, " + ")?;
|
f.write_joined(bounds, " + ")?;
|
||||||
}
|
}
|
||||||
TypeRef::Macro(macro_call) => {
|
TypeRef::Macro(macro_call) => {
|
||||||
let ctx = hir_def::lower::LowerCtx::with_hygiene(
|
let ctx = hir_def::lower::LowerCtx::with_span_map(
|
||||||
f.db.upcast(),
|
f.db.upcast(),
|
||||||
f.db.span_map(macro_call.file_id),
|
f.db.span_map(macro_call.file_id),
|
||||||
);
|
);
|
||||||
|
|
|
@ -866,8 +866,8 @@ impl<'db> SemanticsImpl<'db> {
|
||||||
|
|
||||||
pub fn resolve_trait(&self, path: &ast::Path) -> Option<Trait> {
|
pub fn resolve_trait(&self, path: &ast::Path) -> Option<Trait> {
|
||||||
let analyze = self.analyze(path.syntax())?;
|
let analyze = self.analyze(path.syntax())?;
|
||||||
let hygiene = self.db.span_map(analyze.file_id);
|
let span_map = self.db.span_map(analyze.file_id);
|
||||||
let ctx = LowerCtx::with_hygiene(self.db.upcast(), hygiene);
|
let ctx = LowerCtx::with_span_map(self.db.upcast(), span_map);
|
||||||
let hir_path = Path::from_src(path.clone(), &ctx)?;
|
let hir_path = Path::from_src(path.clone(), &ctx)?;
|
||||||
match analyze.resolver.resolve_path_in_type_ns_fully(self.db.upcast(), &hir_path)? {
|
match analyze.resolver.resolve_path_in_type_ns_fully(self.db.upcast(), &hir_path)? {
|
||||||
TypeNs::TraitId(id) => Some(Trait { id }),
|
TypeNs::TraitId(id) => Some(Trait { id }),
|
||||||
|
|
|
@ -595,7 +595,7 @@ impl SourceAnalyzer {
|
||||||
}
|
}
|
||||||
|
|
||||||
// This must be a normal source file rather than macro file.
|
// This must be a normal source file rather than macro file.
|
||||||
let ctx = LowerCtx::with_hygiene(db.upcast(), db.span_map(self.file_id));
|
let ctx = LowerCtx::with_span_map(db.upcast(), db.span_map(self.file_id));
|
||||||
let hir_path = Path::from_src(path.clone(), &ctx)?;
|
let hir_path = Path::from_src(path.clone(), &ctx)?;
|
||||||
|
|
||||||
// Case where path is a qualifier of a use tree, e.g. foo::bar::{Baz, Qux} where we are
|
// Case where path is a qualifier of a use tree, e.g. foo::bar::{Baz, Qux} where we are
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue