From cb0cd719009826e0f0699208704078401cdc9e88 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Sat, 6 Jun 2020 17:29:51 -0400 Subject: [PATCH] impl From for DefId This makes it easier for new contributors (a.k.a me) to convert between types without having to look up https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/def_id/struct.LocalDefId.html#method.to_def_id. I think in some cases it will also cause rustc to suggest `.into()` when the types don't match which maybe helpful even to experienced contributors. --- src/librustc_span/def_id.rs | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/librustc_span/def_id.rs b/src/librustc_span/def_id.rs index fad9f2f613012..c4bd428b132c6 100644 --- a/src/librustc_span/def_id.rs +++ b/src/librustc_span/def_id.rs @@ -231,6 +231,12 @@ impl LocalDefId { } } +impl From for DefId { + fn from(local: LocalDefId) -> Self { + local.to_def_id() + } +} + impl fmt::Debug for LocalDefId { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { self.to_def_id().fmt(f)