@@ -159,23 +159,27 @@ 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
- impl < DB : HirDatabase > Semantics < ' _ , DB > {
176
+ impl < DB : HirDatabase + ? Sized > Semantics < ' _ , DB > {
177
177
pub fn new ( db : & DB ) -> Semantics < ' _ , DB > {
178
+ // This doesn't work:
178
179
let impl_ = SemanticsImpl :: new ( db) ;
180
+ // Neither does this:
181
+ let impl_ = SemanticsImpl :: new ( db as & ( dyn HirDatabase ) ) ;
182
+
179
183
Semantics { db, imp : impl_ }
180
184
}
181
185
@@ -2387,3 +2391,16 @@ impl RenameConflictsVisitor<'_> {
2387
2391
self . body . walk_child_exprs ( expr, |expr| self . rename_conflicts ( expr) ) ;
2388
2392
}
2389
2393
}
2394
+
2395
+ #[ cfg( test) ]
2396
+ mod tests {
2397
+ use hir_ty:: db:: HirDatabase ;
2398
+
2399
+ use super :: * ;
2400
+
2401
+ #[ test]
2402
+ fn semantics_with_dyn_db ( ) {
2403
+ let maybe_db: Option < & dyn HirDatabase > = None ;
2404
+ let maybe_sema = maybe_db. map ( |db| Semantics :: new ( db) ) ;
2405
+ }
2406
+ }
0 commit comments