Skip to content

Commit 0c0142f

Browse files
committed
Simplify
1 parent b641a66 commit 0c0142f

File tree

4 files changed

+16
-22
lines changed

4 files changed

+16
-22
lines changed

crates/hir/src/semantics/source_to_def.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -131,13 +131,8 @@ impl SourceToDefCtx<'_, '_> {
131131

132132
pub(super) fn module_to_def(&mut self, src: InFile<ast::Module>) -> Option<ModuleId> {
133133
let _p = profile::span("module_to_def");
134-
let parent_declaration = src
135-
.as_ref()
136-
.map(|it| it.syntax())
137-
.cloned()
138-
.ancestors_with_macros(self.db.upcast())
139-
.skip(1)
140-
.find_map(|it| {
134+
let parent_declaration =
135+
src.syntax().cloned().ancestors_with_macros(self.db.upcast()).skip(1).find_map(|it| {
141136
let m = ast::Module::cast(it.value.clone())?;
142137
Some(it.with_value(m))
143138
});
@@ -217,7 +212,7 @@ impl SourceToDefCtx<'_, '_> {
217212
&mut self,
218213
src: InFile<ast::IdentPat>,
219214
) -> Option<(DefWithBodyId, PatId)> {
220-
let container = self.find_pat_or_label_container(src.as_ref().map(|it| it.syntax()))?;
215+
let container = self.find_pat_or_label_container(src.syntax())?;
221216
let (_body, source_map) = self.db.body_with_source_map(container);
222217
let src = src.map(ast::Pat::from);
223218
let pat_id = source_map.node_pat(src.as_ref())?;
@@ -227,7 +222,7 @@ impl SourceToDefCtx<'_, '_> {
227222
&mut self,
228223
src: InFile<ast::SelfParam>,
229224
) -> Option<(DefWithBodyId, PatId)> {
230-
let container = self.find_pat_or_label_container(src.as_ref().map(|it| it.syntax()))?;
225+
let container = self.find_pat_or_label_container(src.syntax())?;
231226
let (_body, source_map) = self.db.body_with_source_map(container);
232227
let pat_id = source_map.node_self_param(src.as_ref())?;
233228
Some((container, pat_id))
@@ -236,7 +231,7 @@ impl SourceToDefCtx<'_, '_> {
236231
&mut self,
237232
src: InFile<ast::Label>,
238233
) -> Option<(DefWithBodyId, LabelId)> {
239-
let container = self.find_pat_or_label_container(src.as_ref().map(|it| it.syntax()))?;
234+
let container = self.find_pat_or_label_container(src.syntax())?;
240235
let (_body, source_map) = self.db.body_with_source_map(container);
241236
let label_id = source_map.node_label(src.as_ref())?;
242237
Some((container, label_id))
@@ -264,8 +259,7 @@ impl SourceToDefCtx<'_, '_> {
264259
}
265260

266261
pub(super) fn type_param_to_def(&mut self, src: InFile<ast::TypeParam>) -> Option<TypeParamId> {
267-
let container: ChildContainer =
268-
self.find_generic_param_container(src.as_ref().map(|it| it.syntax()))?.into();
262+
let container: ChildContainer = self.find_generic_param_container(src.syntax())?.into();
269263
let db = self.db;
270264
let dyn_map =
271265
&*self.cache.entry(container).or_insert_with(|| container.child_by_source(db));
@@ -276,8 +270,7 @@ impl SourceToDefCtx<'_, '_> {
276270
&mut self,
277271
src: InFile<ast::LifetimeParam>,
278272
) -> Option<LifetimeParamId> {
279-
let container: ChildContainer =
280-
self.find_generic_param_container(src.as_ref().map(|it| it.syntax()))?.into();
273+
let container: ChildContainer = self.find_generic_param_container(src.syntax())?.into();
281274
let db = self.db;
282275
let dyn_map =
283276
&*self.cache.entry(container).or_insert_with(|| container.child_by_source(db));
@@ -288,8 +281,7 @@ impl SourceToDefCtx<'_, '_> {
288281
&mut self,
289282
src: InFile<ast::ConstParam>,
290283
) -> Option<ConstParamId> {
291-
let container: ChildContainer =
292-
self.find_generic_param_container(src.as_ref().map(|it| it.syntax()))?.into();
284+
let container: ChildContainer = self.find_generic_param_container(src.syntax())?.into();
293285
let db = self.db;
294286
let dyn_map =
295287
&*self.cache.entry(container).or_insert_with(|| container.child_by_source(db));

crates/hir_expand/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ impl ExpansionInfo {
376376
db::TokenExpander::MacroRules { def_site_token_map, .. }
377377
| db::TokenExpander::MacroDef { def_site_token_map, .. },
378378
Some(tt),
379-
) => (def_site_token_map, tt.as_ref().map(|tt| tt.syntax().clone())),
379+
) => (def_site_token_map, tt.syntax().cloned()),
380380
_ => panic!("`Origin::Def` used with non-`macro_rules!` macro"),
381381
},
382382
};

crates/ide/src/display/navigation_target.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ impl NavigationTarget {
9292
pub(crate) fn from_module_to_decl(db: &RootDatabase, module: hir::Module) -> NavigationTarget {
9393
let name = module.name(db).map(|it| it.to_string().into()).unwrap_or_default();
9494
if let Some(src) = module.declaration_source(db) {
95-
let node = src.as_ref().map(|it| it.syntax());
95+
let node = src.syntax();
9696
let full_range = node.original_file_range(db);
9797
let focus_range = src
9898
.value
@@ -298,7 +298,7 @@ impl TryToNav for hir::Impl {
298298
let frange = if let Some(item) = &derive_attr {
299299
item.syntax().original_file_range(db)
300300
} else {
301-
src.as_ref().map(|it| it.syntax()).original_file_range(db)
301+
src.syntax().original_file_range(db)
302302
};
303303
let focus_range = if derive_attr.is_some() {
304304
None

crates/ide/src/hover.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,6 @@ pub(crate) fn hover(
117117
let node = token.parent()?;
118118
let definition = match_ast! {
119119
match node {
120-
// We don't use NameClass::referenced_or_defined here as we do not want to resolve
121-
// field pattern shorthands to their definition.
122120
ast::Name(name) => NameClass::classify(&sema, &name).map(|class| match class {
123121
NameClass::Definition(it) | NameClass::ConstReference(it) => it,
124122
NameClass::PatFieldShorthand { local_def, field_ref: _ } => Definition::Local(local_def),
@@ -139,6 +137,7 @@ pub(crate) fn hover(
139137
NameClass::defined,
140138
),
141139
_ => {
140+
// intra-doc links
142141
if ast::Comment::cast(token.clone()).is_some() {
143142
cov_mark::hit!(no_highlight_on_comment_hover);
144143
let (attributes, def) = doc_attributes(&sema, &node)?;
@@ -153,9 +152,12 @@ pub(crate) fn hover(
153152
Either::Left(it) => Definition::ModuleDef(it),
154153
Either::Right(it) => Definition::Macro(it),
155154
})
155+
// attributes, require special machinery as they are mere ident tokens
156156
} else if let Some(attr) = token.ancestors().find_map(ast::Attr::cast) {
157+
// lints
157158
if let res@Some(_) = try_hover_for_lint(&attr, &token) {
158159
return res;
160+
// derives
159161
} else {
160162
range_override = Some(token.text_range());
161163
try_resolve_derive_input_at(&sema, &attr, &token).map(Definition::Macro)
@@ -276,7 +278,7 @@ fn hover_type_info(
276278
"```text\nType: {:>apad$}\nCoerced to: {:>opad$}\n```\n",
277279
uncoerced = original,
278280
coerced = adjusted,
279-
// 6 base padding for static text prefix of each line
281+
// 6 base padding for difference of length of the two text prefixes
280282
apad = 6 + adjusted.len().max(original.len()),
281283
opad = original.len(),
282284
)

0 commit comments

Comments
 (0)