@@ -91,7 +91,8 @@ pub enum NameClass {
9191}
9292
9393impl NameClass {
94- pub fn definition ( self , db : & dyn HirDatabase ) -> Option < Definition > {
94+ /// `Definition` defined by this name.
95+ pub fn defined ( self , db : & dyn HirDatabase ) -> Option < Definition > {
9596 let res = match self {
9697 NameClass :: ExternCrate ( krate) => Definition :: ModuleDef ( krate. root_module ( db) . into ( ) ) ,
9798 NameClass :: Definition ( it) => it,
@@ -103,7 +104,8 @@ impl NameClass {
103104 Some ( res)
104105 }
105106
106- pub fn reference_or_definition ( self , db : & dyn HirDatabase ) -> Definition {
107+ /// `Definition` referenced or defined by this name.
108+ pub fn referenced_or_defined ( self , db : & dyn HirDatabase ) -> Definition {
107109 match self {
108110 NameClass :: ExternCrate ( krate) => Definition :: ModuleDef ( krate. root_module ( db) . into ( ) ) ,
109111 NameClass :: Definition ( it) | NameClass :: ConstReference ( it) => it,
@@ -150,7 +152,7 @@ impl NameClass {
150152 } )
151153 . and_then( |name_ref| NameRefClass :: classify( sema, & name_ref) ) ?;
152154
153- Some ( NameClass :: Definition ( name_ref_class. definition ( sema. db) ) )
155+ Some ( NameClass :: Definition ( name_ref_class. referenced ( sema. db) ) )
154156 } else {
155157 let extern_crate = it. syntax( ) . parent( ) . and_then( ast:: ExternCrate :: cast) ?;
156158 let resolved = sema. resolve_extern_crate( & extern_crate) ?;
@@ -233,15 +235,20 @@ impl NameClass {
233235pub enum NameRefClass {
234236 ExternCrate ( Crate ) ,
235237 Definition ( Definition ) ,
236- FieldShorthand { local : Local , field : Definition } ,
238+ FieldShorthand { local_ref : Local , field_ref : Definition } ,
237239}
238240
239241impl NameRefClass {
240- pub fn definition ( self , db : & dyn HirDatabase ) -> Definition {
242+ /// `Definition`, which this name refers to.
243+ pub fn referenced ( self , db : & dyn HirDatabase ) -> Definition {
241244 match self {
242245 NameRefClass :: ExternCrate ( krate) => Definition :: ModuleDef ( krate. root_module ( db) . into ( ) ) ,
243246 NameRefClass :: Definition ( def) => def,
244- NameRefClass :: FieldShorthand { local, field : _ } => Definition :: Local ( local) ,
247+ NameRefClass :: FieldShorthand { local_ref, field_ref : _ } => {
248+ // FIXME: this is inherently ambiguous -- this name refers to
249+ // two different defs....
250+ Definition :: Local ( local_ref)
251+ }
245252 }
246253 }
247254
@@ -272,7 +279,9 @@ impl NameRefClass {
272279 let field = Definition :: Field ( field) ;
273280 let res = match local {
274281 None => NameRefClass :: Definition ( field) ,
275- Some ( local) => NameRefClass :: FieldShorthand { field, local } ,
282+ Some ( local) => {
283+ NameRefClass :: FieldShorthand { field_ref : field, local_ref : local }
284+ }
276285 } ;
277286 return Some ( res) ;
278287 }
0 commit comments