diff options
Diffstat (limited to 'crates/ide_db')
-rw-r--r-- | crates/ide_db/src/helpers.rs | 4 | ||||
-rw-r--r-- | crates/ide_db/src/helpers/famous_defs_fixture.rs | 11 | ||||
-rw-r--r-- | crates/ide_db/src/search.rs | 15 |
3 files changed, 26 insertions, 4 deletions
diff --git a/crates/ide_db/src/helpers.rs b/crates/ide_db/src/helpers.rs index bc7aee110..f9de8ce0e 100644 --- a/crates/ide_db/src/helpers.rs +++ b/crates/ide_db/src/helpers.rs | |||
@@ -45,6 +45,10 @@ impl FamousDefs<'_, '_> { | |||
45 | self.find_crate("core") | 45 | self.find_crate("core") |
46 | } | 46 | } |
47 | 47 | ||
48 | pub fn core_cmp_Ord(&self) -> Option<Trait> { | ||
49 | self.find_trait("core:cmp:Ord") | ||
50 | } | ||
51 | |||
48 | pub fn core_convert_From(&self) -> Option<Trait> { | 52 | pub fn core_convert_From(&self) -> Option<Trait> { |
49 | self.find_trait("core:convert:From") | 53 | self.find_trait("core:convert:From") |
50 | } | 54 | } |
diff --git a/crates/ide_db/src/helpers/famous_defs_fixture.rs b/crates/ide_db/src/helpers/famous_defs_fixture.rs index 5e88de64d..bb4e9666b 100644 --- a/crates/ide_db/src/helpers/famous_defs_fixture.rs +++ b/crates/ide_db/src/helpers/famous_defs_fixture.rs | |||
@@ -1,5 +1,15 @@ | |||
1 | //- /libcore.rs crate:core | 1 | //- /libcore.rs crate:core |
2 | //! Signatures of traits, types and functions from the core lib for use in tests. | 2 | //! Signatures of traits, types and functions from the core lib for use in tests. |
3 | pub mod cmp { | ||
4 | |||
5 | pub trait Ord { | ||
6 | fn cmp(&self, other: &Self) -> Ordering; | ||
7 | fn max(self, other: Self) -> Self; | ||
8 | fn min(self, other: Self) -> Self; | ||
9 | fn clamp(self, min: Self, max: Self) -> Self; | ||
10 | } | ||
11 | } | ||
12 | |||
3 | pub mod convert { | 13 | pub mod convert { |
4 | pub trait From<T> { | 14 | pub trait From<T> { |
5 | fn from(t: T) -> Self; | 15 | fn from(t: T) -> Self; |
@@ -109,6 +119,7 @@ pub mod option { | |||
109 | 119 | ||
110 | pub mod prelude { | 120 | pub mod prelude { |
111 | pub use crate::{ | 121 | pub use crate::{ |
122 | cmp::Ord, | ||
112 | convert::From, | 123 | convert::From, |
113 | default::Default, | 124 | default::Default, |
114 | iter::{IntoIterator, Iterator}, | 125 | iter::{IntoIterator, Iterator}, |
diff --git a/crates/ide_db/src/search.rs b/crates/ide_db/src/search.rs index ba8bea002..ddcfbd3f3 100644 --- a/crates/ide_db/src/search.rs +++ b/crates/ide_db/src/search.rs | |||
@@ -416,10 +416,11 @@ impl<'a> FindUsages<'a> { | |||
416 | sink: &mut dyn FnMut(FileId, FileReference) -> bool, | 416 | sink: &mut dyn FnMut(FileId, FileReference) -> bool, |
417 | ) -> bool { | 417 | ) -> bool { |
418 | match NameClass::classify(self.sema, name) { | 418 | match NameClass::classify(self.sema, name) { |
419 | Some(NameClass::PatFieldShorthand { local_def: _, field_ref }) => { | 419 | Some(NameClass::PatFieldShorthand { local_def: _, field_ref }) |
420 | if !matches!(self.def, Definition::Field(_) if &field_ref == self.def) { | 420 | if matches!( |
421 | return false; | 421 | self.def, Definition::Field(_) if &field_ref == self.def |
422 | } | 422 | ) => |
423 | { | ||
423 | let FileRange { file_id, range } = self.sema.original_range(name.syntax()); | 424 | let FileRange { file_id, range } = self.sema.original_range(name.syntax()); |
424 | let reference = FileReference { | 425 | let reference = FileReference { |
425 | range, | 426 | range, |
@@ -429,6 +430,12 @@ impl<'a> FindUsages<'a> { | |||
429 | }; | 430 | }; |
430 | sink(file_id, reference) | 431 | sink(file_id, reference) |
431 | } | 432 | } |
433 | Some(NameClass::ConstReference(def)) if *self.def == def => { | ||
434 | let FileRange { file_id, range } = self.sema.original_range(name.syntax()); | ||
435 | let reference = | ||
436 | FileReference { range, name: ast::NameLike::Name(name.clone()), access: None }; | ||
437 | sink(file_id, reference) | ||
438 | } | ||
432 | _ => false, // not a usage | 439 | _ => false, // not a usage |
433 | } | 440 | } |
434 | } | 441 | } |