@@ -159,26 +159,42 @@ pub struct SemanticsImpl<'db> {
159
159
macro_call_cache : RefCell < FxHashMap < InFile < ast:: MacroCall > , MacroCallId > > ,
160
160
}
161
161
162
- impl < DB > fmt:: Debug for Semantics < ' _ , DB > {
162
+ impl < DB : ? Sized > fmt:: Debug for Semantics < ' _ , DB > {
163
163
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
164
164
write ! ( f, "Semantics {{ ... }}" )
165
165
}
166
166
}
167
167
168
- impl < ' db , DB > ops:: Deref for Semantics < ' db , DB > {
168
+ impl < ' db , DB : ? Sized > ops:: Deref for Semantics < ' db , DB > {
169
169
type Target = SemanticsImpl < ' db > ;
170
170
171
171
fn deref ( & self ) -> & Self :: Target {
172
172
& self . imp
173
173
}
174
174
}
175
175
176
+ // Note: while this variant of `Semantics<'_, _>` might seem unused, as it does not
177
+ // find actual use within the rust-analyzer project itself, it exists to enable the use
178
+ // within e.g. tracked salsa functions in third-party crates that build upon `ra_ap_hir`.
179
+ impl Semantics < ' _ , dyn HirDatabase > {
180
+ /// Creates an instance that's weakly coupled to its underlying database type.
181
+ pub fn new_dyn ( db : & ' _ dyn HirDatabase ) -> Semantics < ' _ , dyn HirDatabase > {
182
+ let impl_ = SemanticsImpl :: new ( db) ;
183
+ Semantics { db, imp : impl_ }
184
+ }
185
+ }
186
+
176
187
impl < DB : HirDatabase > Semantics < ' _ , DB > {
188
+ /// Creates an instance that's strongly coupled to its underlying database type.
177
189
pub fn new ( db : & DB ) -> Semantics < ' _ , DB > {
178
190
let impl_ = SemanticsImpl :: new ( db) ;
179
191
Semantics { db, imp : impl_ }
180
192
}
193
+ }
181
194
195
+ // Note: We take `DB` as `?Sized` here in order to support type-erased
196
+ // use of `Semantics` via `Semantics<'_, dyn HirDatabase>`:
197
+ impl < DB : HirDatabase + ?Sized > Semantics < ' _ , DB > {
182
198
pub fn hir_file_for ( & self , syntax_node : & SyntaxNode ) -> HirFileId {
183
199
self . imp . find_file ( syntax_node) . file_id
184
200
}
0 commit comments