Skip to content

Commit

Permalink
Apply suggestions from review
Browse files Browse the repository at this point in the history
  • Loading branch information
ecstatic-morse committed Apr 11, 2020
1 parent beeacdb commit f0c7733
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 20 deletions.
34 changes: 20 additions & 14 deletions src/librustc_middle/ty/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,22 +190,28 @@ pub(crate) fn try_load_from_on_disk_cache<'tcx>(tcx: TyCtxt<'tcx>, dep_node: &De
rustc_dep_node_try_load_from_on_disk_cache!(dep_node, tcx)
}

/// An analogue of the `Into` trait that's intended only for query paramaters.
///
/// This exists to allow queries to accept either `DefId` or `LocalDefId` while requiring that the
/// user call `to_def_id` to convert between them everywhere else.
pub trait IntoQueryParam<P> {
fn into_query_param(self) -> P;
}
mod sealed {
use super::{DefId, LocalDefId};

/// An analogue of the `Into` trait that's intended only for query paramaters.
///
/// This exists to allow queries to accept either `DefId` or `LocalDefId` while requiring that the
/// user call `to_def_id` to convert between them everywhere else.
pub trait IntoQueryParam<P> {
fn into_query_param(self) -> P;
}

impl<P> IntoQueryParam<P> for P {
fn into_query_param(self) -> P {
self
impl<P> IntoQueryParam<P> for P {
fn into_query_param(self) -> P {
self
}
}
}

impl IntoQueryParam<DefId> for LocalDefId {
fn into_query_param(self) -> DefId {
self.to_def_id()
impl IntoQueryParam<DefId> for LocalDefId {
fn into_query_param(self) -> DefId {
self.to_def_id()
}
}
}

use sealed::IntoQueryParam;
6 changes: 0 additions & 6 deletions src/librustc_span/def_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,6 @@ impl fmt::Debug for LocalDefId {
}
}

impl From<LocalDefId> for DefId {
fn from(v: LocalDefId) -> Self {
v.to_def_id()
}
}

impl rustc_serialize::UseSpecializedEncodable for LocalDefId {}
impl rustc_serialize::UseSpecializedDecodable for LocalDefId {}

Expand Down

0 comments on commit f0c7733

Please sign in to comment.