use profile::Count;
use rustc_hash::FxHashMap;
use smallvec::SmallVec;
+use stdx::never;
use syntax::{ast, match_ast, SyntaxKind};
use crate::{
Some(node) => node,
None => return Default::default(),
};
- if syntax.kind() == SyntaxKind::ERROR {
+ if never!(syntax.kind() == SyntaxKind::ERROR) {
// FIXME: not 100% sure why these crop up, but return an empty tree to avoid a panic
return Default::default();
}
- let hygiene = Hygiene::new(db.upcast(), file_id);
- let ctx = lower::Ctx::new(db, hygiene.clone(), file_id);
+ let ctx = lower::Ctx::new(db, file_id);
let mut top_attrs = None;
let mut item_tree = match_ast! {
match syntax {
ast::SourceFile(file) => {
- top_attrs = Some(RawAttrs::new(db, &file, &hygiene));
+ top_attrs = Some(RawAttrs::new(db, &file, ctx.hygiene()));
ctx.lower_module_items(&file)
},
ast::MacroItems(items) => {
fn block_item_tree(db: &dyn DefDatabase, block: BlockId) -> Arc<ItemTree> {
let loc = db.lookup_intern_block(block);
let block = loc.ast_id.to_node(db.upcast());
- let hygiene = Hygiene::new(db.upcast(), loc.ast_id.file_id);
- let ctx = lower::Ctx::new(db, hygiene.clone(), loc.ast_id.file_id);
+ let ctx = lower::Ctx::new(db, loc.ast_id.file_id);
Arc::new(ctx.lower_block(&block))
}
self.attrs.get(&of).unwrap_or(&RawAttrs::EMPTY)
}
- pub fn attrs(&self, db: &dyn DefDatabase, krate: CrateId, of: AttrOwner) -> Attrs {
+ pub(crate) fn attrs(&self, db: &dyn DefDatabase, krate: CrateId, of: AttrOwner) -> Attrs {
self.raw_attrs(of).clone().filter(db, krate)
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum Param {
- Normal(Interned<TypeRef>),
+ Normal(Option<Name>, Interned<TypeRef>),
Varargs,
}
}
Some((prefix, ImportKind::Plain))
}
- (Some(prefix), PathKind::Super(0)) => {
- // `some::path::self` == `some::path`
- if path.segments().is_empty() {
- Some((prefix, ImportKind::TypeOnly))
- } else {
- None
+ (Some(mut prefix), PathKind::Super(n))
+ if *n > 0 && prefix.segments().is_empty() =>
+ {
+ // `super::super` + `super::rest`
+ match &mut prefix.kind {
+ PathKind::Super(m) => {
+ cov_mark::hit!(concat_super_mod_paths);
+ *m += *n;
+ for segment in path.segments() {
+ prefix.push_segment(segment.clone());
+ }
+ Some((prefix, ImportKind::Plain))
+ }
+ _ => None,
}
}
+ (Some(prefix), PathKind::Super(0)) if path.segments().is_empty() => {
+ // `some::path::self` == `some::path`
+ Some((prefix, ImportKind::TypeOnly))
+ }
(Some(_), _) => None,
}
}
}
}
+impl AssocItem {
+ pub fn ast_id(self, tree: &ItemTree) -> FileAstId<ast::AssocItem> {
+ match self {
+ AssocItem::Function(id) => tree[id].ast_id.upcast(),
+ AssocItem::TypeAlias(id) => tree[id].ast_id.upcast(),
+ AssocItem::Const(id) => tree[id].ast_id.upcast(),
+ AssocItem::MacroCall(id) => tree[id].ast_id.upcast(),
+ }
+ }
+}
+
#[derive(Debug, Eq, PartialEq)]
pub struct Variant {
pub name: Name,