});
for token in tokens {
if token.kind() == SyntaxKind::IDENT
- && token.text() == derive_name.as_str()
+ && token.text() == &**derive_name
{
precise_location = Some(token.text_range());
break 'outer;
}
};
acc.push(
- UnresolvedProcMacro { node, precise_location, macro_name: name }.into(),
+ UnresolvedProcMacro {
+ node,
+ precise_location,
+ macro_name: name.map(Into::into),
+ }
+ .into(),
);
}
.attrs()
.filter_map(|it| {
let path = ModPath::from_src(db.upcast(), it.path()?, &hygenic)?;
- if path.as_ident()?.to_string() == "derive" {
+ if path.as_ident()?.to_smol_str() == "derive" {
Some(it)
} else {
None
let key = self.key;
self.attrs
.iter()
- .filter(move |attr| attr.path.as_ident().map_or(false, |s| s.to_string() == key))
+ .filter(move |attr| attr.path.as_ident().map_or(false, |s| s.to_smol_str() == key))
}
}
let actual = scopes
.scope_chain(scope)
.flat_map(|scope| scopes.entries(scope))
- .map(|it| it.name().to_string())
+ .map(|it| it.name().to_smol_str())
.collect::<Vec<_>>()
.join("\n");
let expected = expected.join("\n");
fn lower_const(&mut self, konst: &ast::Const) -> FileItemTreeId<Const> {
let mut name = konst.name().map(|it| it.as_name());
- if name.as_ref().map_or(false, |n| n.to_string().starts_with("_DERIVE_")) {
+ if name.as_ref().map_or(false, |n| n.to_smol_str().starts_with("_DERIVE_")) {
// FIXME: this is a hack to treat consts generated by synstructure as unnamed
// remove this some time in the future
name = None;
krate,
MacroCallKind::Derive {
ast_id: item_attr.ast_id,
- derive_name: last_segment.to_string(),
+ derive_name: last_segment.to_string().into_boxed_str(),
derive_attr_index: derive_attr.ast_index,
},
);
krate,
MacroCallKind::Attr {
ast_id: item_attr.ast_id,
- attr_name: last_segment.to_string(),
+ attr_name: last_segment.to_string().into_boxed_str(),
attr_args: arg,
invoc_attr_index: macro_attr.id.ast_index,
},
fn is_builtin_or_registered_attr(&self, path: &ModPath) -> bool {
if path.kind == PathKind::Plain {
if let Some(tool_module) = path.segments().first() {
- let tool_module = tool_module.to_string();
+ let tool_module = tool_module.to_smol_str();
let is_tool = builtin_attr::TOOL_MODULES
.iter()
.copied()
}
if let Some(name) = path.as_ident() {
- let name = name.to_string();
+ let name = name.to_smol_str();
let is_inert = builtin_attr::INERT_ATTRIBUTES
.iter()
.chain(builtin_attr::EXTRA_ATTRIBUTES)
let path = match attr_path.map(|it| it.as_str()) {
None => {
let mut path = self.dir_path.clone();
- path.push(&name.to_string());
+ path.push(&name.to_smol_str());
path
}
Some(attr_path) => {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
ImportAlias::Underscore => f.write_str("_"),
- ImportAlias::Alias(name) => f.write_str(&name.to_string()),
+ ImportAlias::Alias(name) => f.write_str(&name.to_smol_str()),
}
}
}
},
Derive {
ast_id: AstId<ast::Item>,
- derive_name: String,
+ derive_name: Box<str>,
/// Syntactical index of the invoking `#[derive]` attribute.
///
/// Outer attributes are counted first, then inner attributes. This does not support
},
Attr {
ast_id: AstId<ast::Item>,
- attr_name: String,
+ attr_name: Box<str>,
attr_args: (tt::Subtree, mbe::TokenMap),
/// Syntactical index of the invoking `#[attribute]`.
///
}
/// Returns the textual representation of this name as a [`SmolStr`].
- /// Prefer using this over [`ToString::to_string`] if possible as this conversion is cheaper.
+ /// Prefer using this over [`ToString::to_string`] if possible as this conversion is cheaper in
+ /// the general case.
pub fn to_smol_str(&self) -> SmolStr {
match &self.0 {
Repr::Text(it) => it.clone(),
}
pub(crate) fn from_module_to_decl(db: &RootDatabase, module: hir::Module) -> NavigationTarget {
- let name = module.name(db).map(|it| it.to_string().into()).unwrap_or_default();
+ let name = module.name(db).map(|it| it.to_smol_str()).unwrap_or_default();
if let Some(src) = module.declaration_source(db) {
let node = src.syntax();
let full_range = node.original_file_range(db);
impl ToNav for hir::Module {
fn to_nav(&self, db: &RootDatabase) -> NavigationTarget {
let src = self.definition_source(db);
- let name = self.name(db).map(|it| it.to_string().into()).unwrap_or_default();
+ let name = self.name(db).map(|it| it.to_smol_str()).unwrap_or_default();
let (syntax, focus) = match &src.value {
ModuleSource::SourceFile(node) => (node.syntax(), None),
ModuleSource::Module(node) => {
let full_range = src.with_value(&node).original_file_range(db);
let name = match self.name(db) {
- Some(it) => it.to_string().into(),
+ Some(it) => it.to_smol_str(),
None => "".into(),
};
let kind = if self.is_self(db) {
let FileRange { file_id, range } = src.with_value(node).original_file_range(db);
let focus_range =
src.value.lifetime().and_then(|lt| lt.lifetime_ident_token()).map(|lt| lt.text_range());
- let name = self.name(db).to_string().into();
+ let name = self.name(db).to_smol_str();
NavigationTarget {
file_id,
name,
.map(|it| it.syntax().text_range());
Some(NavigationTarget {
file_id: src.file_id.original_file(db),
- name: self.name(db).to_string().into(),
+ name: self.name(db).to_smol_str(),
kind: Some(SymbolKind::TypeParam),
full_range,
focus_range,
let full_range = src.value.syntax().text_range();
Some(NavigationTarget {
file_id: src.file_id.original_file(db),
- name: self.name(db).to_string().into(),
+ name: self.name(db).to_smol_str(),
kind: Some(SymbolKind::LifetimeParam),
full_range,
focus_range: Some(full_range),
let full_range = src.value.syntax().text_range();
Some(NavigationTarget {
file_id: src.file_id.original_file(db),
- name: self.name(db).to_string().into(),
+ name: self.name(db).to_smol_str(),
kind: Some(SymbolKind::ConstParam),
full_range,
focus_range: src.value.name().map(|n| n.syntax().text_range()),
enum_data
.variants(db)
.into_iter()
- .map(|variant| variant.name(db).to_string())
+ .map(|variant| variant.name(db).to_smol_str())
.any(|enum_name| enum_name == pat_text)
} else {
false
}
if let Some(hir::Adt::Struct(s)) = pat_ty.as_adt() {
- if s.fields(db).is_empty() && s.name(db).to_string() == bind_pat.to_string() {
+ if s.fields(db).is_empty() && s.name(db).to_smol_str() == bind_pat.to_string() {
return true;
}
}
}
let fn_name = match callable.kind() {
- hir::CallableKind::Function(it) => Some(it.name(sema.db).to_string()),
+ hir::CallableKind::Function(it) => Some(it.name(sema.db).to_smol_str()),
_ => None,
};
let fn_name = fn_name.as_deref();
param_name: &str,
) -> bool {
match sema.type_of_expr(argument).and_then(|t| t.original.as_adt()) {
- Some(hir::Adt::Enum(e)) => to_lower_snake_case(&e.name(sema.db).to_string()) == param_name,
+ Some(hir::Adt::Enum(e)) => {
+ to_lower_snake_case(&e.name(sema.db).to_smol_str()) == param_name
+ }
_ => false,
}
}
// if the name differs from the definitions name it has to be an alias
if def
.name(sema.db)
- .map_or(false, |it| it.to_string() != name_ref.text())
+ .map_or(false, |it| it.to_smol_str() != name_ref.text().as_str())
{
Err(format_err!("Renaming aliases is currently unsupported"))
} else {
) -> usize {
cov_mark::hit!(certain_fuzzy_order_test);
let import_name = match proposed_mod_path.segments().last() {
- Some(name) => name.to_string().to_lowercase(),
+ Some(name) => name.to_smol_str().to_lowercase(),
None => return usize::MAX,
};
match import_name.match_indices(user_input_lowercased).next() {
ctx.scope.process_all_names(&mut |name, res| {
if let ScopeDef::GenericParam(hir::GenericParam::LifetimeParam(_)) = res {
- if param_lifetime != Some(&*name.to_string()) {
+ if param_lifetime != Some(&*name.to_smol_str()) {
acc.add_resolution(ctx, name, &res);
}
}
module_chain_to_containing_module_file(module, db)
.into_iter()
.filter_map(|module| module.name(db))
- .try_fold(base_directory, |path, name| path.join(&name.to_string()))
+ .try_fold(base_directory, |path, name| path.join(&name.to_smol_str()))
}
fn module_chain_to_containing_module_file(
hir::AssocItem::TypeAlias(it) => Some(*it),
_ => None,
})
- .find(|alias| alias.name(sema.db).to_string() == name_ref.text())
+ .find(|alias| alias.name(sema.db).to_smol_str() == name_ref.text().as_str())
{
return Some(NameRefClass::Definition(Definition::ModuleDef(
ModuleDef::TypeAlias(ty),
segments.extend(
path.segments()
.iter()
- .map(|segment| make::path_segment(make::name_ref(&segment.to_string()))),
+ .map(|segment| make::path_segment(make::name_ref(&segment.to_smol_str()))),
);
make::path_from_segments(segments, is_abs)
}
let krate = self.1?;
let db = self.0.db;
let res =
- krate.dependencies(db).into_iter().find(|dep| dep.name.to_string() == name)?.krate;
+ krate.dependencies(db).into_iter().find(|dep| dep.name.to_smol_str() == name)?.krate;
Some(res)
}
for segment in path {
module = module.children(db).find_map(|child| {
let name = child.name(db)?;
- if name.to_string() == segment {
+ if name.to_smol_str() == segment {
Some(child)
} else {
None
})?;
}
let def =
- module.scope(db, None).into_iter().find(|(name, _def)| name.to_string() == trait_)?.1;
+ module.scope(db, None).into_iter().find(|(name, _def)| name.to_smol_str() == trait_)?.1;
Some(def)
}
}
unresolved_first_segment: &str,
) -> Option<ItemInNs> {
let segment_is_name = item_name(db, original_item)
- .map(|name| name.to_string() == unresolved_first_segment)
+ .map(|name| name.to_smol_str() == unresolved_first_segment)
.unwrap_or(false);
Some(if segment_is_name {
};
while let Some(module) = current_module {
if let Some(module_name) = module.name(db) {
- if module_name.to_string() == segment_name {
+ if module_name.to_smol_str() == segment_name {
return Some(module);
}
}
})
});
let name = match name {
- Some(name) => name.to_string(),
+ Some(name) => name.to_smol_str(),
None => return,
};
let name = name.as_str();
_ => return None,
};
TryEnum::ALL.iter().find_map(|&var| {
- if enum_.name(sema.db).to_string() == var.type_name() {
+ if enum_.name(sema.db).to_smol_str() == var.type_name() {
return Some(var);
}
None
Some(make::ext::expr_todo())
};
let field =
- make::record_expr_field(make::name_ref(&f.name(ctx.sema.db).to_string()), field_expr)
+ make::record_expr_field(make::name_ref(&f.name(ctx.sema.db).to_smol_str()), field_expr)
.clone_for_update();
new_field_list.add_field(field);
}
None,
|_ty, assoc_item| {
let item_name = assoc_item.name(self.scope.db)?;
- if item_name.to_string().as_str() == name.text() {
+ if item_name.to_smol_str().as_str() == name.text() {
Some(hir::PathResolution::AssocItem(assoc_item))
} else {
None