diff --git a/crates/hir-def/src/visibility.rs b/crates/hir-def/src/visibility.rs index 8d27884c26..3294ce29a4 100644 --- a/crates/hir-def/src/visibility.rs +++ b/crates/hir-def/src/visibility.rs @@ -4,7 +4,6 @@ use std::iter; use hir_expand::{span_map::SpanMapRef, InFile}; use la_arena::ArenaMap; -use stdx::assert_eq_size; use syntax::ast; use triomphe::Arc; @@ -25,7 +24,6 @@ pub enum RawVisibility { /// `pub`. Public, } -assert_eq_size!(RawVisibility, 48); impl RawVisibility { pub(crate) const fn private() -> RawVisibility { diff --git a/crates/hir-expand/src/lib.rs b/crates/hir-expand/src/lib.rs index 37b41c09c5..05f12527a4 100644 --- a/crates/hir-expand/src/lib.rs +++ b/crates/hir-expand/src/lib.rs @@ -26,7 +26,6 @@ pub mod span_map; mod fixup; use attrs::collect_attrs; -use stdx::assert_eq_size; use triomphe::Arc; use std::{fmt, hash::Hash}; @@ -176,7 +175,6 @@ pub struct MacroCallLoc { pub kind: MacroCallKind, pub call_site: Span, } -assert_eq_size!(MacroCallLoc, 104); #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub struct MacroDefId { @@ -187,7 +185,6 @@ pub struct MacroDefId { pub allow_internal_unsafe: bool, pub span: Span, } -assert_eq_size!(MacroDefId, 44); #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] pub enum MacroDefKind { diff --git a/crates/hir-expand/src/mod_path.rs b/crates/hir-expand/src/mod_path.rs index 6dc01fba91..0eb1fc1eb5 100644 --- a/crates/hir-expand/src/mod_path.rs +++ b/crates/hir-expand/src/mod_path.rs @@ -15,7 +15,6 @@ use crate::{ use base_db::CrateId; use smallvec::SmallVec; use span::SyntaxContextId; -use stdx::assert_eq_size; use syntax::{ast, AstNode}; #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] @@ -23,7 +22,6 @@ pub struct ModPath { pub kind: PathKind, segments: SmallVec<[Name; 1]>, } -assert_eq_size!(ModPath, 40); #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)] pub struct UnescapedModPath<'a>(&'a ModPath); diff --git a/crates/hir-expand/src/name.rs b/crates/hir-expand/src/name.rs index 6ebefde32c..91c362399e 100644 --- a/crates/hir-expand/src/name.rs +++ b/crates/hir-expand/src/name.rs @@ -2,7 +2,6 @@ use std::fmt; -use stdx::assert_eq_size; use syntax::{ast, format_smolstr, utils::is_raw_identifier, SmolStr}; /// `Name` is a wrapper around string, which is used in hir for both references @@ -14,7 +13,6 @@ use syntax::{ast, format_smolstr, utils::is_raw_identifier, SmolStr}; /// name without "r#". #[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] pub struct Name(Repr); -assert_eq_size!(Name, 24); /// Wrapper of `Name` to print the name without "r#" even when it is a raw identifier. #[derive(Debug, Clone, PartialEq, Eq, Hash, PartialOrd, Ord)] diff --git a/crates/hir/src/attrs.rs b/crates/hir/src/attrs.rs index 7b9f895bc7..fc0a196df7 100644 --- a/crates/hir/src/attrs.rs +++ b/crates/hir/src/attrs.rs @@ -2,7 +2,6 @@ use std::ops::ControlFlow; -use base_db::FileId; use hir_def::{ attr::AttrsWithOwner, item_scope::ItemInNs, @@ -11,12 +10,8 @@ use hir_def::{ resolver::{HasResolver, Resolver, TypeNs}, AssocItemId, AttrDefId, ModuleDefId, }; -use hir_expand::{ - name::Name, - span_map::{RealSpanMap, SpanMapRef}, -}; +use hir_expand::{mod_path::PathKind, name::Name}; use hir_ty::{db::HirDatabase, method_resolution}; -use syntax::{ast, AstNode}; use crate::{ Adt, AsAssocItem, AssocItem, BuiltinType, Const, ConstParam, DocLinkDef, Enum, ExternCrateDecl, @@ -129,7 +124,7 @@ fn resolve_doc_path_on_( AttrDefId::GenericParamId(_) => return None, }; - let mut modpath = modpath_from_str(db, link)?; + let mut modpath = modpath_from_str(link)?; let resolved = resolver.resolve_module_path_in_items(db.upcast(), &modpath); if resolved.is_none() { @@ -305,34 +300,37 @@ fn as_module_def_if_namespace_matches( (ns.unwrap_or(expected_ns) == expected_ns).then(|| DocLinkDef::ModuleDef(def)) } -fn modpath_from_str(db: &dyn HirDatabase, link: &str) -> Option { +fn modpath_from_str(link: &str) -> Option { // FIXME: this is not how we should get a mod path here. let try_get_modpath = |link: &str| { - let ast_path = ast::SourceFile::parse(&format!("type T = {link};")) - .syntax_node() - .descendants() - .find_map(ast::Path::cast)?; - if ast_path.syntax().text() != link { - return None; - } - ModPath::from_src( - db.upcast(), - ast_path, - SpanMapRef::RealSpanMap(&RealSpanMap::absolute(FileId::BOGUS)), - ) + let mut parts = link.split("::"); + let mut first_segment = None; + let kind = match parts.next()? { + "" => PathKind::Abs, + "crate" => PathKind::Crate, + "self" => PathKind::Super(0), + "super" => { + let mut deg = 1; + while let Some(segment) = parts.next() { + if segment == "super" { + deg += 1; + } else { + first_segment = Some(segment); + break; + } + } + PathKind::Super(deg) + } + segment => { + first_segment = Some(segment); + PathKind::Plain + } + }; + let parts = first_segment.into_iter().chain(parts).map(|segment| match segment.parse() { + Ok(idx) => Name::new_tuple_field(idx), + Err(_) => Name::new_text_dont_use(segment.into()), + }); + Some(ModPath::from_segments(kind, parts)) }; - - let full = try_get_modpath(link); - if full.is_some() { - return full; - } - - // Tuple field names cannot be a part of `ModPath` usually, but rustdoc can - // resolve doc paths like `TupleStruct::0`. - // FIXME: Find a better way to handle these. - let (base, maybe_tuple_field) = link.rsplit_once("::")?; - let tuple_field = Name::new_tuple_field(maybe_tuple_field.parse().ok()?); - let mut modpath = try_get_modpath(base)?; - modpath.push_segment(tuple_field); - Some(modpath) + try_get_modpath(link) } diff --git a/crates/proc-macro-srv/src/server/token_id.rs b/crates/proc-macro-srv/src/server/token_id.rs index f3da01cb10..c83e09af0d 100644 --- a/crates/proc-macro-srv/src/server/token_id.rs +++ b/crates/proc-macro-srv/src/server/token_id.rs @@ -206,7 +206,7 @@ impl server::TokenStream for TokenIdServer { stream: if subtree.token_trees.is_empty() { None } else { - Some(subtree.token_trees) + Some(TokenStream { token_trees: subtree.token_trees }) }, span: bridge::DelimSpan::from_single(subtree.delimiter.open), }), diff --git a/crates/span/src/lib.rs b/crates/span/src/lib.rs index 426e4cb55a..6796dc4188 100644 --- a/crates/span/src/lib.rs +++ b/crates/span/src/lib.rs @@ -2,7 +2,6 @@ use std::fmt::{self, Write}; use salsa::InternId; -use stdx::assert_eq_size; mod map; @@ -36,7 +35,6 @@ pub const FIXUP_ERASED_FILE_AST_ID_MARKER: ErasedFileAstId = la_arena::Idx::from_raw(la_arena::RawIdx::from_u32(!0 - 1)); pub type Span = SpanData; -assert_eq_size!(Span, 20); #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] pub struct SpanData { diff --git a/crates/stdx/src/macros.rs b/crates/stdx/src/macros.rs index 9f7b7dbc1a..d71e418c89 100644 --- a/crates/stdx/src/macros.rs +++ b/crates/stdx/src/macros.rs @@ -59,12 +59,3 @@ macro_rules! impl_from { )* } } - -#[macro_export] -macro_rules! assert_eq_size { - ($($ty:ty,)+ $val:expr $(,)?) => { - const _: () = { - $(core::mem::transmute::<[u8; $val], $ty>;)+ - }; - }; -}