mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-11-02 04:48:13 +00:00
Remove Name::to_smol_str
This commit is contained in:
parent
df5f1777b8
commit
2346a80ab4
54 changed files with 288 additions and 190 deletions
|
|
@ -17,7 +17,7 @@ use hir::{
|
|||
use stdx::{format_to, impl_from};
|
||||
use syntax::{
|
||||
ast::{self, AstNode},
|
||||
match_ast, SyntaxKind, SyntaxNode, SyntaxToken,
|
||||
match_ast, SyntaxKind, SyntaxNode, SyntaxToken, ToSmolStr,
|
||||
};
|
||||
|
||||
use crate::documentation::{Documentation, HasDocs};
|
||||
|
|
@ -670,7 +670,7 @@ impl NameRefClass {
|
|||
hir::AssocItem::TypeAlias(it) => Some(it),
|
||||
_ => None,
|
||||
})
|
||||
.find(|alias| alias.name(sema.db).to_smol_str() == name_ref.text().as_str())
|
||||
.find(|alias| alias.name(sema.db).display_no_db().to_smolstr() == name_ref.text().as_str())
|
||||
{
|
||||
return Some(NameRefClass::Definition(Definition::TypeAlias(ty)));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
use base_db::{CrateOrigin, LangCrateOrigin, SourceDatabase};
|
||||
use hir::{Crate, Enum, Function, Macro, Module, ScopeDef, Semantics, Trait};
|
||||
use syntax::ToSmolStr;
|
||||
|
||||
use crate::RootDatabase;
|
||||
|
||||
|
|
@ -198,15 +199,18 @@ impl FamousDefs<'_, '_> {
|
|||
for segment in path {
|
||||
module = module.children(db).find_map(|child| {
|
||||
let name = child.name(db)?;
|
||||
if name.to_smol_str() == segment {
|
||||
if name.display_no_db().to_smolstr() == segment {
|
||||
Some(child)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})?;
|
||||
}
|
||||
let def =
|
||||
module.scope(db, None).into_iter().find(|(name, _def)| name.to_smol_str() == trait_)?.1;
|
||||
let def = module
|
||||
.scope(db, None)
|
||||
.into_iter()
|
||||
.find(|(name, _def)| name.display_no_db().to_smolstr() == trait_)?
|
||||
.1;
|
||||
Some(def)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use base_db::{FileId, SourceDatabaseExt};
|
|||
use hir::{Crate, DescendPreference, ItemInNs, ModuleDef, Name, Semantics};
|
||||
use syntax::{
|
||||
ast::{self, make},
|
||||
AstToken, SyntaxKind, SyntaxToken, TokenAtOffset,
|
||||
AstToken, SyntaxKind, SyntaxToken, ToSmolStr, TokenAtOffset,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
|
|
@ -50,9 +50,9 @@ pub fn mod_path_to_ast(path: &hir::ModPath) -> ast::Path {
|
|||
}
|
||||
|
||||
segments.extend(
|
||||
path.segments()
|
||||
.iter()
|
||||
.map(|segment| make::path_segment(make::name_ref(&segment.to_smol_str()))),
|
||||
path.segments().iter().map(|segment| {
|
||||
make::path_segment(make::name_ref(&segment.display_no_db().to_smolstr()))
|
||||
}),
|
||||
);
|
||||
make::path_from_segments(segments, is_abs)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use itertools::{EitherOrBoth, Itertools};
|
|||
use rustc_hash::{FxHashMap, FxHashSet};
|
||||
use syntax::{
|
||||
ast::{self, make, HasName},
|
||||
AstNode, SmolStr, SyntaxNode,
|
||||
AstNode, SmolStr, SyntaxNode, ToSmolStr,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
|
|
@ -459,7 +459,7 @@ fn find_import_for_segment(
|
|||
unresolved_first_segment: &str,
|
||||
) -> Option<ItemInNs> {
|
||||
let segment_is_name = item_name(db, original_item)
|
||||
.map(|name| name.to_smol_str() == unresolved_first_segment)
|
||||
.map(|name| name.display_no_db().to_smolstr() == unresolved_first_segment)
|
||||
.unwrap_or(false);
|
||||
|
||||
Some(if segment_is_name {
|
||||
|
|
@ -483,7 +483,7 @@ fn module_with_segment_name(
|
|||
};
|
||||
while let Some(module) = current_module {
|
||||
if let Some(module_name) = module.name(db) {
|
||||
if module_name.to_smol_str() == segment_name {
|
||||
if module_name.display_no_db().to_smolstr() == segment_name {
|
||||
return Some(module);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ use memchr::memmem::Finder;
|
|||
use nohash_hasher::IntMap;
|
||||
use once_cell::unsync::Lazy;
|
||||
use parser::SyntaxKind;
|
||||
use syntax::{ast, match_ast, AstNode, AstToken, SyntaxElement, TextRange, TextSize};
|
||||
use syntax::{ast, match_ast, AstNode, AstToken, SyntaxElement, TextRange, TextSize, ToSmolStr};
|
||||
use triomphe::Arc;
|
||||
|
||||
use crate::{
|
||||
|
|
@ -468,7 +468,10 @@ impl<'a> FindUsages<'a> {
|
|||
};
|
||||
// We need to unescape the name in case it is written without "r#" in earlier
|
||||
// editions of Rust where it isn't a keyword.
|
||||
self.def.name(sema.db).or_else(self_kw_refs).map(|it| it.unescaped().to_smol_str())
|
||||
self.def
|
||||
.name(sema.db)
|
||||
.or_else(self_kw_refs)
|
||||
.map(|it| it.unescaped().display(sema.db).to_smolstr())
|
||||
}
|
||||
};
|
||||
let name = match &name {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,10 @@
|
|||
use std::iter;
|
||||
|
||||
use hir::Semantics;
|
||||
use syntax::ast::{self, make, Pat};
|
||||
use syntax::{
|
||||
ast::{self, make, Pat},
|
||||
ToSmolStr,
|
||||
};
|
||||
|
||||
use crate::RootDatabase;
|
||||
|
||||
|
|
@ -26,7 +29,7 @@ impl TryEnum {
|
|||
_ => return None,
|
||||
};
|
||||
TryEnum::ALL.iter().find_map(|&var| {
|
||||
if enum_.name(sema.db).to_smol_str() == var.type_name() {
|
||||
if enum_.name(sema.db).display_no_db().to_smolstr() == var.type_name() {
|
||||
return Some(var);
|
||||
}
|
||||
None
|
||||
|
|
|
|||
|
|
@ -1,7 +1,10 @@
|
|||
//! Functionality for generating trivial constructors
|
||||
|
||||
use hir::StructKind;
|
||||
use syntax::ast::{make, Expr, Path};
|
||||
use syntax::{
|
||||
ast::{make, Expr, Path},
|
||||
ToSmolStr,
|
||||
};
|
||||
|
||||
/// given a type return the trivial constructor (if one exists)
|
||||
pub fn use_trivial_constructor(
|
||||
|
|
@ -15,7 +18,9 @@ pub fn use_trivial_constructor(
|
|||
if variant.kind(db) == hir::StructKind::Unit {
|
||||
let path = make::path_qualified(
|
||||
path,
|
||||
make::path_segment(make::name_ref(&variant.name(db).to_smol_str())),
|
||||
make::path_segment(make::name_ref(
|
||||
&variant.name(db).display_no_db().to_smolstr(),
|
||||
)),
|
||||
);
|
||||
|
||||
return Some(make::expr_path(path));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue