diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2020-07-13 15:33:32 +0100 |
---|---|---|
committer | GitHub <[email protected]> | 2020-07-13 15:33:32 +0100 |
commit | 853440775d72974585ca3fe39f9688a4d4302dd3 (patch) | |
tree | 89272d8f03145df99fe68f0e35f8892dc4ab2c72 /crates/ra_hir_def/src | |
parent | 4b1c3724364ff538acdcb44bdd23d501ef54cff3 (diff) | |
parent | 693ac892f2db5db1ce7cf86db7bf6207b3515c42 (diff) |
Merge #5342
5342: Don't copy-paste `impl_froms` into every crate r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/ra_hir_def/src')
-rw-r--r-- | crates/ra_hir_def/src/lib.rs | 45 |
1 files changed, 15 insertions, 30 deletions
diff --git a/crates/ra_hir_def/src/lib.rs b/crates/ra_hir_def/src/lib.rs index 564434ccc..b71d626c3 100644 --- a/crates/ra_hir_def/src/lib.rs +++ b/crates/ra_hir_def/src/lib.rs | |||
@@ -65,6 +65,7 @@ use item_tree::{ | |||
65 | Const, Enum, Function, Impl, ItemTreeId, ItemTreeNode, ModItem, Static, Struct, Trait, | 65 | Const, Enum, Function, Impl, ItemTreeId, ItemTreeNode, ModItem, Static, Struct, Trait, |
66 | TypeAlias, Union, | 66 | TypeAlias, Union, |
67 | }; | 67 | }; |
68 | use stdx::impl_from; | ||
68 | 69 | ||
69 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 70 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
70 | pub struct ModuleId { | 71 | pub struct ModuleId { |
@@ -223,25 +224,6 @@ pub struct TypeParamId { | |||
223 | 224 | ||
224 | pub type LocalTypeParamId = Idx<generics::TypeParamData>; | 225 | pub type LocalTypeParamId = Idx<generics::TypeParamData>; |
225 | 226 | ||
226 | macro_rules! impl_froms { | ||
227 | ($e:ident: $($v:ident $(($($sv:ident),*))?),*) => { | ||
228 | $( | ||
229 | impl From<$v> for $e { | ||
230 | fn from(it: $v) -> $e { | ||
231 | $e::$v(it) | ||
232 | } | ||
233 | } | ||
234 | $($( | ||
235 | impl From<$sv> for $e { | ||
236 | fn from(it: $sv) -> $e { | ||
237 | $e::$v($v::$sv(it)) | ||
238 | } | ||
239 | } | ||
240 | )*)? | ||
241 | )* | ||
242 | } | ||
243 | } | ||
244 | |||
245 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 227 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
246 | pub enum ContainerId { | 228 | pub enum ContainerId { |
247 | ModuleId(ModuleId), | 229 | ModuleId(ModuleId), |
@@ -254,7 +236,7 @@ pub enum AssocContainerId { | |||
254 | ImplId(ImplId), | 236 | ImplId(ImplId), |
255 | TraitId(TraitId), | 237 | TraitId(TraitId), |
256 | } | 238 | } |
257 | impl_froms!(AssocContainerId: ContainerId); | 239 | impl_from!(ContainerId for AssocContainerId); |
258 | 240 | ||
259 | /// A Data Type | 241 | /// A Data Type |
260 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] | 242 | #[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] |
@@ -263,7 +245,7 @@ pub enum AdtId { | |||
263 | UnionId(UnionId), | 245 | UnionId(UnionId), |
264 | EnumId(EnumId), | 246 | EnumId(EnumId), |
265 | } | 247 | } |
266 | impl_froms!(AdtId: StructId, UnionId, EnumId); | 248 | impl_from!(StructId, UnionId, EnumId for AdtId); |
267 | 249 | ||
268 | /// The defs which can be visible in the module. | 250 | /// The defs which can be visible in the module. |
269 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 251 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
@@ -279,8 +261,8 @@ pub enum ModuleDefId { | |||
279 | TypeAliasId(TypeAliasId), | 261 | TypeAliasId(TypeAliasId), |
280 | BuiltinType(BuiltinType), | 262 | BuiltinType(BuiltinType), |
281 | } | 263 | } |
282 | impl_froms!( | 264 | impl_from!( |
283 | ModuleDefId: ModuleId, | 265 | ModuleId, |
284 | FunctionId, | 266 | FunctionId, |
285 | AdtId(StructId, EnumId, UnionId), | 267 | AdtId(StructId, EnumId, UnionId), |
286 | EnumVariantId, | 268 | EnumVariantId, |
@@ -289,6 +271,7 @@ impl_froms!( | |||
289 | TraitId, | 271 | TraitId, |
290 | TypeAliasId, | 272 | TypeAliasId, |
291 | BuiltinType | 273 | BuiltinType |
274 | for ModuleDefId | ||
292 | ); | 275 | ); |
293 | 276 | ||
294 | /// The defs which have a body. | 277 | /// The defs which have a body. |
@@ -299,7 +282,7 @@ pub enum DefWithBodyId { | |||
299 | ConstId(ConstId), | 282 | ConstId(ConstId), |
300 | } | 283 | } |
301 | 284 | ||
302 | impl_froms!(DefWithBodyId: FunctionId, ConstId, StaticId); | 285 | impl_from!(FunctionId, ConstId, StaticId for DefWithBodyId); |
303 | 286 | ||
304 | #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] | 287 | #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] |
305 | pub enum AssocItemId { | 288 | pub enum AssocItemId { |
@@ -311,7 +294,7 @@ pub enum AssocItemId { | |||
311 | // sure that you can only turn actual assoc items into AssocItemIds. This would | 294 | // sure that you can only turn actual assoc items into AssocItemIds. This would |
312 | // require not implementing From, and instead having some checked way of | 295 | // require not implementing From, and instead having some checked way of |
313 | // casting them, and somehow making the constructors private, which would be annoying. | 296 | // casting them, and somehow making the constructors private, which would be annoying. |
314 | impl_froms!(AssocItemId: FunctionId, ConstId, TypeAliasId); | 297 | impl_from!(FunctionId, ConstId, TypeAliasId for AssocItemId); |
315 | 298 | ||
316 | #[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] | 299 | #[derive(Clone, Copy, PartialEq, Eq, Debug, Hash)] |
317 | pub enum GenericDefId { | 300 | pub enum GenericDefId { |
@@ -326,14 +309,15 @@ pub enum GenericDefId { | |||
326 | // consts can have type parameters from their parents (i.e. associated consts of traits) | 309 | // consts can have type parameters from their parents (i.e. associated consts of traits) |
327 | ConstId(ConstId), | 310 | ConstId(ConstId), |
328 | } | 311 | } |
329 | impl_froms!( | 312 | impl_from!( |
330 | GenericDefId: FunctionId, | 313 | FunctionId, |
331 | AdtId(StructId, EnumId, UnionId), | 314 | AdtId(StructId, EnumId, UnionId), |
332 | TraitId, | 315 | TraitId, |
333 | TypeAliasId, | 316 | TypeAliasId, |
334 | ImplId, | 317 | ImplId, |
335 | EnumVariantId, | 318 | EnumVariantId, |
336 | ConstId | 319 | ConstId |
320 | for GenericDefId | ||
337 | ); | 321 | ); |
338 | 322 | ||
339 | impl From<AssocItemId> for GenericDefId { | 323 | impl From<AssocItemId> for GenericDefId { |
@@ -361,8 +345,8 @@ pub enum AttrDefId { | |||
361 | ImplId(ImplId), | 345 | ImplId(ImplId), |
362 | } | 346 | } |
363 | 347 | ||
364 | impl_froms!( | 348 | impl_from!( |
365 | AttrDefId: ModuleId, | 349 | ModuleId, |
366 | FieldId, | 350 | FieldId, |
367 | AdtId(StructId, EnumId, UnionId), | 351 | AdtId(StructId, EnumId, UnionId), |
368 | EnumVariantId, | 352 | EnumVariantId, |
@@ -373,6 +357,7 @@ impl_froms!( | |||
373 | TypeAliasId, | 357 | TypeAliasId, |
374 | MacroDefId, | 358 | MacroDefId, |
375 | ImplId | 359 | ImplId |
360 | for AttrDefId | ||
376 | ); | 361 | ); |
377 | 362 | ||
378 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] | 363 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
@@ -381,7 +366,7 @@ pub enum VariantId { | |||
381 | StructId(StructId), | 366 | StructId(StructId), |
382 | UnionId(UnionId), | 367 | UnionId(UnionId), |
383 | } | 368 | } |
384 | impl_froms!(VariantId: EnumVariantId, StructId, UnionId); | 369 | impl_from!(EnumVariantId, StructId, UnionId for VariantId); |
385 | 370 | ||
386 | trait Intern { | 371 | trait Intern { |
387 | type ID; | 372 | type ID; |