diff options
Diffstat (limited to 'src/tools/rust-analyzer/crates/ide/src/references.rs')
-rw-r--r-- | src/tools/rust-analyzer/crates/ide/src/references.rs | 395 |
1 files changed, 395 insertions, 0 deletions
diff --git a/src/tools/rust-analyzer/crates/ide/src/references.rs b/src/tools/rust-analyzer/crates/ide/src/references.rs index 0f758cfa2..cabbc2872 100644 --- a/src/tools/rust-analyzer/crates/ide/src/references.rs +++ b/src/tools/rust-analyzer/crates/ide/src/references.rs @@ -1636,4 +1636,399 @@ pub fn deri$0ve(_stream: TokenStream) -> TokenStream {} "#]], ); } + + #[test] + fn assoc_items_trait_def() { + check( + r#" +trait Trait { + const CONST$0: usize; +} + +impl Trait for () { + const CONST: usize = 0; +} + +impl Trait for ((),) { + const CONST: usize = 0; +} + +fn f<T: Trait>() { + let _ = <()>::CONST; + + let _ = T::CONST; +} +"#, + expect![[r#" + CONST Const FileId(0) 18..37 24..29 + + FileId(0) 71..76 + FileId(0) 125..130 + FileId(0) 183..188 + FileId(0) 206..211 + "#]], + ); + check( + r#" +trait Trait { + type TypeAlias$0; +} + +impl Trait for () { + type TypeAlias = (); +} + +impl Trait for ((),) { + type TypeAlias = (); +} + +fn f<T: Trait>() { + let _: <() as Trait>::TypeAlias; + + let _: T::TypeAlias; +} +"#, + expect![[r#" + TypeAlias TypeAlias FileId(0) 18..33 23..32 + + FileId(0) 66..75 + FileId(0) 117..126 + FileId(0) 181..190 + FileId(0) 207..216 + "#]], + ); + check( + r#" +trait Trait { + fn function$0() {} +} + +impl Trait for () { + fn function() {} +} + +impl Trait for ((),) { + fn function() {} +} + +fn f<T: Trait>() { + let _ = <()>::function; + + let _ = T::function; +} +"#, + expect![[r#" + function Function FileId(0) 18..34 21..29 + + FileId(0) 65..73 + FileId(0) 112..120 + FileId(0) 166..174 + FileId(0) 192..200 + "#]], + ); + } + + #[test] + fn assoc_items_trait_impl_def() { + check( + r#" +trait Trait { + const CONST: usize; +} + +impl Trait for () { + const CONST$0: usize = 0; +} + +impl Trait for ((),) { + const CONST: usize = 0; +} + +fn f<T: Trait>() { + let _ = <()>::CONST; + + let _ = T::CONST; +} +"#, + expect![[r#" + CONST Const FileId(0) 65..88 71..76 + + FileId(0) 183..188 + "#]], + ); + check( + r#" +trait Trait { + type TypeAlias; +} + +impl Trait for () { + type TypeAlias$0 = (); +} + +impl Trait for ((),) { + type TypeAlias = (); +} + +fn f<T: Trait>() { + let _: <() as Trait>::TypeAlias; + + let _: T::TypeAlias; +} +"#, + expect![[r#" + TypeAlias TypeAlias FileId(0) 61..81 66..75 + + FileId(0) 23..32 + FileId(0) 117..126 + FileId(0) 181..190 + FileId(0) 207..216 + "#]], + ); + check( + r#" +trait Trait { + fn function() {} +} + +impl Trait for () { + fn function$0() {} +} + +impl Trait for ((),) { + fn function() {} +} + +fn f<T: Trait>() { + let _ = <()>::function; + + let _ = T::function; +} +"#, + expect![[r#" + function Function FileId(0) 62..78 65..73 + + FileId(0) 166..174 + "#]], + ); + } + + #[test] + fn assoc_items_ref() { + check( + r#" +trait Trait { + const CONST: usize; +} + +impl Trait for () { + const CONST: usize = 0; +} + +impl Trait for ((),) { + const CONST: usize = 0; +} + +fn f<T: Trait>() { + let _ = <()>::CONST$0; + + let _ = T::CONST; +} +"#, + expect![[r#" + CONST Const FileId(0) 65..88 71..76 + + FileId(0) 183..188 + "#]], + ); + check( + r#" +trait Trait { + type TypeAlias; +} + +impl Trait for () { + type TypeAlias = (); +} + +impl Trait for ((),) { + type TypeAlias = (); +} + +fn f<T: Trait>() { + let _: <() as Trait>::TypeAlias$0; + + let _: T::TypeAlias; +} +"#, + expect![[r#" + TypeAlias TypeAlias FileId(0) 18..33 23..32 + + FileId(0) 66..75 + FileId(0) 117..126 + FileId(0) 181..190 + FileId(0) 207..216 + "#]], + ); + check( + r#" +trait Trait { + fn function() {} +} + +impl Trait for () { + fn function() {} +} + +impl Trait for ((),) { + fn function() {} +} + +fn f<T: Trait>() { + let _ = <()>::function$0; + + let _ = T::function; +} +"#, + expect![[r#" + function Function FileId(0) 62..78 65..73 + + FileId(0) 166..174 + "#]], + ); + } + + #[test] + fn name_clashes() { + check( + r#" +trait Foo { + fn method$0(&self) -> u8; +} + +struct Bar { + method: u8, +} + +impl Foo for Bar { + fn method(&self) -> u8 { + self.method + } +} +fn method() {} +"#, + expect![[r#" + method Function FileId(0) 16..39 19..25 + + FileId(0) 101..107 + "#]], + ); + check( + r#" +trait Foo { + fn method(&self) -> u8; +} + +struct Bar { + method$0: u8, +} + +impl Foo for Bar { + fn method(&self) -> u8 { + self.method + } +} +fn method() {} +"#, + expect![[r#" + method Field FileId(0) 60..70 60..66 + + FileId(0) 136..142 Read + "#]], + ); + check( + r#" +trait Foo { + fn method(&self) -> u8; +} + +struct Bar { + method: u8, +} + +impl Foo for Bar { + fn method$0(&self) -> u8 { + self.method + } +} +fn method() {} +"#, + expect![[r#" + method Function FileId(0) 98..148 101..107 + + (no references) + "#]], + ); + check( + r#" +trait Foo { + fn method(&self) -> u8; +} + +struct Bar { + method: u8, +} + +impl Foo for Bar { + fn method(&self) -> u8 { + self.method$0 + } +} +fn method() {} +"#, + expect![[r#" + method Field FileId(0) 60..70 60..66 + + FileId(0) 136..142 Read + "#]], + ); + check( + r#" +trait Foo { + fn method(&self) -> u8; +} + +struct Bar { + method: u8, +} + +impl Foo for Bar { + fn method(&self) -> u8 { + self.method + } +} +fn method$0() {} +"#, + expect![[r#" + method Function FileId(0) 151..165 154..160 + + (no references) + "#]], + ); + } + + #[test] + fn raw_identifier() { + check( + r#" +fn r#fn$0() {} +fn main() { r#fn(); } +"#, + expect![[r#" + r#fn Function FileId(0) 0..12 3..7 + + FileId(0) 25..29 + "#]], + ); + } } |