@@ -83,27 +83,31 @@ pub enum NameClass {
83
83
Definition ( Definition ) ,
84
84
/// `None` in `if let None = Some(82) {}`
85
85
ConstReference ( Definition ) ,
86
- FieldShorthand {
86
+ /// `field` in `if let Foo { field } = todo!() {}`
87
+ PatFieldShorthand {
87
88
local : Local ,
88
89
field : Definition ,
89
90
} ,
90
91
}
91
92
92
93
impl NameClass {
93
94
pub fn definition ( self , db : & dyn HirDatabase ) -> Option < Definition > {
94
- Some ( match self {
95
+ let res = match self {
95
96
NameClass :: ExternCrate ( krate) => Definition :: ModuleDef ( krate. root_module ( db) . into ( ) ) ,
96
97
NameClass :: Definition ( it) => it,
97
98
NameClass :: ConstReference ( _) => return None ,
98
- NameClass :: FieldShorthand { local, field : _ } => Definition :: Local ( local) ,
99
- } )
99
+ /// Both `local` and `field` are definitions here, but only `local`
100
+ /// is the definition which is introduced by this name.
101
+ NameClass :: PatFieldShorthand { local, field : _ } => Definition :: Local ( local) ,
102
+ } ;
103
+ Some ( res)
100
104
}
101
105
102
106
pub fn definition_or_reference ( self , db : & dyn HirDatabase ) -> Definition {
103
107
match self {
104
108
NameClass :: ExternCrate ( krate) => Definition :: ModuleDef ( krate. root_module ( db) . into ( ) ) ,
105
109
NameClass :: Definition ( it) | NameClass :: ConstReference ( it) => it,
106
- NameClass :: FieldShorthand { local : _, field } => field,
110
+ NameClass :: PatFieldShorthand { local : _, field } => field,
107
111
}
108
112
}
109
113
}
@@ -161,7 +165,7 @@ pub fn classify_name(sema: &Semantics<RootDatabase>, name: &ast::Name) -> Option
161
165
if record_pat_field. name_ref( ) . is_none( ) {
162
166
if let Some ( field) = sema. resolve_record_pat_field( & record_pat_field) {
163
167
let field = Definition :: Field ( field) ;
164
- return Some ( NameClass :: FieldShorthand { local, field } ) ;
168
+ return Some ( NameClass :: PatFieldShorthand { local, field } ) ;
165
169
}
166
170
}
167
171
}
0 commit comments