9920: minor: Simplify r=Veykril a=Veykril

bors r+

Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
bors[bot] 2021-08-16 14:13:04 +00:00 committed by GitHub
commit 6a07bf6a9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 16 additions and 22 deletions

View File

@ -131,13 +131,8 @@ impl SourceToDefCtx<'_, '_> {
pub(super) fn module_to_def(&mut self, src: InFile<ast::Module>) -> Option<ModuleId> {
let _p = profile::span("module_to_def");
let parent_declaration = src
.as_ref()
.map(|it| it.syntax())
.cloned()
.ancestors_with_macros(self.db.upcast())
.skip(1)
.find_map(|it| {
let parent_declaration =
src.syntax().cloned().ancestors_with_macros(self.db.upcast()).skip(1).find_map(|it| {
let m = ast::Module::cast(it.value.clone())?;
Some(it.with_value(m))
});
@ -217,7 +212,7 @@ impl SourceToDefCtx<'_, '_> {
&mut self,
src: InFile<ast::IdentPat>,
) -> Option<(DefWithBodyId, PatId)> {
let container = self.find_pat_or_label_container(src.as_ref().map(|it| it.syntax()))?;
let container = self.find_pat_or_label_container(src.syntax())?;
let (_body, source_map) = self.db.body_with_source_map(container);
let src = src.map(ast::Pat::from);
let pat_id = source_map.node_pat(src.as_ref())?;
@ -227,7 +222,7 @@ impl SourceToDefCtx<'_, '_> {
&mut self,
src: InFile<ast::SelfParam>,
) -> Option<(DefWithBodyId, PatId)> {
let container = self.find_pat_or_label_container(src.as_ref().map(|it| it.syntax()))?;
let container = self.find_pat_or_label_container(src.syntax())?;
let (_body, source_map) = self.db.body_with_source_map(container);
let pat_id = source_map.node_self_param(src.as_ref())?;
Some((container, pat_id))
@ -236,7 +231,7 @@ impl SourceToDefCtx<'_, '_> {
&mut self,
src: InFile<ast::Label>,
) -> Option<(DefWithBodyId, LabelId)> {
let container = self.find_pat_or_label_container(src.as_ref().map(|it| it.syntax()))?;
let container = self.find_pat_or_label_container(src.syntax())?;
let (_body, source_map) = self.db.body_with_source_map(container);
let label_id = source_map.node_label(src.as_ref())?;
Some((container, label_id))
@ -264,8 +259,7 @@ impl SourceToDefCtx<'_, '_> {
}
pub(super) fn type_param_to_def(&mut self, src: InFile<ast::TypeParam>) -> Option<TypeParamId> {
let container: ChildContainer =
self.find_generic_param_container(src.as_ref().map(|it| it.syntax()))?.into();
let container: ChildContainer = self.find_generic_param_container(src.syntax())?.into();
let db = self.db;
let dyn_map =
&*self.cache.entry(container).or_insert_with(|| container.child_by_source(db));
@ -276,8 +270,7 @@ impl SourceToDefCtx<'_, '_> {
&mut self,
src: InFile<ast::LifetimeParam>,
) -> Option<LifetimeParamId> {
let container: ChildContainer =
self.find_generic_param_container(src.as_ref().map(|it| it.syntax()))?.into();
let container: ChildContainer = self.find_generic_param_container(src.syntax())?.into();
let db = self.db;
let dyn_map =
&*self.cache.entry(container).or_insert_with(|| container.child_by_source(db));
@ -288,8 +281,7 @@ impl SourceToDefCtx<'_, '_> {
&mut self,
src: InFile<ast::ConstParam>,
) -> Option<ConstParamId> {
let container: ChildContainer =
self.find_generic_param_container(src.as_ref().map(|it| it.syntax()))?.into();
let container: ChildContainer = self.find_generic_param_container(src.syntax())?.into();
let db = self.db;
let dyn_map =
&*self.cache.entry(container).or_insert_with(|| container.child_by_source(db));

View File

@ -376,7 +376,7 @@ impl ExpansionInfo {
db::TokenExpander::MacroRules { def_site_token_map, .. }
| db::TokenExpander::MacroDef { def_site_token_map, .. },
Some(tt),
) => (def_site_token_map, tt.as_ref().map(|tt| tt.syntax().clone())),
) => (def_site_token_map, tt.syntax().cloned()),
_ => panic!("`Origin::Def` used with non-`macro_rules!` macro"),
},
};

View File

@ -92,7 +92,7 @@ impl NavigationTarget {
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();
if let Some(src) = module.declaration_source(db) {
let node = src.as_ref().map(|it| it.syntax());
let node = src.syntax();
let full_range = node.original_file_range(db);
let focus_range = src
.value
@ -298,7 +298,7 @@ impl TryToNav for hir::Impl {
let frange = if let Some(item) = &derive_attr {
item.syntax().original_file_range(db)
} else {
src.as_ref().map(|it| it.syntax()).original_file_range(db)
src.syntax().original_file_range(db)
};
let focus_range = if derive_attr.is_some() {
None

View File

@ -117,8 +117,6 @@ pub(crate) fn hover(
let node = token.parent()?;
let definition = match_ast! {
match node {
// We don't use NameClass::referenced_or_defined here as we do not want to resolve
// field pattern shorthands to their definition.
ast::Name(name) => NameClass::classify(&sema, &name).map(|class| match class {
NameClass::Definition(it) | NameClass::ConstReference(it) => it,
NameClass::PatFieldShorthand { local_def, field_ref: _ } => Definition::Local(local_def),
@ -139,6 +137,7 @@ pub(crate) fn hover(
NameClass::defined,
),
_ => {
// intra-doc links
if ast::Comment::cast(token.clone()).is_some() {
cov_mark::hit!(no_highlight_on_comment_hover);
let (attributes, def) = doc_attributes(&sema, &node)?;
@ -153,9 +152,12 @@ pub(crate) fn hover(
Either::Left(it) => Definition::ModuleDef(it),
Either::Right(it) => Definition::Macro(it),
})
// attributes, require special machinery as they are mere ident tokens
} else if let Some(attr) = token.ancestors().find_map(ast::Attr::cast) {
// lints
if let res@Some(_) = try_hover_for_lint(&attr, &token) {
return res;
// derives
} else {
range_override = Some(token.text_range());
try_resolve_derive_input_at(&sema, &attr, &token).map(Definition::Macro)
@ -276,7 +278,7 @@ fn hover_type_info(
"```text\nType: {:>apad$}\nCoerced to: {:>opad$}\n```\n",
uncoerced = original,
coerced = adjusted,
// 6 base padding for static text prefix of each line
// 6 base padding for difference of length of the two text prefixes
apad = 6 + adjusted.len().max(original.len()),
opad = original.len(),
)