mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-28 10:39:45 +00:00
Merge pull request #19559 from ChayimFriedman2/rust-186
internal: Switch to Rust 1.86.0
This commit is contained in:
commit
55efab890b
81 changed files with 1010 additions and 1258 deletions
|
|
@ -46,7 +46,7 @@ impl Attrs {
|
|||
}
|
||||
|
||||
pub(crate) fn filter(db: &dyn DefDatabase, krate: Crate, raw_attrs: RawAttrs) -> Attrs {
|
||||
Attrs(raw_attrs.filter(db.upcast(), krate))
|
||||
Attrs(raw_attrs.filter(db, krate))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -507,7 +507,7 @@ impl AttrsWithOwner {
|
|||
// FIXME: We should be never getting `None` here.
|
||||
match src.value.get(it.local_id()) {
|
||||
Some(val) => RawAttrs::from_attrs_owner(
|
||||
db.upcast(),
|
||||
db,
|
||||
src.with_value(val),
|
||||
db.span_map(src.file_id).as_ref(),
|
||||
),
|
||||
|
|
@ -519,7 +519,7 @@ impl AttrsWithOwner {
|
|||
// FIXME: We should be never getting `None` here.
|
||||
match src.value.get(it.local_id()) {
|
||||
Some(val) => RawAttrs::from_attrs_owner(
|
||||
db.upcast(),
|
||||
db,
|
||||
src.with_value(val),
|
||||
db.span_map(src.file_id).as_ref(),
|
||||
),
|
||||
|
|
@ -531,7 +531,7 @@ impl AttrsWithOwner {
|
|||
// FIXME: We should be never getting `None` here.
|
||||
match src.value.get(it.local_id) {
|
||||
Some(val) => RawAttrs::from_attrs_owner(
|
||||
db.upcast(),
|
||||
db,
|
||||
src.with_value(val),
|
||||
db.span_map(src.file_id).as_ref(),
|
||||
),
|
||||
|
|
@ -544,7 +544,7 @@ impl AttrsWithOwner {
|
|||
AttrDefId::UseId(it) => attrs_from_item_tree_loc(db, it),
|
||||
};
|
||||
|
||||
let attrs = raw_attrs.filter(db.upcast(), def.krate(db));
|
||||
let attrs = raw_attrs.filter(db, def.krate(db));
|
||||
Attrs(attrs)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
//! Defines database & queries for name resolution.
|
||||
use base_db::{Crate, RootQueryDb, SourceDatabase, Upcast};
|
||||
use base_db::{Crate, RootQueryDb, SourceDatabase};
|
||||
use either::Either;
|
||||
use hir_expand::{HirFileId, MacroDefId, db::ExpandDatabase};
|
||||
use intern::sym;
|
||||
|
|
@ -100,13 +100,7 @@ pub trait InternDatabase: RootQueryDb {
|
|||
}
|
||||
|
||||
#[query_group::query_group]
|
||||
pub trait DefDatabase:
|
||||
InternDatabase
|
||||
+ ExpandDatabase
|
||||
+ SourceDatabase
|
||||
+ Upcast<dyn ExpandDatabase>
|
||||
+ Upcast<dyn RootQueryDb>
|
||||
{
|
||||
pub trait DefDatabase: InternDatabase + ExpandDatabase + SourceDatabase {
|
||||
/// Whether to expand procedural macros during name resolution.
|
||||
#[salsa::input]
|
||||
fn expand_proc_attr_macros(&self) -> bool;
|
||||
|
|
@ -381,7 +375,7 @@ fn include_macro_invoc(
|
|||
.flat_map(|m| m.scope.iter_macro_invoc())
|
||||
.filter_map(|invoc| {
|
||||
db.lookup_intern_macro_call(*invoc.1)
|
||||
.include_file_id(db.upcast(), *invoc.1)
|
||||
.include_file_id(db, *invoc.1)
|
||||
.map(|x| (*invoc.1, x))
|
||||
})
|
||||
.collect()
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ impl Expander {
|
|||
krate: Crate,
|
||||
has_attrs: &dyn HasAttrs,
|
||||
) -> Attrs {
|
||||
Attrs::filter(db, krate, RawAttrs::new(db.upcast(), has_attrs, self.span_map.as_ref()))
|
||||
Attrs::filter(db, krate, RawAttrs::new(db, has_attrs, self.span_map.as_ref()))
|
||||
}
|
||||
|
||||
pub(super) fn is_cfg_enabled(
|
||||
|
|
@ -103,7 +103,7 @@ impl Expander {
|
|||
let result = self.within_limit(db, |this| {
|
||||
let macro_call = this.in_file(¯o_call);
|
||||
match macro_call.as_call_id_with_errors(
|
||||
db.upcast(),
|
||||
db,
|
||||
krate,
|
||||
|path| resolver(path).map(|it| db.macro_def(it)),
|
||||
eager_callback,
|
||||
|
|
@ -178,7 +178,7 @@ impl Expander {
|
|||
self.recursion_depth = u32::MAX;
|
||||
cov_mark::hit!(your_stack_belongs_to_me);
|
||||
return ExpandResult::only_err(ExpandError::new(
|
||||
db.macro_arg_considering_derives(call_id, &call_id.lookup(db.upcast()).kind).2,
|
||||
db.macro_arg_considering_derives(call_id, &call_id.lookup(db).kind).2,
|
||||
ExpandErrorKind::RecursionOverflow,
|
||||
));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -78,7 +78,7 @@ pub(super) fn lower_path(
|
|||
return None;
|
||||
}
|
||||
break kind = resolve_crate_root(
|
||||
collector.db.upcast(),
|
||||
collector.db,
|
||||
collector.expander.ctx_for_range(name_ref.syntax().text_range()),
|
||||
)
|
||||
.map(PathKind::DollarCrate)
|
||||
|
|
@ -216,7 +216,7 @@ pub(super) fn lower_path(
|
|||
let syn_ctxt = collector.expander.ctx_for_range(path.segment()?.syntax().text_range());
|
||||
if let Some(macro_call_id) = syn_ctxt.outer_expn(collector.db) {
|
||||
if collector.db.lookup_intern_macro_call(macro_call_id).def.local_inner {
|
||||
kind = match resolve_crate_root(collector.db.upcast(), syn_ctxt) {
|
||||
kind = match resolve_crate_root(collector.db, syn_ctxt) {
|
||||
Some(crate_root) => PathKind::DollarCrate(crate_root),
|
||||
None => PathKind::Crate,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -53,19 +53,18 @@ pub(crate) fn print_body_hir(
|
|||
edition: Edition,
|
||||
) -> String {
|
||||
let header = match owner {
|
||||
DefWithBodyId::FunctionId(it) => it
|
||||
.lookup(db)
|
||||
.id
|
||||
.resolved(db, |it| format!("fn {}", it.name.display(db.upcast(), edition))),
|
||||
DefWithBodyId::FunctionId(it) => {
|
||||
it.lookup(db).id.resolved(db, |it| format!("fn {}", it.name.display(db, edition)))
|
||||
}
|
||||
DefWithBodyId::StaticId(it) => it
|
||||
.lookup(db)
|
||||
.id
|
||||
.resolved(db, |it| format!("static {} = ", it.name.display(db.upcast(), edition))),
|
||||
.resolved(db, |it| format!("static {} = ", it.name.display(db, edition))),
|
||||
DefWithBodyId::ConstId(it) => it.lookup(db).id.resolved(db, |it| {
|
||||
format!(
|
||||
"const {} = ",
|
||||
match &it.name {
|
||||
Some(name) => name.display(db.upcast(), edition).to_string(),
|
||||
Some(name) => name.display(db, edition).to_string(),
|
||||
None => "_".to_owned(),
|
||||
}
|
||||
)
|
||||
|
|
@ -75,8 +74,8 @@ pub(crate) fn print_body_hir(
|
|||
let enum_loc = loc.parent.lookup(db);
|
||||
format!(
|
||||
"enum {}::{}",
|
||||
enum_loc.id.item_tree(db)[enum_loc.id.value].name.display(db.upcast(), edition),
|
||||
loc.id.item_tree(db)[loc.id.value].name.display(db.upcast(), edition),
|
||||
enum_loc.id.item_tree(db)[enum_loc.id.value].name.display(db, edition),
|
||||
loc.id.item_tree(db)[loc.id.value].name.display(db, edition),
|
||||
)
|
||||
}
|
||||
};
|
||||
|
|
@ -162,7 +161,7 @@ pub(crate) fn print_struct(
|
|||
wln!(p, "#[fundamental]");
|
||||
}
|
||||
w!(p, "struct ");
|
||||
w!(p, "{}", name.display(db.upcast(), edition));
|
||||
w!(p, "{}", name.display(db, edition));
|
||||
print_generic_params(db, generic_params, &mut p);
|
||||
match shape {
|
||||
FieldsShape::Record => wln!(p, " {{...}}"),
|
||||
|
|
@ -219,7 +218,7 @@ pub(crate) fn print_function(
|
|||
w!(p, "extern \"{}\" ", abi.as_str());
|
||||
}
|
||||
w!(p, "fn ");
|
||||
w!(p, "{}", name.display(db.upcast(), edition));
|
||||
w!(p, "{}", name.display(db, edition));
|
||||
print_generic_params(db, generic_params, &mut p);
|
||||
w!(p, "(");
|
||||
for (i, param) in params.iter().enumerate() {
|
||||
|
|
@ -260,7 +259,7 @@ fn print_where_clauses(db: &dyn DefDatabase, generic_params: &GenericParams, p:
|
|||
}
|
||||
WherePredicateTypeTarget::TypeOrConstParam(idx) => {
|
||||
match generic_params[*idx].name() {
|
||||
Some(name) => w!(p, "{}", name.display(db.upcast(), p.edition)),
|
||||
Some(name) => w!(p, "{}", name.display(db, p.edition)),
|
||||
None => w!(p, "Param[{}]", idx.into_raw()),
|
||||
}
|
||||
w!(p, ": ");
|
||||
|
|
@ -278,7 +277,7 @@ fn print_where_clauses(db: &dyn DefDatabase, generic_params: &GenericParams, p:
|
|||
if i != 0 {
|
||||
w!(p, ", ");
|
||||
}
|
||||
w!(p, "{}", lifetime.display(db.upcast(), p.edition));
|
||||
w!(p, "{}", lifetime.display(db, p.edition));
|
||||
}
|
||||
w!(p, "> ");
|
||||
match target {
|
||||
|
|
@ -289,7 +288,7 @@ fn print_where_clauses(db: &dyn DefDatabase, generic_params: &GenericParams, p:
|
|||
}
|
||||
WherePredicateTypeTarget::TypeOrConstParam(idx) => {
|
||||
match generic_params[*idx].name() {
|
||||
Some(name) => w!(p, "{}", name.display(db.upcast(), p.edition)),
|
||||
Some(name) => w!(p, "{}", name.display(db, p.edition)),
|
||||
None => w!(p, "Param[{}]", idx.into_raw()),
|
||||
}
|
||||
w!(p, ": ");
|
||||
|
|
@ -313,7 +312,7 @@ fn print_generic_params(db: &dyn DefDatabase, generic_params: &GenericParams, p:
|
|||
w!(p, ", ");
|
||||
}
|
||||
first = false;
|
||||
w!(p, "{}", param.name.display(db.upcast(), p.edition));
|
||||
w!(p, "{}", param.name.display(db, p.edition));
|
||||
}
|
||||
for (i, param) in generic_params.iter_type_or_consts() {
|
||||
if !first {
|
||||
|
|
@ -321,7 +320,7 @@ fn print_generic_params(db: &dyn DefDatabase, generic_params: &GenericParams, p:
|
|||
}
|
||||
first = false;
|
||||
if let Some(const_param) = param.const_param() {
|
||||
w!(p, "const {}: ", const_param.name.display(db.upcast(), p.edition));
|
||||
w!(p, "const {}: ", const_param.name.display(db, p.edition));
|
||||
p.print_type_ref(const_param.ty);
|
||||
if let Some(default) = const_param.default {
|
||||
w!(p, " = ");
|
||||
|
|
@ -330,7 +329,7 @@ fn print_generic_params(db: &dyn DefDatabase, generic_params: &GenericParams, p:
|
|||
}
|
||||
if let Some(type_param) = param.type_param() {
|
||||
match &type_param.name {
|
||||
Some(name) => w!(p, "{}", name.display(db.upcast(), p.edition)),
|
||||
Some(name) => w!(p, "{}", name.display(db, p.edition)),
|
||||
None => w!(p, "Param[{}]", i.into_raw()),
|
||||
}
|
||||
if let Some(default) = type_param.default {
|
||||
|
|
@ -476,7 +475,7 @@ impl Printer<'_> {
|
|||
offset_of
|
||||
.fields
|
||||
.iter()
|
||||
.format_with(".", |field, f| f(&field.display(self.db.upcast(), edition)))
|
||||
.format_with(".", |field, f| f(&field.display(self.db, edition)))
|
||||
);
|
||||
}
|
||||
Expr::Path(path) => self.print_path(path),
|
||||
|
|
@ -498,7 +497,7 @@ impl Printer<'_> {
|
|||
}
|
||||
Expr::Loop { body, label } => {
|
||||
if let Some(lbl) = label {
|
||||
w!(self, "{}: ", self.store[*lbl].name.display(self.db.upcast(), self.edition));
|
||||
w!(self, "{}: ", self.store[*lbl].name.display(self.db, self.edition));
|
||||
}
|
||||
w!(self, "loop ");
|
||||
self.print_expr(*body);
|
||||
|
|
@ -518,7 +517,7 @@ impl Printer<'_> {
|
|||
}
|
||||
Expr::MethodCall { receiver, method_name, args, generic_args } => {
|
||||
self.print_expr(*receiver);
|
||||
w!(self, ".{}", method_name.display(self.db.upcast(), self.edition));
|
||||
w!(self, ".{}", method_name.display(self.db, self.edition));
|
||||
if let Some(args) = generic_args {
|
||||
w!(self, "::<");
|
||||
self.print_generic_args(args);
|
||||
|
|
@ -556,13 +555,13 @@ impl Printer<'_> {
|
|||
Expr::Continue { label } => {
|
||||
w!(self, "continue");
|
||||
if let Some(lbl) = label {
|
||||
w!(self, " {}", self.store[*lbl].name.display(self.db.upcast(), self.edition));
|
||||
w!(self, " {}", self.store[*lbl].name.display(self.db, self.edition));
|
||||
}
|
||||
}
|
||||
Expr::Break { expr, label } => {
|
||||
w!(self, "break");
|
||||
if let Some(lbl) = label {
|
||||
w!(self, " {}", self.store[*lbl].name.display(self.db.upcast(), self.edition));
|
||||
w!(self, " {}", self.store[*lbl].name.display(self.db, self.edition));
|
||||
}
|
||||
if let Some(expr) = expr {
|
||||
self.whitespace();
|
||||
|
|
@ -607,7 +606,7 @@ impl Printer<'_> {
|
|||
let edition = self.edition;
|
||||
self.indented(|p| {
|
||||
for field in &**fields {
|
||||
w!(p, "{}: ", field.name.display(self.db.upcast(), edition));
|
||||
w!(p, "{}: ", field.name.display(self.db, edition));
|
||||
p.print_expr(field.expr);
|
||||
wln!(p, ",");
|
||||
}
|
||||
|
|
@ -621,7 +620,7 @@ impl Printer<'_> {
|
|||
}
|
||||
Expr::Field { expr, name } => {
|
||||
self.print_expr(*expr);
|
||||
w!(self, ".{}", name.display(self.db.upcast(), self.edition));
|
||||
w!(self, ".{}", name.display(self.db, self.edition));
|
||||
}
|
||||
Expr::Await { expr } => {
|
||||
self.print_expr(*expr);
|
||||
|
|
@ -760,7 +759,7 @@ impl Printer<'_> {
|
|||
Expr::Literal(lit) => self.print_literal(lit),
|
||||
Expr::Block { id: _, statements, tail, label } => {
|
||||
let label = label.map(|lbl| {
|
||||
format!("{}: ", self.store[lbl].name.display(self.db.upcast(), self.edition))
|
||||
format!("{}: ", self.store[lbl].name.display(self.db, self.edition))
|
||||
});
|
||||
self.print_block(label.as_deref(), statements, tail);
|
||||
}
|
||||
|
|
@ -846,7 +845,7 @@ impl Printer<'_> {
|
|||
let oneline = matches!(self.line_format, LineFormat::Oneline);
|
||||
self.indented(|p| {
|
||||
for (idx, arg) in args.iter().enumerate() {
|
||||
let field_name = arg.name.display(self.db.upcast(), edition).to_string();
|
||||
let field_name = arg.name.display(self.db, edition).to_string();
|
||||
|
||||
let mut same_name = false;
|
||||
if let Pat::Bind { id, subpat: None } = &self.store[arg.pat] {
|
||||
|
|
@ -1019,7 +1018,7 @@ impl Printer<'_> {
|
|||
BindingAnnotation::Ref => "ref ",
|
||||
BindingAnnotation::RefMut => "ref mut ",
|
||||
};
|
||||
w!(self, "{}{}", mode, name.display(self.db.upcast(), self.edition));
|
||||
w!(self, "{}{}", mode, name.display(self.db, self.edition));
|
||||
}
|
||||
|
||||
fn print_path(&mut self, path: &Path) {
|
||||
|
|
@ -1030,7 +1029,7 @@ impl Printer<'_> {
|
|||
let loc = $it.lookup(self.db);
|
||||
let tree = loc.item_tree_id().item_tree(self.db);
|
||||
let name = &tree[loc.id.value].name;
|
||||
w!(self, "{}", name.display(self.db.upcast(), self.edition));
|
||||
w!(self, "{}", name.display(self.db, self.edition));
|
||||
}};
|
||||
}
|
||||
match *it {
|
||||
|
|
@ -1046,7 +1045,7 @@ impl Printer<'_> {
|
|||
}
|
||||
|
||||
if let Some(s) = s {
|
||||
w!(self, "::{}", s.display(self.db.upcast(), self.edition));
|
||||
w!(self, "::{}", s.display(self.db, self.edition));
|
||||
}
|
||||
return w!(self, ")");
|
||||
}
|
||||
|
|
@ -1088,7 +1087,7 @@ impl Printer<'_> {
|
|||
w!(self, "::");
|
||||
}
|
||||
|
||||
w!(self, "{}", segment.name.display(self.db.upcast(), self.edition));
|
||||
w!(self, "{}", segment.name.display(self.db, self.edition));
|
||||
if let Some(generics) = segment.args_and_bindings {
|
||||
w!(self, "::<");
|
||||
self.print_generic_args(generics);
|
||||
|
|
@ -1121,7 +1120,7 @@ impl Printer<'_> {
|
|||
w!(self, ", ");
|
||||
}
|
||||
first = false;
|
||||
w!(self, "{}", binding.name.display(self.db.upcast(), self.edition));
|
||||
w!(self, "{}", binding.name.display(self.db, self.edition));
|
||||
if !binding.bounds.is_empty() {
|
||||
w!(self, ": ");
|
||||
self.print_type_bounds(&binding.bounds);
|
||||
|
|
@ -1145,7 +1144,7 @@ impl Printer<'_> {
|
|||
let generic_params = self.db.generic_params(param.parent());
|
||||
|
||||
match generic_params[param.local_id()].name() {
|
||||
Some(name) => w!(self, "{}", name.display(self.db.upcast(), self.edition)),
|
||||
Some(name) => w!(self, "{}", name.display(self.db, self.edition)),
|
||||
None => w!(self, "Param[{}]", param.local_id().into_raw()),
|
||||
}
|
||||
}
|
||||
|
|
@ -1154,7 +1153,7 @@ impl Printer<'_> {
|
|||
match lt_ref {
|
||||
LifetimeRef::Static => w!(self, "'static"),
|
||||
LifetimeRef::Named(lt) => {
|
||||
w!(self, "{}", lt.display(self.db.upcast(), self.edition))
|
||||
w!(self, "{}", lt.display(self.db, self.edition))
|
||||
}
|
||||
LifetimeRef::Placeholder => w!(self, "'_"),
|
||||
LifetimeRef::Error => w!(self, "'{{error}}"),
|
||||
|
|
@ -1270,7 +1269,7 @@ impl Printer<'_> {
|
|||
"for<{}> ",
|
||||
lifetimes
|
||||
.iter()
|
||||
.map(|it| it.display(self.db.upcast(), self.edition))
|
||||
.map(|it| it.display(self.db, self.edition))
|
||||
.format(", ")
|
||||
.to_string()
|
||||
);
|
||||
|
|
@ -1286,7 +1285,7 @@ impl Printer<'_> {
|
|||
}
|
||||
match arg {
|
||||
UseArgRef::Name(it) => {
|
||||
w!(self, "{}", it.display(self.db.upcast(), self.edition))
|
||||
w!(self, "{}", it.display(self.db, self.edition))
|
||||
}
|
||||
UseArgRef::Lifetime(it) => self.print_lifetime_ref(it),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -68,12 +68,7 @@ impl ImportMap {
|
|||
for (k, v) in self.item_to_info_map.iter() {
|
||||
format_to!(out, "{:?} ({:?}) -> ", k, v.1);
|
||||
for v in &v.0 {
|
||||
format_to!(
|
||||
out,
|
||||
"{}:{:?}, ",
|
||||
v.name.display(db.upcast(), Edition::CURRENT),
|
||||
v.container
|
||||
);
|
||||
format_to!(out, "{}:{:?}, ", v.name.display(db, Edition::CURRENT), v.container);
|
||||
}
|
||||
format_to!(out, "\n");
|
||||
}
|
||||
|
|
@ -483,7 +478,7 @@ fn search_maps(
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use base_db::{RootQueryDb, Upcast};
|
||||
use base_db::RootQueryDb;
|
||||
use expect_test::{Expect, expect};
|
||||
use test_fixture::WithFixture;
|
||||
|
||||
|
|
@ -533,10 +528,10 @@ mod tests {
|
|||
})
|
||||
.expect("could not find crate");
|
||||
|
||||
let actual = search_dependencies(db.upcast(), krate, &query)
|
||||
let actual = search_dependencies(&db, krate, &query)
|
||||
.into_iter()
|
||||
.filter_map(|(dependency, _)| {
|
||||
let dependency_krate = dependency.krate(db.upcast())?;
|
||||
let dependency_krate = dependency.krate(&db)?;
|
||||
let dependency_imports = db.import_map(dependency_krate);
|
||||
|
||||
let (path, mark) = match assoc_item_path(&db, &dependency_imports, dependency) {
|
||||
|
|
@ -594,7 +589,7 @@ mod tests {
|
|||
Some(format!(
|
||||
"{}::{}",
|
||||
render_path(db, &trait_info[0]),
|
||||
assoc_item_name.display(db.upcast(), Edition::CURRENT)
|
||||
assoc_item_name.display(db, Edition::CURRENT)
|
||||
))
|
||||
}
|
||||
|
||||
|
|
@ -611,7 +606,7 @@ mod tests {
|
|||
|
||||
let map = db.import_map(krate);
|
||||
|
||||
Some(format!("{name}:\n{}\n", map.fmt_for_test(db.upcast())))
|
||||
Some(format!("{name}:\n{}\n", map.fmt_for_test(&db)))
|
||||
})
|
||||
.sorted()
|
||||
.collect::<String>();
|
||||
|
|
@ -634,7 +629,7 @@ mod tests {
|
|||
module = parent;
|
||||
}
|
||||
|
||||
segments.iter().rev().map(|it| it.display(db.upcast(), Edition::CURRENT)).join("::")
|
||||
segments.iter().rev().map(|it| it.display(db, Edition::CURRENT)).join("::")
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ impl ItemTree {
|
|||
let mut item_tree = match_ast! {
|
||||
match syntax {
|
||||
ast::SourceFile(file) => {
|
||||
top_attrs = Some(RawAttrs::new(db.upcast(), &file, ctx.span_map()));
|
||||
top_attrs = Some(RawAttrs::new(db, &file, ctx.span_map()));
|
||||
ctx.lower_module_items(&file)
|
||||
},
|
||||
ast::MacroItems(items) => {
|
||||
|
|
@ -150,7 +150,7 @@ impl ItemTree {
|
|||
static EMPTY: OnceLock<Arc<ItemTree>> = OnceLock::new();
|
||||
|
||||
let loc = block.lookup(db);
|
||||
let block = loc.ast_id.to_node(db.upcast());
|
||||
let block = loc.ast_id.to_node(db);
|
||||
|
||||
let ctx = lower::Ctx::new(db, loc.ast_id.file_id);
|
||||
let mut item_tree = ctx.lower_block(&block);
|
||||
|
|
@ -885,7 +885,7 @@ impl Use {
|
|||
) -> ast::UseTree {
|
||||
// Re-lower the AST item and get the source map.
|
||||
// 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);
|
||||
let ast_use_tree = ast.use_tree().expect("missing `use_tree`");
|
||||
let (_, source_map) = lower::lower_use_tree(db, ast_use_tree, &mut |range| {
|
||||
db.span_map(file_id).span_for_range(range).ctx
|
||||
|
|
@ -902,7 +902,7 @@ impl Use {
|
|||
) -> Arena<ast::UseTree> {
|
||||
// Re-lower the AST item and get the source map.
|
||||
// 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);
|
||||
let ast_use_tree = ast.use_tree().expect("missing `use_tree`");
|
||||
lower::lower_use_tree(db, ast_use_tree, &mut |range| {
|
||||
db.span_map(file_id).span_for_range(range).ctx
|
||||
|
|
|
|||
|
|
@ -95,9 +95,7 @@ impl<'a> Ctx<'a> {
|
|||
}
|
||||
|
||||
pub(super) fn lower_block(mut self, block: &ast::BlockExpr) -> ItemTree {
|
||||
self.tree
|
||||
.attrs
|
||||
.insert(AttrOwner::TopLevel, RawAttrs::new(self.db.upcast(), block, self.span_map()));
|
||||
self.tree.attrs.insert(AttrOwner::TopLevel, RawAttrs::new(self.db, block, self.span_map()));
|
||||
self.tree.top_level = block
|
||||
.statements()
|
||||
.filter_map(|stmt| match stmt {
|
||||
|
|
@ -146,7 +144,7 @@ impl<'a> Ctx<'a> {
|
|||
ast::Item::MacroDef(ast) => self.lower_macro_def(ast)?.into(),
|
||||
ast::Item::ExternBlock(ast) => self.lower_extern_block(ast).into(),
|
||||
};
|
||||
let attrs = RawAttrs::new(self.db.upcast(), item, self.span_map());
|
||||
let attrs = RawAttrs::new(self.db, item, self.span_map());
|
||||
self.add_attrs(mod_item.into(), attrs);
|
||||
|
||||
Some(mod_item)
|
||||
|
|
@ -172,7 +170,7 @@ impl<'a> Ctx<'a> {
|
|||
ast::AssocItem::Const(ast) => Some(self.lower_const(ast).into()),
|
||||
ast::AssocItem::MacroCall(ast) => self.lower_macro_call(ast).map(Into::into),
|
||||
}?;
|
||||
let attrs = RawAttrs::new(self.db.upcast(), item_node, self.span_map());
|
||||
let attrs = RawAttrs::new(self.db, item_node, self.span_map());
|
||||
self.add_attrs(
|
||||
match item {
|
||||
AssocItem::Function(it) => AttrOwner::ModItem(ModItem::Function(it)),
|
||||
|
|
@ -217,7 +215,7 @@ impl<'a> Ctx<'a> {
|
|||
for (i, field) in it.fields().enumerate() {
|
||||
let data = self.lower_record_field(&field);
|
||||
fields.push(data);
|
||||
let attr = RawAttrs::new(self.db.upcast(), &field, self.span_map());
|
||||
let attr = RawAttrs::new(self.db, &field, self.span_map());
|
||||
if !attr.is_empty() {
|
||||
attrs.push((i, attr))
|
||||
}
|
||||
|
|
@ -231,7 +229,7 @@ impl<'a> Ctx<'a> {
|
|||
for (i, field) in it.fields().enumerate() {
|
||||
let data = self.lower_tuple_field(i, &field);
|
||||
fields.push(data);
|
||||
let attr = RawAttrs::new(self.db.upcast(), &field, self.span_map());
|
||||
let attr = RawAttrs::new(self.db, &field, self.span_map());
|
||||
if !attr.is_empty() {
|
||||
attrs.push((i, attr))
|
||||
}
|
||||
|
|
@ -299,10 +297,7 @@ impl<'a> Ctx<'a> {
|
|||
let start = self.next_variant_idx();
|
||||
for variant in variants.variants() {
|
||||
let idx = self.lower_variant(&variant);
|
||||
self.add_attrs(
|
||||
id(idx).into(),
|
||||
RawAttrs::new(self.db.upcast(), &variant, self.span_map()),
|
||||
);
|
||||
self.add_attrs(id(idx).into(), RawAttrs::new(self.db, &variant, self.span_map()));
|
||||
}
|
||||
let end = self.next_variant_idx();
|
||||
FileItemTreeId(start)..FileItemTreeId(end)
|
||||
|
|
@ -465,7 +460,7 @@ impl<'a> Ctx<'a> {
|
|||
let span_map = self.span_map();
|
||||
let path = m.path()?;
|
||||
let range = path.syntax().text_range();
|
||||
let path = Interned::new(ModPath::from_src(self.db.upcast(), path, &mut |range| {
|
||||
let path = Interned::new(ModPath::from_src(self.db, path, &mut |range| {
|
||||
span_map.span_for_range(range).ctx
|
||||
})?);
|
||||
let ast_id = self.source_ast_id_map.ast_id(m);
|
||||
|
|
@ -508,7 +503,7 @@ impl<'a> Ctx<'a> {
|
|||
ast::ExternItem::TypeAlias(ty) => self.lower_type_alias(ty)?.into(),
|
||||
ast::ExternItem::MacroCall(call) => self.lower_macro_call(call)?.into(),
|
||||
};
|
||||
let attrs = RawAttrs::new(self.db.upcast(), &item, self.span_map());
|
||||
let attrs = RawAttrs::new(self.db, &item, self.span_map());
|
||||
self.add_attrs(mod_item.into(), attrs);
|
||||
Some(mod_item)
|
||||
})
|
||||
|
|
@ -559,7 +554,7 @@ impl UseTreeLowering<'_> {
|
|||
// E.g. `use something::{inner}` (prefix is `None`, path is `something`)
|
||||
// or `use something::{path::{inner::{innerer}}}` (prefix is `something::path`, path is `inner`)
|
||||
Some(path) => {
|
||||
match ModPath::from_src(self.db.upcast(), path, span_for_range) {
|
||||
match ModPath::from_src(self.db, path, span_for_range) {
|
||||
Some(it) => Some(it),
|
||||
None => return None, // FIXME: report errors somewhere
|
||||
}
|
||||
|
|
@ -580,7 +575,7 @@ impl UseTreeLowering<'_> {
|
|||
} else {
|
||||
let is_glob = tree.star_token().is_some();
|
||||
let path = match tree.path() {
|
||||
Some(path) => Some(ModPath::from_src(self.db.upcast(), path, span_for_range)?),
|
||||
Some(path) => Some(ModPath::from_src(self.db, path, span_for_range)?),
|
||||
None => None,
|
||||
};
|
||||
let alias = tree.rename().map(|a| {
|
||||
|
|
@ -639,7 +634,7 @@ fn visibility_from_ast(
|
|||
let Some(node) = node else { return private_vis() };
|
||||
let path = match node.kind() {
|
||||
ast::VisibilityKind::In(path) => {
|
||||
let path = ModPath::from_src(db.upcast(), path, span_for_range);
|
||||
let path = ModPath::from_src(db, path, span_for_range);
|
||||
match path {
|
||||
None => return private_vis(),
|
||||
Some(path) => path,
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ impl Printer<'_> {
|
|||
self,
|
||||
"#{}[{}{}]{}",
|
||||
inner,
|
||||
attr.path.display(self.db.upcast(), self.edition),
|
||||
attr.path.display(self.db, self.edition),
|
||||
attr.input.as_ref().map(|it| it.to_string()).unwrap_or_default(),
|
||||
separated_by,
|
||||
);
|
||||
|
|
@ -112,7 +112,7 @@ impl Printer<'_> {
|
|||
fn print_visibility(&mut self, vis: RawVisibilityId) {
|
||||
match &self.tree[vis] {
|
||||
RawVisibility::Module(path, _expl) => {
|
||||
w!(self, "pub({}) ", path.display(self.db.upcast(), self.edition))
|
||||
w!(self, "pub({}) ", path.display(self.db, self.edition))
|
||||
}
|
||||
RawVisibility::Public => w!(self, "pub "),
|
||||
};
|
||||
|
|
@ -135,7 +135,7 @@ impl Printer<'_> {
|
|||
w!(this, "unsafe ");
|
||||
}
|
||||
|
||||
wln!(this, "{},", name.display(self.db.upcast(), edition));
|
||||
wln!(this, "{},", name.display(self.db, edition));
|
||||
}
|
||||
});
|
||||
w!(self, "}}");
|
||||
|
|
@ -152,7 +152,7 @@ impl Printer<'_> {
|
|||
if *is_unsafe {
|
||||
w!(this, "unsafe ");
|
||||
}
|
||||
wln!(this, "{},", name.display(self.db.upcast(), edition));
|
||||
wln!(this, "{},", name.display(self.db, edition));
|
||||
}
|
||||
});
|
||||
w!(self, ")");
|
||||
|
|
@ -164,20 +164,20 @@ impl Printer<'_> {
|
|||
fn print_use_tree(&mut self, use_tree: &UseTree) {
|
||||
match &use_tree.kind {
|
||||
UseTreeKind::Single { path, alias } => {
|
||||
w!(self, "{}", path.display(self.db.upcast(), self.edition));
|
||||
w!(self, "{}", path.display(self.db, self.edition));
|
||||
if let Some(alias) = alias {
|
||||
w!(self, " as {}", alias.display(self.edition));
|
||||
}
|
||||
}
|
||||
UseTreeKind::Glob { path } => {
|
||||
if let Some(path) = path {
|
||||
w!(self, "{}::", path.display(self.db.upcast(), self.edition));
|
||||
w!(self, "{}::", path.display(self.db, self.edition));
|
||||
}
|
||||
w!(self, "*");
|
||||
}
|
||||
UseTreeKind::Prefixed { prefix, list } => {
|
||||
if let Some(prefix) = prefix {
|
||||
w!(self, "{}::", prefix.display(self.db.upcast(), self.edition));
|
||||
w!(self, "{}::", prefix.display(self.db, self.edition));
|
||||
}
|
||||
w!(self, "{{");
|
||||
for (i, tree) in list.iter().enumerate() {
|
||||
|
|
@ -207,7 +207,7 @@ impl Printer<'_> {
|
|||
let ExternCrate { name, alias, visibility, ast_id } = &self.tree[it];
|
||||
self.print_ast_id(ast_id.erase());
|
||||
self.print_visibility(*visibility);
|
||||
w!(self, "extern crate {}", name.display(self.db.upcast(), self.edition));
|
||||
w!(self, "extern crate {}", name.display(self.db, self.edition));
|
||||
if let Some(alias) = alias {
|
||||
w!(self, " as {}", alias.display(self.edition));
|
||||
}
|
||||
|
|
@ -232,13 +232,13 @@ impl Printer<'_> {
|
|||
let Function { name, visibility, ast_id } = &self.tree[it];
|
||||
self.print_ast_id(ast_id.erase());
|
||||
self.print_visibility(*visibility);
|
||||
wln!(self, "fn {};", name.display(self.db.upcast(), self.edition));
|
||||
wln!(self, "fn {};", name.display(self.db, self.edition));
|
||||
}
|
||||
ModItem::Struct(it) => {
|
||||
let Struct { visibility, name, fields, shape: kind, ast_id } = &self.tree[it];
|
||||
self.print_ast_id(ast_id.erase());
|
||||
self.print_visibility(*visibility);
|
||||
w!(self, "struct {}", name.display(self.db.upcast(), self.edition));
|
||||
w!(self, "struct {}", name.display(self.db, self.edition));
|
||||
self.print_fields(FieldParent::Struct(it), *kind, fields);
|
||||
if matches!(kind, FieldsShape::Record) {
|
||||
wln!(self);
|
||||
|
|
@ -250,7 +250,7 @@ impl Printer<'_> {
|
|||
let Union { name, visibility, fields, ast_id } = &self.tree[it];
|
||||
self.print_ast_id(ast_id.erase());
|
||||
self.print_visibility(*visibility);
|
||||
w!(self, "union {}", name.display(self.db.upcast(), self.edition));
|
||||
w!(self, "union {}", name.display(self.db, self.edition));
|
||||
self.print_fields(FieldParent::Union(it), FieldsShape::Record, fields);
|
||||
wln!(self);
|
||||
}
|
||||
|
|
@ -258,14 +258,14 @@ impl Printer<'_> {
|
|||
let Enum { name, visibility, variants, ast_id } = &self.tree[it];
|
||||
self.print_ast_id(ast_id.erase());
|
||||
self.print_visibility(*visibility);
|
||||
w!(self, "enum {}", name.display(self.db.upcast(), self.edition));
|
||||
w!(self, "enum {}", name.display(self.db, self.edition));
|
||||
let edition = self.edition;
|
||||
self.indented(|this| {
|
||||
for variant in FileItemTreeId::range_iter(variants.clone()) {
|
||||
let Variant { name, fields, shape: kind, ast_id } = &this.tree[variant];
|
||||
this.print_ast_id(ast_id.erase());
|
||||
this.print_attrs_of(variant, "\n");
|
||||
w!(this, "{}", name.display(self.db.upcast(), edition));
|
||||
w!(this, "{}", name.display(self.db, edition));
|
||||
this.print_fields(FieldParent::EnumVariant(variant), *kind, fields);
|
||||
wln!(this, ",");
|
||||
}
|
||||
|
|
@ -278,7 +278,7 @@ impl Printer<'_> {
|
|||
self.print_visibility(*visibility);
|
||||
w!(self, "const ");
|
||||
match name {
|
||||
Some(name) => w!(self, "{}", name.display(self.db.upcast(), self.edition)),
|
||||
Some(name) => w!(self, "{}", name.display(self.db, self.edition)),
|
||||
None => w!(self, "_"),
|
||||
}
|
||||
wln!(self, " = _;");
|
||||
|
|
@ -288,7 +288,7 @@ impl Printer<'_> {
|
|||
self.print_ast_id(ast_id.erase());
|
||||
self.print_visibility(*visibility);
|
||||
w!(self, "static ");
|
||||
w!(self, "{}", name.display(self.db.upcast(), self.edition));
|
||||
w!(self, "{}", name.display(self.db, self.edition));
|
||||
w!(self, " = _;");
|
||||
wln!(self);
|
||||
}
|
||||
|
|
@ -296,7 +296,7 @@ impl Printer<'_> {
|
|||
let Trait { name, visibility, items, ast_id } = &self.tree[it];
|
||||
self.print_ast_id(ast_id.erase());
|
||||
self.print_visibility(*visibility);
|
||||
w!(self, "trait {} {{", name.display(self.db.upcast(), self.edition));
|
||||
w!(self, "trait {} {{", name.display(self.db, self.edition));
|
||||
self.indented(|this| {
|
||||
for item in &**items {
|
||||
this.print_mod_item((*item).into());
|
||||
|
|
@ -308,7 +308,7 @@ impl Printer<'_> {
|
|||
let TraitAlias { name, visibility, ast_id } = &self.tree[it];
|
||||
self.print_ast_id(ast_id.erase());
|
||||
self.print_visibility(*visibility);
|
||||
wln!(self, "trait {} = ..;", name.display(self.db.upcast(), self.edition));
|
||||
wln!(self, "trait {} = ..;", name.display(self.db, self.edition));
|
||||
}
|
||||
ModItem::Impl(it) => {
|
||||
let Impl { items, ast_id } = &self.tree[it];
|
||||
|
|
@ -325,7 +325,7 @@ impl Printer<'_> {
|
|||
let TypeAlias { name, visibility, ast_id } = &self.tree[it];
|
||||
self.print_ast_id(ast_id.erase());
|
||||
self.print_visibility(*visibility);
|
||||
w!(self, "type {}", name.display(self.db.upcast(), self.edition));
|
||||
w!(self, "type {}", name.display(self.db, self.edition));
|
||||
w!(self, ";");
|
||||
wln!(self);
|
||||
}
|
||||
|
|
@ -333,7 +333,7 @@ impl Printer<'_> {
|
|||
let Mod { name, visibility, kind, ast_id } = &self.tree[it];
|
||||
self.print_ast_id(ast_id.erase());
|
||||
self.print_visibility(*visibility);
|
||||
w!(self, "mod {}", name.display(self.db.upcast(), self.edition));
|
||||
w!(self, "mod {}", name.display(self.db, self.edition));
|
||||
match kind {
|
||||
ModKind::Inline { items } => {
|
||||
w!(self, " {{");
|
||||
|
|
@ -358,22 +358,18 @@ impl Printer<'_> {
|
|||
ctxt,
|
||||
expand_to
|
||||
);
|
||||
wln!(self, "{}!(...);", path.display(self.db.upcast(), self.edition));
|
||||
wln!(self, "{}!(...);", path.display(self.db, self.edition));
|
||||
}
|
||||
ModItem::MacroRules(it) => {
|
||||
let MacroRules { name, ast_id } = &self.tree[it];
|
||||
self.print_ast_id(ast_id.erase());
|
||||
wln!(
|
||||
self,
|
||||
"macro_rules! {} {{ ... }}",
|
||||
name.display(self.db.upcast(), self.edition)
|
||||
);
|
||||
wln!(self, "macro_rules! {} {{ ... }}", name.display(self.db, self.edition));
|
||||
}
|
||||
ModItem::Macro2(it) => {
|
||||
let Macro2 { name, visibility, ast_id } = &self.tree[it];
|
||||
self.print_ast_id(ast_id.erase());
|
||||
self.print_visibility(*visibility);
|
||||
wln!(self, "macro {} {{ ... }}", name.display(self.db.upcast(), self.edition));
|
||||
wln!(self, "macro {} {{ ... }}", name.display(self.db, self.edition));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -640,7 +640,7 @@ impl GeneralConstId {
|
|||
GeneralConstId::StaticId(it) => {
|
||||
let loc = it.lookup(db);
|
||||
let tree = loc.item_tree_id().item_tree(db);
|
||||
let name = tree[loc.id.value].name.display(db.upcast(), Edition::CURRENT);
|
||||
let name = tree[loc.id.value].name.display(db, Edition::CURRENT);
|
||||
name.to_string()
|
||||
}
|
||||
GeneralConstId::ConstId(const_id) => {
|
||||
|
|
@ -648,7 +648,7 @@ impl GeneralConstId {
|
|||
let tree = loc.item_tree_id().item_tree(db);
|
||||
tree[loc.id.value].name.as_ref().map_or_else(
|
||||
|| "_".to_owned(),
|
||||
|name| name.display(db.upcast(), Edition::CURRENT).to_string(),
|
||||
|name| name.display(db, Edition::CURRENT).to_string(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -336,11 +336,11 @@ impl ModuleOrigin {
|
|||
&ModuleOrigin::Inline { definition, definition_tree_id } => InFile::new(
|
||||
definition_tree_id.file_id(),
|
||||
ModuleSource::Module(
|
||||
AstId::new(definition_tree_id.file_id(), definition).to_node(db.upcast()),
|
||||
AstId::new(definition_tree_id.file_id(), definition).to_node(db),
|
||||
),
|
||||
),
|
||||
ModuleOrigin::BlockExpr { block, .. } => {
|
||||
InFile::new(block.file_id, ModuleSource::BlockExpr(block.to_node(db.upcast())))
|
||||
InFile::new(block.file_id, ModuleSource::BlockExpr(block.to_node(db)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -607,12 +607,12 @@ impl DefMap {
|
|||
) {
|
||||
format_to!(buf, "{}\n", path);
|
||||
|
||||
map.modules[module].scope.dump(db.upcast(), buf);
|
||||
map.modules[module].scope.dump(db, buf);
|
||||
|
||||
for (name, child) in
|
||||
map.modules[module].children.iter().sorted_by(|a, b| Ord::cmp(&a.0, &b.0))
|
||||
{
|
||||
let path = format!("{path}::{}", name.display(db.upcast(), Edition::LATEST));
|
||||
let path = format!("{path}::{}", name.display(db, Edition::LATEST));
|
||||
buf.push('\n');
|
||||
go(buf, db, map, &path, *child);
|
||||
}
|
||||
|
|
@ -748,17 +748,14 @@ impl ModuleData {
|
|||
&ModuleOrigin::File { definition, .. } | &ModuleOrigin::CrateRoot { definition } => {
|
||||
InFile::new(
|
||||
definition.into(),
|
||||
ErasedAstId::new(definition.into(), ROOT_ERASED_FILE_AST_ID)
|
||||
.to_range(db.upcast()),
|
||||
ErasedAstId::new(definition.into(), ROOT_ERASED_FILE_AST_ID).to_range(db),
|
||||
)
|
||||
}
|
||||
&ModuleOrigin::Inline { definition, definition_tree_id } => InFile::new(
|
||||
definition_tree_id.file_id(),
|
||||
AstId::new(definition_tree_id.file_id(), definition).to_range(db.upcast()),
|
||||
AstId::new(definition_tree_id.file_id(), definition).to_range(db),
|
||||
),
|
||||
ModuleOrigin::BlockExpr { block, .. } => {
|
||||
InFile::new(block.file_id, block.to_range(db.upcast()))
|
||||
}
|
||||
ModuleOrigin::BlockExpr { block, .. } => InFile::new(block.file_id, block.to_range(db)),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -766,7 +763,7 @@ impl ModuleData {
|
|||
/// `None` for the crate root or block.
|
||||
pub fn declaration_source(&self, db: &dyn DefDatabase) -> Option<InFile<ast::Module>> {
|
||||
let decl = self.origin.declaration()?;
|
||||
let value = decl.to_node(db.upcast());
|
||||
let value = decl.to_node(db);
|
||||
Some(InFile { file_id: decl.file_id, value })
|
||||
}
|
||||
|
||||
|
|
@ -774,7 +771,7 @@ impl ModuleData {
|
|||
/// `None` for the crate root or block.
|
||||
pub fn declaration_source_range(&self, db: &dyn DefDatabase) -> Option<InFile<TextRange>> {
|
||||
let decl = self.origin.declaration()?;
|
||||
Some(InFile { file_id: decl.file_id, value: decl.to_range(db.upcast()) })
|
||||
Some(InFile { file_id: decl.file_id, value: decl.to_range(db) })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -259,7 +259,7 @@ impl<'a> AssocItemCollector<'a> {
|
|||
.map(|it| self.db.macro_def(it))
|
||||
};
|
||||
match macro_call_as_call_id(
|
||||
self.db.upcast(),
|
||||
self.db,
|
||||
&AstIdWithPath::new(tree_id.file_id(), ast_id, Clone::clone(path)),
|
||||
ctxt,
|
||||
expand_to,
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ pub(super) fn attr_macro_as_call_id(
|
|||
};
|
||||
|
||||
def.make_call(
|
||||
db.upcast(),
|
||||
db,
|
||||
krate,
|
||||
MacroCallKind::Attr {
|
||||
ast_id: item_attr.ast_id,
|
||||
|
|
@ -146,7 +146,7 @@ pub(super) fn derive_macro_as_call_id(
|
|||
.filter(|(_, def_id)| def_id.is_derive())
|
||||
.ok_or_else(|| UnresolvedMacro { path: item_attr.path.as_ref().clone() })?;
|
||||
let call_id = def_id.make_call(
|
||||
db.upcast(),
|
||||
db,
|
||||
krate,
|
||||
MacroCallKind::Derive {
|
||||
ast_id: item_attr.ast_id,
|
||||
|
|
|
|||
|
|
@ -286,14 +286,13 @@ impl DefCollector<'_> {
|
|||
crate_data.rustc_coherence_is_core = true;
|
||||
}
|
||||
() if *attr_name == sym::feature.clone() => {
|
||||
let features = attr
|
||||
.parse_path_comma_token_tree(self.db.upcast())
|
||||
.into_iter()
|
||||
.flatten()
|
||||
.filter_map(|(feat, _)| match feat.segments() {
|
||||
[name] => Some(name.symbol().clone()),
|
||||
_ => None,
|
||||
});
|
||||
let features =
|
||||
attr.parse_path_comma_token_tree(self.db).into_iter().flatten().filter_map(
|
||||
|(feat, _)| match feat.segments() {
|
||||
[name] => Some(name.symbol().clone()),
|
||||
_ => None,
|
||||
},
|
||||
);
|
||||
crate_data.unstable_features.extend(features);
|
||||
}
|
||||
() if *attr_name == sym::register_attr.clone() => {
|
||||
|
|
@ -549,7 +548,7 @@ impl DefCollector<'_> {
|
|||
types => {
|
||||
tracing::debug!(
|
||||
"could not resolve prelude path `{}` to module (resolved to {:?})",
|
||||
path.display(self.db.upcast(), Edition::LATEST),
|
||||
path.display(self.db, Edition::LATEST),
|
||||
types
|
||||
);
|
||||
}
|
||||
|
|
@ -809,7 +808,7 @@ impl DefCollector<'_> {
|
|||
}
|
||||
|
||||
fn resolve_import(&self, module_id: LocalModuleId, import: &Import) -> PartialResolvedImport {
|
||||
let _p = tracing::info_span!("resolve_import", import_path = %import.path.display(self.db.upcast(), Edition::LATEST))
|
||||
let _p = tracing::info_span!("resolve_import", import_path = %import.path.display(self.db, Edition::LATEST))
|
||||
.entered();
|
||||
tracing::debug!("resolving import: {:?} ({:?})", import, self.def_map.data.edition);
|
||||
let res = self.def_map.resolve_path_fp_with_macro(
|
||||
|
|
@ -1256,7 +1255,7 @@ impl DefCollector<'_> {
|
|||
match &directive.kind {
|
||||
MacroDirectiveKind::FnLike { ast_id, expand_to, ctxt: call_site } => {
|
||||
let call_id = macro_call_as_call_id(
|
||||
self.db.upcast(),
|
||||
self.db,
|
||||
ast_id,
|
||||
*call_site,
|
||||
*expand_to,
|
||||
|
|
@ -1410,7 +1409,7 @@ impl DefCollector<'_> {
|
|||
|
||||
let ast_id = ast_id.with_value(ast_adt_id);
|
||||
|
||||
match attr.parse_path_comma_token_tree(self.db.upcast()) {
|
||||
match attr.parse_path_comma_token_tree(self.db) {
|
||||
Some(derive_macros) => {
|
||||
let call_id = call_id();
|
||||
let mut len = 0;
|
||||
|
|
@ -1517,7 +1516,7 @@ impl DefCollector<'_> {
|
|||
|
||||
let item_tree = self.db.file_item_tree(file_id);
|
||||
|
||||
let mod_dir = if macro_call_id.as_macro_file().is_include_macro(self.db.upcast()) {
|
||||
let mod_dir = if macro_call_id.as_macro_file().is_include_macro(self.db) {
|
||||
ModDir::root()
|
||||
} else {
|
||||
self.mod_dirs[&module_id].clone()
|
||||
|
|
@ -1543,7 +1542,7 @@ impl DefCollector<'_> {
|
|||
MacroDirectiveKind::FnLike { ast_id, expand_to, ctxt: call_site } => {
|
||||
// FIXME: we shouldn't need to re-resolve the macro here just to get the unresolved error!
|
||||
let macro_call_as_call_id = macro_call_as_call_id(
|
||||
self.db.upcast(),
|
||||
self.db,
|
||||
ast_id,
|
||||
*call_site,
|
||||
*expand_to,
|
||||
|
|
@ -1991,8 +1990,7 @@ impl ModCollector<'_, '_> {
|
|||
cov_mark::hit!(macro_rules_from_other_crates_are_visible_with_macro_use);
|
||||
let mut single_imports = Vec::new();
|
||||
for attr in macro_use_attrs {
|
||||
let Some(paths) = attr.parse_path_comma_token_tree(self.def_collector.db.upcast())
|
||||
else {
|
||||
let Some(paths) = attr.parse_path_comma_token_tree(self.def_collector.db) else {
|
||||
// `#[macro_use]` (without any paths) found, forget collected names and just import
|
||||
// all visible macros.
|
||||
self.def_collector.import_macros_from_extern_crate(
|
||||
|
|
@ -2222,7 +2220,7 @@ impl ModCollector<'_, '_> {
|
|||
}
|
||||
tracing::debug!(
|
||||
"non-builtin attribute {}",
|
||||
attr.path.display(self.def_collector.db.upcast(), Edition::LATEST)
|
||||
attr.path.display(self.def_collector.db, Edition::LATEST)
|
||||
);
|
||||
|
||||
let ast_id = AstIdWithPath::new(
|
||||
|
|
@ -2359,8 +2357,8 @@ impl ModCollector<'_, '_> {
|
|||
stdx::always!(
|
||||
name == mac.name,
|
||||
"built-in macro {} has #[rustc_builtin_macro] which declares different name {}",
|
||||
mac.name.display(self.def_collector.db.upcast(), Edition::LATEST),
|
||||
name.display(self.def_collector.db.upcast(), Edition::LATEST),
|
||||
mac.name.display(self.def_collector.db, Edition::LATEST),
|
||||
name.display(self.def_collector.db, Edition::LATEST),
|
||||
);
|
||||
helpers_opt = Some(helpers);
|
||||
}
|
||||
|
|
@ -2424,7 +2422,7 @@ impl ModCollector<'_, '_> {
|
|||
let mut eager_callback_buffer = vec![];
|
||||
// Case 1: try to resolve macro calls with single-segment name and expand macro_rules
|
||||
if let Ok(res) = macro_call_as_call_id_with_eager(
|
||||
db.upcast(),
|
||||
db,
|
||||
ast_id.ast_id,
|
||||
&ast_id.path,
|
||||
ctxt,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
//! This module resolves `mod foo;` declaration to file.
|
||||
use arrayvec::ArrayVec;
|
||||
use base_db::{AnchoredPath, RootQueryDb};
|
||||
use base_db::AnchoredPath;
|
||||
use hir_expand::{HirFileIdExt, name::Name};
|
||||
use span::EditionedFileId;
|
||||
|
||||
|
|
@ -77,11 +77,10 @@ impl ModDir {
|
|||
}
|
||||
};
|
||||
|
||||
let orig_file_id = file_id.original_file_respecting_includes(db.upcast());
|
||||
let orig_file_id = file_id.original_file_respecting_includes(db);
|
||||
for candidate in candidate_files.iter() {
|
||||
let path = AnchoredPath { anchor: orig_file_id.file_id(), path: candidate.as_str() };
|
||||
if let Some(file_id) = base_db::Upcast::<dyn RootQueryDb>::upcast(db).resolve_path(path)
|
||||
{
|
||||
if let Some(file_id) = db.resolve_path(path) {
|
||||
let is_mod_rs = candidate.ends_with("/mod.rs");
|
||||
|
||||
let root_dir_owner = is_mod_rs || attr_path.is_some();
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ use std::{fmt, panic, sync::Mutex};
|
|||
|
||||
use base_db::{
|
||||
Crate, CrateGraphBuilder, CratesMap, FileSourceRootInput, FileText, RootQueryDb,
|
||||
SourceDatabase, SourceRoot, SourceRootId, SourceRootInput, Upcast,
|
||||
SourceDatabase, SourceRoot, SourceRootId, SourceRootInput,
|
||||
};
|
||||
use hir_expand::{InFile, db::ExpandDatabase, files::FilePosition};
|
||||
use hir_expand::{InFile, files::FilePosition};
|
||||
use salsa::{AsDynDatabase, Durability};
|
||||
use span::{EditionedFileId, FileId};
|
||||
use syntax::{AstNode, algo, ast};
|
||||
|
|
@ -44,32 +44,6 @@ impl Default for TestDB {
|
|||
}
|
||||
}
|
||||
|
||||
impl Upcast<dyn ExpandDatabase> for TestDB {
|
||||
#[inline]
|
||||
fn upcast(&self) -> &(dyn ExpandDatabase + 'static) {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Upcast<dyn DefDatabase> for TestDB {
|
||||
#[inline]
|
||||
fn upcast(&self) -> &(dyn DefDatabase + 'static) {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Upcast<dyn RootQueryDb> for TestDB {
|
||||
fn upcast(&self) -> &(dyn RootQueryDb + 'static) {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
impl Upcast<dyn SourceDatabase> for TestDB {
|
||||
fn upcast(&self) -> &(dyn SourceDatabase + 'static) {
|
||||
self
|
||||
}
|
||||
}
|
||||
|
||||
#[salsa::db]
|
||||
impl salsa::Database for TestDB {
|
||||
fn salsa_event(&self, event: &dyn std::ops::Fn() -> salsa::Event) {
|
||||
|
|
@ -158,10 +132,8 @@ impl TestDB {
|
|||
}
|
||||
|
||||
pub(crate) fn module_for_file(&self, file_id: FileId) -> ModuleId {
|
||||
let db = <TestDB as Upcast<dyn DefDatabase>>::upcast(self);
|
||||
|
||||
for &krate in self.relevant_crates(file_id).iter() {
|
||||
let crate_def_map = db.crate_def_map(krate);
|
||||
let crate_def_map = self.crate_def_map(krate);
|
||||
for (local_id, data) in crate_def_map.modules() {
|
||||
if data.origin.file_id().map(EditionedFileId::file_id) == Some(file_id) {
|
||||
return crate_def_map.module_id(local_id);
|
||||
|
|
@ -172,10 +144,8 @@ impl TestDB {
|
|||
}
|
||||
|
||||
pub(crate) fn module_at_position(&self, position: FilePosition) -> ModuleId {
|
||||
let db = <TestDB as Upcast<dyn DefDatabase>>::upcast(self);
|
||||
|
||||
let file_module = self.module_for_file(position.file_id.file_id());
|
||||
let mut def_map = file_module.def_map(db);
|
||||
let mut def_map = file_module.def_map(self);
|
||||
let module = self.mod_at_position(&def_map, position);
|
||||
|
||||
def_map = match self.block_at_position(&def_map, position) {
|
||||
|
|
@ -198,11 +168,10 @@ impl TestDB {
|
|||
|
||||
/// Finds the smallest/innermost module in `def_map` containing `position`.
|
||||
fn mod_at_position(&self, def_map: &DefMap, position: FilePosition) -> LocalModuleId {
|
||||
let db = <TestDB as Upcast<dyn DefDatabase>>::upcast(self);
|
||||
let mut size = None;
|
||||
let mut res = DefMap::ROOT;
|
||||
for (module, data) in def_map.modules() {
|
||||
let src = data.definition_source(db);
|
||||
let src = data.definition_source(self);
|
||||
if src.file_id != position.file_id {
|
||||
continue;
|
||||
}
|
||||
|
|
@ -238,18 +207,17 @@ impl TestDB {
|
|||
}
|
||||
|
||||
fn block_at_position(&self, def_map: &DefMap, position: FilePosition) -> Option<Arc<DefMap>> {
|
||||
let db = <TestDB as Upcast<dyn DefDatabase>>::upcast(self);
|
||||
// Find the smallest (innermost) function in `def_map` containing the cursor.
|
||||
let mut size = None;
|
||||
let mut fn_def = None;
|
||||
for (_, module) in def_map.modules() {
|
||||
let file_id = module.definition_source(db).file_id;
|
||||
let file_id = module.definition_source(self).file_id;
|
||||
if file_id != position.file_id {
|
||||
continue;
|
||||
}
|
||||
for decl in module.scope.declarations() {
|
||||
if let ModuleDefId::FunctionId(it) = decl {
|
||||
let range = it.lookup(db).source(db).value.syntax().text_range();
|
||||
let range = it.lookup(self).source(self).value.syntax().text_range();
|
||||
|
||||
if !range.contains(position.offset) {
|
||||
continue;
|
||||
|
|
@ -275,13 +243,13 @@ impl TestDB {
|
|||
|
||||
// Find the innermost block expression that has a `DefMap`.
|
||||
let def_with_body = fn_def?.into();
|
||||
let source_map = db.body_with_source_map(def_with_body).1;
|
||||
let scopes = db.expr_scopes(def_with_body);
|
||||
let source_map = self.body_with_source_map(def_with_body).1;
|
||||
let scopes = self.expr_scopes(def_with_body);
|
||||
|
||||
let editioned_file_id_wrapper =
|
||||
base_db::EditionedFileId::new(db.as_dyn_database(), position.file_id);
|
||||
base_db::EditionedFileId::new(self.as_dyn_database(), position.file_id);
|
||||
|
||||
let root_syntax_node = db.parse(editioned_file_id_wrapper).syntax_node();
|
||||
let root_syntax_node = self.parse(editioned_file_id_wrapper).syntax_node();
|
||||
let scope_iter =
|
||||
algo::ancestors_at_offset(&root_syntax_node, position.offset).filter_map(|node| {
|
||||
let block = ast::BlockExpr::cast(node)?;
|
||||
|
|
@ -298,7 +266,7 @@ impl TestDB {
|
|||
let mut containing_blocks =
|
||||
scopes.scope_chain(Some(scope)).filter_map(|scope| scopes.block(scope));
|
||||
|
||||
if let Some(block) = containing_blocks.next().map(|block| db.block_def_map(block)) {
|
||||
if let Some(block) = containing_blocks.next().map(|block| self.block_def_map(block)) {
|
||||
return Some(block);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue