Skip to content

Commit b996d80

Browse files
committed
Adjust an impl of IntoQueryParam.
`IntoQueryParam` is a trait that lets query callers be a bit sloppy with arguments: - types similar to `DefId` and `LocalDefId` will be auto-converted - reference types will be auto-derefed I find this sloppiness a bit odd and distasteful; I'm not sure why queries get special treatment like this. Anyway, it turns out that the auto-derefing is only used for `&DefId`. This commit replaces the blanket impl for `&'a P` with one for `&DefId`, which enables the next commit.
1 parent aa8d5b1 commit b996d80

1 file changed

Lines changed: 7 additions & 5 deletions

File tree

compiler/rustc_middle/src/query/plumbing.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -627,24 +627,26 @@ mod sealed {
627627

628628
use super::{DefId, LocalDefId, OwnerId};
629629

630-
/// An analogue of the `Into` trait that's intended only for query parameters.
630+
/// An analogue of the `Into` trait that's intended only for certain query keys.
631631
///
632-
/// This exists to allow queries to accept either `DefId` or `LocalDefId` while requiring that the
633-
/// user call `to_def_id` to convert between them everywhere else.
632+
/// This lets queries with `DefId` or `LocalDefId` keys be called with closely-related types
633+
/// without requiring an explicit conversion, as a mild conveniences for common cases.
634634
pub trait IntoQueryParam<P> {
635635
fn into_query_param(self) -> P;
636636
}
637637

638+
// This blanket impl provides a no-op "conversion" for all non-`DefId`/`LocalDefId` types.
638639
impl<P> IntoQueryParam<P> for P {
639640
#[inline(always)]
640641
fn into_query_param(self) -> P {
641642
self
642643
}
643644
}
644645

645-
impl<'a, P: Copy> IntoQueryParam<P> for &'a P {
646+
#[allow(rustc::pass_by_value)]
647+
impl IntoQueryParam<DefId> for &DefId {
646648
#[inline(always)]
647-
fn into_query_param(self) -> P {
649+
fn into_query_param(self) -> DefId {
648650
*self
649651
}
650652
}

0 commit comments

Comments
 (0)